git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[StGit PATCH 1/5] If a patch is not changed when pushing, reuse the same commit object

From
Karl Hasselström <kha@treskal.com>
Date
Apr 17, 2008, 21:12 UTC
Message-ID
<20080417211247.12809.90469.stgit@yoghurt>
In-Reply-To
<20080417210137.12809.88457.stgit@yoghurt>

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 |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/stgit/lib/transaction.py b/stgit/lib/transaction.py
index 2946a67..1ece01e 100644
--- a/stgit/lib/transaction.py
+++ b/stgit/lib/transaction.py
@@ -1,4 +1,5 @@
 from stgit import exception, utils
+from stgit.utils import any, all
 from stgit.out import *
 from stgit.lib import git
 
@@ -175,8 +176,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 +205,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))
Previous: Karl HasselströmNext: Karl Hasselström
Message 2 of 7 in “test suite update”
  1. 0/5 test suite updateKarl Hasselström, Apr 17, 2008
  2. 1/5 If a patch is not changed when pushing, reuse the same commit objectKarl Hasselström, Apr 17, 2008
  3. 2/5 Use hardcoded author and committer names in testsKarl Hasselström, Apr 17, 2008
  4. 3/5 Steal more test-lib.sh updates from gitKarl Hasselström, Apr 17, 2008
  5. 4/5 Get rid of backticks in test-lib.shKarl Hasselström, Apr 17, 2008
  6. 5/5 Use test_cmp instead of diff -u in the test suiteKarl Hasselström, Apr 17, 2008
  7. Karl HasselströmApr 17, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.