diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2010-07-07 17:30:47 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2010-07-07 17:30:47 +0200 |
commit | bc31651674648f026464fd4110858c4ffeac3c18 (patch) | |
tree | d52bd46d5a2c00c6c852148dba16a29d31ae3a5c /lib/git/repo/base.py | |
parent | f068cdc5a1a13539c4a1d756ae950aab65f5348b (diff) | |
download | gitpython-bc31651674648f026464fd4110858c4ffeac3c18.tar.gz |
Adjusted previous object creators to use the rev_parse method directly. rev_parse could be adjusted not to return Objects anymore, providing better performance for those who just want a sha only. On the other hand, the method is high-level and should be convenient to use as well, its a starting point for more usually, hence its unlikely to call it in tight loops
Diffstat (limited to 'lib/git/repo/base.py')
-rw-r--r-- | lib/git/repo/base.py | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/lib/git/repo/base.py b/lib/git/repo/base.py index e659225e..ed805991 100644 --- a/lib/git/repo/base.py +++ b/lib/git/repo/base.py @@ -323,11 +323,9 @@ class Repo(object): :param rev: revision specifier, see git-rev-parse for viable options. :return: ``git.Commit``""" if rev is None: - rev = self.active_branch - - c = Object.new(self, rev) - assert c.type == "commit", "Revision %s did not point to a commit, but to %s" % (rev, c) - return c + return self.active_branch.commit + else: + return self.rev_parse(str(rev)+"^0") def iter_trees(self, *args, **kwargs): """:return: Iterator yielding Tree objects @@ -348,14 +346,9 @@ class Repo(object): it cannot know about its path relative to the repository root and subsequent operations might have unexpected results.""" if rev is None: - rev = self.active_branch - - c = Object.new(self, rev) - if c.type == "commit": - return c.tree - elif c.type == "tree": - return c - raise ValueError( "Revision %s did not point to a treeish, but to %s" % (rev, c)) + return self.active_branch.commit.tree + else: + return self.rev_parse(str(rev)+"^{tree}") def iter_commits(self, rev=None, paths='', **kwargs): """A list of Commit objects representing the history of a given ref/commit |