The Commit objects are used for commands like 'series' to check whether
a patch is empty or not. Since the bottom of a patch is usually the same
as the top of the previous one, it makes sense to cache the Commit
objects and reduce their creation (and git-cat-file calls) to half. This
patch adds a Commit objects factory which caches the results.
Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
def get_committer(self):
return self.__committer
+# dictionary of Commit objects, used to avoid multiple calls to git
+__commits = dict()
#
# Functions
#
+def get_commit(id_hash):
+ """Commit objects factory. Save/look-up them in the __commits
+ dictionary
+ """
+ if id_hash in __commits:
+ return __commits[id_hash]
+ else:
+ commit = Commit(id_hash)
+ __commits[id_hash] = commit
+ return commit
+
def get_conflicts():
"""Return the list of file conflicts
"""
if bottom == top:
return True
- elif git.Commit(top).get_tree() == git.Commit(bottom).get_tree():
+ elif git.get_commit(top).get_tree() \
+ == git.get_commit(bottom).get_tree():
return True
return False