summaryrefslogtreecommitdiff
path: root/lib/git/objects/tree.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-12-30 16:17:28 +0100
committerSebastian Thiel <byronimo@gmail.com>2009-12-30 16:17:28 +0100
commitd86e77edd500f09e3e19017c974b525643fbd539 (patch)
treee2c4bbdb4aff635b9480109d7dcef17a63c050b3 /lib/git/objects/tree.py
parent1b3feddd1269a0b0976f4eef2093cb0dbf258f99 (diff)
downloadgitpython-d86e77edd500f09e3e19017c974b525643fbd539.tar.gz
tree: implemented recursive paths in __div__ and __getitem__ method, allowing the keys to contain slashes; adjusted test to check for this
Diffstat (limited to 'lib/git/objects/tree.py')
-rw-r--r--lib/git/objects/tree.py33
1 files changed, 27 insertions, 6 deletions
diff --git a/lib/git/objects/tree.py b/lib/git/objects/tree.py
index c80450fc..0b0ac0b1 100644
--- a/lib/git/objects/tree.py
+++ b/lib/git/objects/tree.py
@@ -158,7 +158,32 @@ class Tree(base.IndexObject, diff.Diffable, utils.Traversable):
Raise
KeyError if given file or tree does not exist in tree
"""
- return self[file]
+ msg = "Blob or Tree named %r not found"
+ if '/' in file:
+ tree = self
+ item = self
+ tokens = file.split('/')
+ for i,token in enumerate(tokens):
+ item = tree[token]
+ if item.type == 'tree':
+ tree = item
+ else:
+ # safety assertion - blobs are at the end of the path
+ if i != len(tokens)-1:
+ raise KeyError(msg % file)
+ return item
+ # END handle item type
+ # END for each token of split path
+ if item == self:
+ raise KeyError(msg % file)
+ return item
+ else:
+ for obj in self._cache:
+ if obj.name == file:
+ return obj
+ # END for each obj
+ raise KeyError( msg % file )
+ # END handle long paths
def __repr__(self):
@@ -205,11 +230,7 @@ class Tree(base.IndexObject, diff.Diffable, utils.Traversable):
if isinstance(item, basestring):
# compatability
- for obj in self._cache:
- if obj.name == item:
- return obj
- # END for each obj
- raise KeyError( "Blob or Tree named %s not found" % item )
+ return self.__div__(item)
# END index is basestring
raise TypeError( "Invalid index type: %r" % item )