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/tag.py | 52 +++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) (limited to 'lib/git/tag.py') diff --git a/lib/git/tag.py b/lib/git/tag.py index 4266a7a9..89060ee0 100644 --- a/lib/git/tag.py +++ b/lib/git/tag.py @@ -74,7 +74,7 @@ class TagObject(base.Object): type = "tag" __slots__ = ( "object", "tag", "tagger", "tagged_date", "message" ) - def __init__(self, repo, id, size=None, object=None, tag=None, + def __init__(self, repo, id, object=None, tag=None, tagger=None, tagged_date=None, message=None): """ Initialize a tag object with additional data @@ -85,9 +85,6 @@ class TagObject(base.Object): ``id`` SHA1 or ref suitable for git-rev-parse - ``size`` - Size of the object's data in bytes - ``object`` Object instance of object we are pointing to @@ -100,29 +97,30 @@ class TagObject(base.Object): ``tagged_date`` : (tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst) is the DateTime of the tag creation """ - super(TagObject, self).__init__(repo, id , size) - self.object = object - self.tag = tag - self.tagger = tagger - self.tagged_date = tagged_date - self.message = message - - def __bake__(self): - super(TagObject, self).__bake__() - - output = self.repo.git.cat_file(self.type,self.id) - lines = output.split("\n") - - obj, hexsha = lines[0].split(" ") # object - type_token, type_name = lines[1].split(" ") # type - self.object = base.Object.get_type_by_name(type_name)(self.repo, hexsha) - - self.tag = lines[2][4:] # tag - - tagger_info = lines[3][7:]# tagger - self.tagger, self.tagged_date = commit.Commit._actor(tagger_info) + super(TagObject, self).__init__(repo, id ) + self._set_self_from_args_(locals()) - # line 4 empty - check git source to figure out purpose - self.message = "\n".join(lines[5:]) + def _set_cache_(self, attr): + """ + Cache all our attributes at once + """ + if attr in self.__slots__: + output = self.repo.git.cat_file(self.type,self.id) + lines = output.split("\n") + + obj, hexsha = lines[0].split(" ") # object + type_token, type_name = lines[1].split(" ") # type + self.object = base.Object.get_type_by_name(type_name)(self.repo, hexsha) + + self.tag = lines[2][4:] # tag + + tagger_info = lines[3][7:]# tagger + self.tagger, self.tagged_date = commit.Commit._actor(tagger_info) + + # line 4 empty - check git source to figure out purpose + self.message = "\n".join(lines[5:]) + # END check our attributes + else: + super(TagObject, self)._set_cache_(attr) -- cgit v1.2.3