From bc1ecd0bb28c457634ea5ea747c55945d1aa1997 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Karl=20Hasselstr=C3=B6m?= Date: Wed, 23 Jul 2008 23:29:09 +0200 Subject: [PATCH] Do simple in-index merge with diff+apply instead of read-tree MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- stgit/lib/git.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/stgit/lib/git.py b/stgit/lib/git.py index 6929698..732858e 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, quiet = True) 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, quiet): """In-index patch application, no worktree involved.""" try: @@ -561,6 +558,14 @@ class Index(RunWithEnv): r.no_output() except run.RunException: raise MergeException('Patch does not apply cleanly') + def apply_treediff(self, tree1, tree2, quiet): + """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; in other words, we don't have + # to use --binary. + self.apply(self.__repository.diff_tree(tree1, tree2, ['--full-index']), + quiet) def delete(self): if os.path.isfile(self.__filename): os.remove(self.__filename) -- 2.11.0