Skip to content

Commit 785bf20

Browse files
newrengitster
authored andcommitted
merge-ort: resolve paths early when we have sufficient information
When there are no directories involved at a given path, and all three sides have a file at that path, and two of the three sides of history match, we can immediately resolve the merge of that path in collect_merge_info() and do not need to wait until process_entries(). This is actually a very minor improvement: half the time when I run it, I see an improvement; the other half a slowdown. It seems to be in the range of noise. However, this idea serves as the beginning of some bigger optimizations coming in the following patches. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent daab8a5 commit 785bf20

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

merge-ort.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,43 @@ static int collect_merge_info_callback(int n,
10231023
return mask;
10241024
}
10251025

1026+
/*
1027+
* If the sides match, and all three paths are present and are
1028+
* files, then we can take either as the resolution. We can't do
1029+
* this with trees, because there may be rename sources from the
1030+
* merge_base.
1031+
*/
1032+
if (sides_match && filemask == 0x07) {
1033+
/* use side1 (== side2) version as resolution */
1034+
setup_path_info(opt, &pi, dirname, info->pathlen, fullpath,
1035+
names, names+1, side1_null, 0,
1036+
filemask, dirmask, 1);
1037+
return mask;
1038+
}
1039+
1040+
/*
1041+
* If side1 matches mbase and all three paths are present and are
1042+
* files, then we can use side2 as the resolution. We cannot
1043+
* necessarily do so this for trees, because there may be rename
1044+
* destinations within side2.
1045+
*/
1046+
if (side1_matches_mbase && filemask == 0x07) {
1047+
/* use side2 version as resolution */
1048+
setup_path_info(opt, &pi, dirname, info->pathlen, fullpath,
1049+
names, names+2, side2_null, 0,
1050+
filemask, dirmask, 1);
1051+
return mask;
1052+
}
1053+
1054+
/* Similar to above but swapping sides 1 and 2 */
1055+
if (side2_matches_mbase && filemask == 0x07) {
1056+
/* use side1 version as resolution */
1057+
setup_path_info(opt, &pi, dirname, info->pathlen, fullpath,
1058+
names, names+1, side1_null, 0,
1059+
filemask, dirmask, 1);
1060+
return mask;
1061+
}
1062+
10261063
/*
10271064
* Gather additional information used in rename detection.
10281065
*/

0 commit comments

Comments
 (0)