{"thread":{"id":"13110","subject":"[StGit PATCH] If a patch is not changed when pushing, reuse the same commit object","startedAt":"2008-04-14T21:21:50Z","lastAt":"2008-04-14T21:21:50Z","messageCount":1,"participants":["Karl Hasselström"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"74381","messageId":"20080414212150.7334.92647.stgit@yoghurt","threadId":"13110","inReplyTo":null,"subject":"[StGit PATCH] If a patch is not changed when pushing, reuse the same commit object","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-04-14T21:21:50Z","receivedAt":"2008-04-14T21:21:50Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"It should be marginally faster since we don't have to create a new\ncommit object, but mostly it's a cleanliness issue: rewriting history\nwhen we don't have to is bad.\n\nSigned-off-by: Karl Hasselström <kha@treskal.com>\n\n---\n\n stgit/lib/transaction.py |   10 +++++++---\n 1 files changed, 7 insertions(+), 3 deletions(-)\n\n\ndiff --git a/stgit/lib/transaction.py b/stgit/lib/transaction.py\nindex 2946a67..9a23c01 100644\n--- a/stgit/lib/transaction.py\n+++ b/stgit/lib/transaction.py\n@@ -175,8 +175,8 @@ class StackTransaction(object):\n         \"\"\"Attempt to push the named patch. If this results in conflicts,\n         halts the transaction. If index+worktree are given, spill any\n         conflicts to them.\"\"\"\n-        cd = self.patches[pn].data\n-        cd = cd.set_committer(None)\n+        orig_cd = self.patches[pn].data\n+        cd = orig_cd.set_committer(None)\n         s = ['', ' (empty)'][cd.is_nochange()]\n         oldparent = cd.parent\n         cd = cd.set_parent(self.__head)\n@@ -204,7 +204,11 @@ class StackTransaction(object):\n             except git.MergeException, e:\n                 self.__halt(str(e))\n         cd = cd.set_tree(tree)\n-        self.patches[pn] = self.__stack.repository.commit(cd)\n+        if any(getattr(cd, a) != getattr(orig_cd, a) for a in\n+               ['parent', 'tree', 'author', 'message']):\n+            self.patches[pn] = self.__stack.repository.commit(cd)\n+        else:\n+            s = ' (unmodified)'\n         del self.unapplied[self.unapplied.index(pn)]\n         self.applied.append(pn)\n         out.info('Pushed %s%s' % (pn, s))\n"}]}