Skip to content

Commit 566b5c0

Browse files
torvaldsgitster
authored andcommitted
Optimize the three-way merge of git-read-tree
As mentioned, the three-way case *should* be as trivial as the following. It passes all the tests, and I verified that a conflicting merge in the 100,000 file horror-case merged correctly (with the conflict markers) in 0.687 seconds with this, so it works, but I'm lazy and somebody else should double-check it [jc: followed all three-way merge codepaths and verified it removes when it should]. Without this patch, the merge took 8.355 seconds, so this patch really does make a huge difference for merge performance with lots and lots of files, and we're not talking percentages, we're talking orders-of-magnitude differences! Now "unpack_trees()" is just fast enough that we don't need to avoid it (although it's probably still a good idea to eventually convert it to use the traverse_trees() infrastructure some day - just to avoid having extraneous tree traversal functions). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent cbbb218 commit 566b5c0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

unpack-trees.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,6 @@ int threeway_merge(struct cache_entry **stages,
667667
int no_anc_exists = 1;
668668
int i;
669669

670-
remove_entry(remove);
671670
for (i = 1; i < o->head_idx; i++) {
672671
if (!stages[i] || stages[i] == o->df_conflict_entry)
673672
any_anc_missing = 1;
@@ -730,8 +729,10 @@ int threeway_merge(struct cache_entry **stages,
730729
}
731730

732731
/* #1 */
733-
if (!head && !remote && any_anc_missing)
732+
if (!head && !remote && any_anc_missing) {
733+
remove_entry(remove);
734734
return 0;
735+
}
735736

736737
/* Under the new "aggressive" rule, we resolve mostly trivial
737738
* cases that we historically had git-merge-one-file resolve.
@@ -763,6 +764,7 @@ int threeway_merge(struct cache_entry **stages,
763764
if ((head_deleted && remote_deleted) ||
764765
(head_deleted && remote && remote_match) ||
765766
(remote_deleted && head && head_match)) {
767+
remove_entry(remove);
766768
if (index)
767769
return deleted_entry(index, index, o);
768770
else if (ce && !head_deleted)
@@ -785,6 +787,7 @@ int threeway_merge(struct cache_entry **stages,
785787
verify_uptodate(index, o);
786788
}
787789

790+
remove_entry(remove);
788791
o->nontrivial_merge = 1;
789792

790793
/* #2, #3, #4, #6, #7, #9, #10, #11. */

0 commit comments

Comments
 (0)