From: Catalin Marinas Date: Thu, 18 Aug 2005 12:46:20 +0000 (+0100) Subject: Optimise the Commit objects creation X-Git-Tag: v0.14.3~706 X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/commitdiff_plain/8e29bcd2fd67066143b88de8829130c6af043e2f?hp=e4f41f5d393b5f1e83a39a42a5f204efb6ef7ea6 Optimise the Commit objects creation 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 --- diff --git a/stgit/git.py b/stgit/git.py index 9d8cdf0..c1c20c7 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -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 """ diff --git a/stgit/stack.py b/stgit/stack.py index 065c084..71f038d 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -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