diff options
| author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-11 19:07:03 +0200 |
|---|---|---|
| committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-11 19:07:03 +0200 |
| commit | 15b9129ec639112e94ea96b6a395ad9b149515d1 (patch) | |
| tree | c1a3388f25447a4ffc2c9e11912b4352a2f8ffd9 /lib/git/tag.py | |
| parent | 7a7eedde7f5d5082f7f207ef76acccd24a6113b1 (diff) | |
| download | GitPython-15b9129ec639112e94ea96b6a395ad9b149515d1.tar.gz GitPython-15b9129ec639112e94ea96b6a395ad9b149515d1.zip | |
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
Diffstat (limited to 'lib/git/tag.py')
| -rw-r--r-- | lib/git/tag.py | 52 |
1 files changed, 25 insertions, 27 deletions
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 <hexsha> - type_token, type_name = lines[1].split(" ") # type <type_name> - self.object = base.Object.get_type_by_name(type_name)(self.repo, hexsha) - - self.tag = lines[2][4:] # tag <tag name> - - tagger_info = lines[3][7:]# tagger <actor> <date> - 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 <hexsha> + type_token, type_name = lines[1].split(" ") # type <type_name> + self.object = base.Object.get_type_by_name(type_name)(self.repo, hexsha) + + self.tag = lines[2][4:] # tag <tag name> + + tagger_info = lines[3][7:]# tagger <actor> <date> + 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) |
