From 15b9129ec639112e94ea96b6a395ad9b149515d1 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Oct 2009 19:07:03 +0200 Subject: lazymixin system now supports per-attribute baking, it is up to the class whether it bakes more. This also leads to more efficient use of memory as values are only cached and set when required - the baking system does not require an own tracking variable anymore, and values are only to be cached once - then python will natively find the cache without involving any additional overhead. This works by using __getattr__ instead of __get_attribute__ which would always be called --- lib/git/tree.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'lib/git/tree.py') diff --git a/lib/git/tree.py b/lib/git/tree.py index 90f1b72d..db4a3e22 100644 --- a/lib/git/tree.py +++ b/lib/git/tree.py @@ -13,18 +13,19 @@ class Tree(base.IndexObject): type = "tree" __slots__ = "_contents" - def __init__(self, repo, id, mode=None, path=None, size=None): - super(Tree, self).__init__(repo, id, mode, path, size) - self._contents = None - - def __bake__(self): - # Read the tree contents. - super(Tree, self).__bake__() - self._contents = {} - for line in self.repo.git.ls_tree(self.id).splitlines(): - obj = self.content_from_string(self.repo, line) - if obj is not None: - self._contents[obj.path] = obj + def __init__(self, repo, id, mode=None, path=None): + super(Tree, self).__init__(repo, id, mode, path) + + def _set_cache_(self, attr): + if attr == "_contents": + # Read the tree contents. + self._contents = {} + for line in self.repo.git.ls_tree(self.id).splitlines(): + obj = self.content_from_string(self.repo, line) + if obj is not None: + self._contents[obj.path] = obj + else: + super(Tree, self)._set_cache_(attr) @staticmethod def content_from_string(repo, text): -- cgit v1.2.1