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

[StGit PATCH 1/2] Do simple in-index merge with diff+apply instead of read-tree

From
Karl Hasselström <kha@treskal.com>
Date
Jul 2, 2008, 06:12 UTC
Message-ID
<20080702061243.11361.75544.stgit@yoghurt>
In-Reply-To
<20080702060113.11361.39006.stgit@yoghurt>

The advantage is that patch application will resolve some file content conflicts for us, so that we'll fall back to merge-recursive less often. This is a significant speedup, especially since merge-recursive needs to touch the worktree, which means we have to check out the index first.

(A simple test, pushing 250 patches in a 32k-file repository, with one file-level merge necessary per push, went from 1.07 to 0.36 seconds per patch with this patch applied.)

Signed-off-by: Karl Hasselström <kha@treskal.com>
---
 stgit/lib/git.py |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/stgit/lib/git.py b/stgit/lib/git.py
index 6ccdfa7..a38eaa5 100644
--- a/stgit/lib/git.py
+++ b/stgit/lib/git.py
@@ -475,9 +475,10 @@ class Repository(RunWithEnv):
             return ours
 
         index = self.temp_index()
+        index.read_tree(ours)
         try:
-            index.merge(base, ours, theirs)
             try:
+                index.apply_treediff(base, theirs)
                 return index.write_tree()
             except MergeException:
                 return None
@@ -548,10 +549,6 @@ class Index(RunWithEnv):
             return False
         else:
             return True
-    def merge(self, base, ours, theirs):
-        """In-index merge, no worktree involved."""
-        self.run(['git', 'read-tree', '-m', '-i', '--aggressive',
-                  base.sha1, ours.sha1, theirs.sha1]).no_output()
     def apply(self, patch_text):
         """In-index patch application, no worktree involved."""
         try:
@@ -559,6 +556,12 @@ class Index(RunWithEnv):
                      ).raw_input(patch_text).no_output()
         except run.RunException:
             raise MergeException('Patch does not apply cleanly')
+    def apply_treediff(self, tree1, tree2):
+        """Apply the diff from C{tree1} to C{tree2} to the index."""
+        # Passing --full-index here is necessary to support binary
+        # files. It is also sufficient, since the repository already
+        # contains all involved objects.
+        self.apply(self.__repository.diff_tree(tree1, tree2, ['--full-index']))
     def delete(self):
         if os.path.isfile(self.__filename):
             os.remove(self.__filename)
Previous: Karl HasselströmNext: Catalin Marinas
Message 2 of 9 in “push optimizations”
  1. 0/2 push optimizationsKarl Hasselström, Jul 2, 2008
  2. 1/2 Do simple in-index merge with diff+apply instead of read-treeKarl Hasselström, Jul 2, 2008
  3. Catalin MarinasJul 12, 2008
  4. 2/2 Reuse the same temp index in a transactionKarl Hasselström, Jul 2, 2008
  5. Reuse the same temp index in a transactionKarl Hasselström, Jul 3, 2008
  6. Catalin MarinasJul 12, 2008
  7. Karl HasselströmJul 14, 2008
  8. Catalin MarinasJul 7, 2008
  9. Karl HasselströmJul 8, 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.