diff options
-rw-r--r-- | lib/git/tree.py | 11 | ||||
-rw-r--r-- | test/git/test_repo.py | 4 | ||||
-rw-r--r-- | test/git/test_tree.py | 2 |
3 files changed, 8 insertions, 9 deletions
diff --git a/lib/git/tree.py b/lib/git/tree.py index f1aa0b3b..86e893ef 100644 --- a/lib/git/tree.py +++ b/lib/git/tree.py @@ -32,13 +32,13 @@ class Tree(LazyMixin): def construct_initialize(self, repo, id, text): self.repo = repo self.id = id - self.contents = [] + self.contents = {} self.__baked__ = False for line in text.splitlines(): - self.contents.append(self.content_from_string(self.repo, line)) - - self.contents = [c for c in self.contents if c is not None] + obj = self.content_from_string(self.repo, line) + if obj: + self.contents[obj.name] = obj self.__bake_it__() return self @@ -84,8 +84,7 @@ class Tree(LazyMixin): Returns ``GitPython.Blob`` or ``GitPython.Tree`` or ``None`` if not found """ - contents = [c for c in self.contents if c.name == file] - return contents and contents[0] or None + return self.contents.get(file) @property def basename(self): diff --git a/test/git/test_repo.py b/test/git/test_repo.py index 7550e1d6..c7a4c01b 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -96,8 +96,8 @@ class TestRepo(object): tree = self.repo.tree('master') - assert_equal(4, len([c for c in tree.contents if isinstance(c, Blob)])) - assert_equal(3, len([c for c in tree.contents if isinstance(c, Tree)])) + assert_equal(4, len([c for c in tree.contents.values() if isinstance(c, Blob)])) + assert_equal(3, len([c for c in tree.contents.values() if isinstance(c, Tree)])) assert_true(git.called) assert_equal(git.call_args, (('ls_tree', 'master'), {})) diff --git a/test/git/test_tree.py b/test/git/test_tree.py index 957b8962..d66764b3 100644 --- a/test/git/test_tree.py +++ b/test/git/test_tree.py @@ -18,7 +18,7 @@ class TestTree(object): tree = self.repo.tree('master') - child = tree.contents[-1] + child = tree.contents['grit'] child.contents child.contents |