chiark / gitweb /
Optimise the Commit objects creation
authorCatalin Marinas <catalin.marinas@gmail.com>
Thu, 18 Aug 2005 12:46:20 +0000 (13:46 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Thu, 18 Aug 2005 12:46:20 +0000 (13:46 +0100)
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>
stgit/git.py
stgit/stack.py

index 9d8cdf0d099f5d83f10cea6897680ecc0cb56ea0..c1c20c78cbe7c814be4de7a87ef0155ad092b8fb 100644 (file)
@@ -75,10 +75,23 @@ class Commit:
     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
     """
index 065c08493bb103bd241021e93dc42cd9e9c684ed..71f038d84bb56746a57ea185f17c7670b89b9930 100644 (file)
@@ -540,7 +540,8 @@ class Series:
 
         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