From bc31651674648f026464fd4110858c4ffeac3c18 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 7 Jul 2010 17:30:47 +0200 Subject: 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 --- lib/git/repo/base.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'lib/git/repo/base.py') 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 -- cgit v1.2.1