Skip to content

Commit 291f29c

Browse files
newrengitster
authored andcommitted
merge-ort: avoid recursing into identical trees
When all three trees have the same oid, there is no need to recurse into these trees to find that all files within them happen to match. We can just record any one of the trees as the resolution of merging that particular path. Immediately resolving trees for other types of trivial tree merges (such as one side matches the merge base, or the two sides match each other) would prevent us from detecting renames for some paths, and thus prevent us from doing three-way content merges for those paths whose renames we did not detect. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 98bf984 commit 291f29c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

merge-ort.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,19 @@ static int collect_merge_info_callback(int n,
367367
fullpath = xmalloc(len + 1);
368368
make_traverse_path(fullpath, len + 1, info, p->path, p->pathlen);
369369

370+
/*
371+
* If mbase, side1, and side2 all match, we can resolve early. Even
372+
* if these are trees, there will be no renames or anything
373+
* underneath.
374+
*/
375+
if (side1_matches_mbase && side2_matches_mbase) {
376+
/* mbase, side1, & side2 all match; use mbase as resolution */
377+
setup_path_info(opt, &pi, dirname, info->pathlen, fullpath,
378+
names, names+0, mbase_null, 0,
379+
filemask, dirmask, 1);
380+
return mask;
381+
}
382+
370383
/*
371384
* Record information about the path so we can resolve later in
372385
* process_entries.

0 commit comments

Comments
 (0)