From 43eb1edf93c381bf3f3809a809df33dae23b50d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20Fr=C3=A9cinaux?= Date: Fri, 5 Sep 2008 23:04:58 +0200 Subject: Initialize trees completely in tree.__bake__(). This is a simplification of the tree baking code. As a matter of consequency, Tree.construct() and tree.construct_initialize() have been killed, and repo.tree() has lost the "paths" argument. This is not a problem since one can just have the same result with: dict(k, o for k, o in tree.items() if k in paths) --- lib/git/repo.py | 8 +++----- lib/git/tree.py | 22 ++++++---------------- 2 files changed, 9 insertions(+), 21 deletions(-) (limited to 'lib/git') diff --git a/lib/git/repo.py b/lib/git/repo.py index 0e52fab7..86057d8b 100644 --- a/lib/git/repo.py +++ b/lib/git/repo.py @@ -199,24 +199,22 @@ class Repo(object): diff_refs = list(set(other_repo_refs) - set(repo_refs)) return map(lambda ref: Commit.find_all(other_repo, ref, max_count=1)[0], diff_refs) - def tree(self, treeish = 'master', paths = []): + def tree(self, treeish = 'master'): """ The Tree object for the given treeish reference ``treeish`` is the reference (default 'master') - ``paths`` - is an optional Array of directory paths to restrict the tree (default []) Examples:: - repo.tree('master', ['lib/']) + repo.tree('master') Returns ``GitPython.Tree`` """ - return Tree.construct(self, treeish, paths) + return Tree(self, id=treeish) def blob(self, id): """ diff --git a/lib/git/tree.py b/lib/git/tree.py index 86e893ef..1ed3396d 100644 --- a/lib/git/tree.py +++ b/lib/git/tree.py @@ -21,28 +21,18 @@ class Tree(LazyMixin): setattr(self, k, v) def __bake__(self): - temp = Tree.construct(self.repo, self.id) - self.contents = temp.contents + # Ensure the treeish references directly a tree + treeish = self.id + if not treeish.endswith(':'): + treeish = treeish + ':' - @classmethod - def construct(cls, repo, treeish, paths = []): - output = repo.git.ls_tree(treeish, *paths) - return Tree(repo, id=treeish).construct_initialize(repo, treeish, output) - - def construct_initialize(self, repo, id, text): - self.repo = repo - self.id = id + # Read the tree contents. self.contents = {} - self.__baked__ = False - - for line in text.splitlines(): + for line in self.repo.git.ls_tree(self.id).splitlines(): obj = self.content_from_string(self.repo, line) if obj: self.contents[obj.name] = obj - self.__bake_it__() - return self - def content_from_string(self, repo, text): """ Parse a content item and create the appropriate object -- cgit v1.2.1