threads / patch / 13110

patchIf a patch is not changed when pushing, reuse the same commit object

Subject: [StGit PATCH] If a patch is not changed when pushing, reuse the same commit object

## tl;dr

One message between Apr 14, 2008 and Apr 14, 2008. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Karl Hasselström· Apr 14, 2008, 21:21 UTC · lore

It should be marginally faster since we don't have to create a new commit object, but mostly it's a cleanliness issue: rewriting history when we don't have to is bad.

Signed-off-by: Karl Hasselström <kha@treskal.com>
---
 stgit/lib/transaction.py |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
Show changes to stgit/lib/transaction.py +7 −3
diff --git a/stgit/lib/transaction.py b/stgit/lib/transaction.py
index 2946a67..9a23c01 100644
--- a/stgit/lib/transaction.py
+++ b/stgit/lib/transaction.py
@@ -175,8 +175,8 @@ class StackTransaction(object):
         """Attempt to push the named patch. If this results in conflicts,
         halts the transaction. If index+worktree are given, spill any
         conflicts to them."""
-        cd = self.patches[pn].data
-        cd = cd.set_committer(None)
+        orig_cd = self.patches[pn].data
+        cd = orig_cd.set_committer(None)
         s = ['', ' (empty)'][cd.is_nochange()]
         oldparent = cd.parent
         cd = cd.set_parent(self.__head)
@@ -204,7 +204,11 @@ class StackTransaction(object):
             except git.MergeException, e:
                 self.__halt(str(e))
         cd = cd.set_tree(tree)
-        self.patches[pn] = self.__stack.repository.commit(cd)
+        if any(getattr(cd, a) != getattr(orig_cd, a) for a in
+               ['parent', 'tree', 'author', 'message']):
+            self.patches[pn] = self.__stack.repository.commit(cd)
+        else:
+            s = ' (unmodified)'
         del self.unapplied[self.unapplied.index(pn)]
         self.applied.append(pn)
         out.info('Pushed %s%s' % (pn, s))

← back to recent threads