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/commit.py | |
parent | 7a7eedde7f5d5082f7f207ef76acccd24a6113b1 (diff) | |
download | gitpython-15b9129ec639112e94ea96b6a395ad9b149515d1.tar.gz |
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/commit.py')
-rw-r--r-- | lib/git/commit.py | 69 |
1 files changed, 28 insertions, 41 deletions
diff --git a/lib/git/commit.py b/lib/git/commit.py index 1ae84799..5d494621 100644 --- a/lib/git/commit.py +++ b/lib/git/commit.py @@ -25,6 +25,8 @@ class Commit(base.Object): # object configuration type = "commit" + __slots__ = ("tree", "author", "authored_date", "committer", "committed_date", + "message", "parents") def __init__(self, repo, id, tree=None, author=None, authored_date=None, committer=None, committed_date=None, message=None, parents=None): @@ -38,7 +40,7 @@ class Commit(base.Object): is the sha id of the commit ``parents`` : list( Commit, ... ) - is a list of commit ids + is a list of commit ids or actual Commits ``tree`` : Tree is the corresponding tree id @@ -61,49 +63,34 @@ class Commit(base.Object): Returns git.Commit """ - super(Commit,self).__init__(repo, id, "commit") - self.parents = None - self.tree = None - self.author = author - self.authored_date = authored_date - self.committer = committer - self.committed_date = committed_date - self.message = message - - if self.id: - if parents is not None: - self.parents = [Commit(repo, p) for p in parents] - if tree is not None: - self.tree = Tree(repo, id=tree) - - def __eq__(self, other): - return self.id == other.id - - def __ne__(self, other): - return self.id != other.id - - def __bake__(self): - """ - Called by LazyMixin superclass when the first uninitialized member needs - to be set as it is queried. - """ - super(Commit, self).__bake__() - temp = Commit.find_all(self.repo, self.id, max_count=1)[0] - self.parents = temp.parents - self.tree = temp.tree - self.author = temp.author - self.authored_date = temp.authored_date - self.committer = temp.committer - self.committed_date = temp.committed_date - self.message = temp.message + super(Commit,self).__init__(repo, id) + self._set_self_from_args_(locals()) - @property - def id_abbrev(self): + if parents is not None: + self.parents = tuple( self.__class__(repo, p) for p in parents ) + # END for each parent to convert + + if self.id and tree is not None: + self.tree = Tree(repo, id=tree) + # END id to tree conversion + + def _set_cache_(self, attr): """ - Returns - First 7 bytes of the commit's sha id as an abbreviation of the full string. + Called by LazyMixin superclass when the given uninitialized member needs + to be set. + We set all values at once. """ - return self.id[0:7] + if attr in self.__slots__: + temp = Commit.find_all(self.repo, self.id, max_count=1)[0] + self.parents = temp.parents + self.tree = temp.tree + self.author = temp.author + self.authored_date = temp.authored_date + self.committer = temp.committer + self.committed_date = temp.committed_date + self.message = temp.message + else: + super(Commit, self)._set_cache_(attr) @property def summary(self): |