diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-11-04 13:17:37 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-11-04 13:17:37 +0100 |
commit | f41d42ee7e264ce2fc32cea555e5f666fa1b1fe9 (patch) | |
tree | 1d45b8f6fd8a6114b120e13844cc05e930793297 /lib/git/repo.py | |
parent | c4cde8df886112ee32b0a09fcac90c28c85ded7f (diff) | |
download | gitpython-f41d42ee7e264ce2fc32cea555e5f666fa1b1fe9.tar.gz |
Improved cmd error handling in case an invalid revision is specified for an object
repo.tree: improved to be less restricting
Diffstat (limited to 'lib/git/repo.py')
-rw-r--r-- | lib/git/repo.py | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/lib/git/repo.py b/lib/git/repo.py index 41484aa0..6d388633 100644 --- a/lib/git/repo.py +++ b/lib/git/repo.py @@ -349,12 +349,12 @@ class Repo(object): """ return ( c.tree for c in self.iter_commits(*args, **kwargs) ) - def tree(self, ref=None): + def tree(self, rev=None): """ - The Tree object for the given treeish reference + The Tree object for the given treeish revision - ``ref`` - is a Ref instance defaulting to the active_branch if None. + ``rev`` + is a revision pointing to a Treeish ( being a commit or tree ) Examples:: @@ -364,32 +364,19 @@ class Repo(object): ``git.Tree`` NOTE - A ref is requried here to assure you point to a commit or tag. Otherwise - it is not garantueed that you point to the root-level tree. - If you need a non-root level tree, find it by iterating the root tree. Otherwise it cannot know about its path relative to the repository root and subsequent operations might have unexpected results. """ - if ref is None: - ref = self.active_branch - if not isinstance(ref, Reference): - raise ValueError( "Reference required, got %r" % ref ) - - - # As we are directly reading object information, we must make sure - # we truly point to a tree object. We resolve the ref to a sha in all cases - # to assure the returned tree can be compared properly. Except for - # heads, ids should always be hexshas - hexsha, typename, size = self.git.get_object_header( ref ) - if typename != "tree": - # will raise if this is not a valid tree - hexsha, typename, size = self.git.get_object_header( str(ref)+'^{tree}' ) - # END tree handling - ref = hexsha - - # the root has an empty relative path and the default mode - return Tree(self, ref, 0, '') + 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)) def iter_commits(self, rev=None, paths='', **kwargs): """ |