From 8e29bcd2fd67066143b88de8829130c6af043e2f Mon Sep 17 00:00:00 2001 From: Catalin Marinas Date: Thu, 18 Aug 2005 13:46:20 +0100 Subject: [PATCH] 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 --- stgit/git.py | 13 +++++++++++++ stgit/stack.py | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) 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 -- 2.11.0