]> git.ipfire.org Git - thirdparty/git.git/commitdiff
merge-ort: resolve paths early when we have sufficient information
authorElijah Newren <newren@gmail.com>
Fri, 16 Jul 2021 05:22:31 +0000 (05:22 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 20 Jul 2021 21:47:39 +0000 (14:47 -0700)
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 <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
merge-ort.c

index 8cfa0ccd3c87695592eb52af7d2125082b4b4cb4..570432697366b9766ee1c5dbb505bd4f8f95e7b9 100644 (file)
@@ -1023,6 +1023,43 @@ static int collect_merge_info_callback(int n,
                return mask;
        }
 
+       /*
+        * If the sides match, and all three paths are present and are
+        * files, then we can take either as the resolution.  We can't do
+        * this with trees, because there may be rename sources from the
+        * merge_base.
+        */
+       if (sides_match && filemask == 0x07) {
+               /* use side1 (== side2) version as resolution */
+               setup_path_info(opt, &pi, dirname, info->pathlen, fullpath,
+                               names, names+1, side1_null, 0,
+                               filemask, dirmask, 1);
+               return mask;
+       }
+
+       /*
+        * If side1 matches mbase and all three paths are present and are
+        * files, then we can use side2 as the resolution.  We cannot
+        * necessarily do so this for trees, because there may be rename
+        * destinations within side2.
+        */
+       if (side1_matches_mbase && filemask == 0x07) {
+               /* use side2 version as resolution */
+               setup_path_info(opt, &pi, dirname, info->pathlen, fullpath,
+                               names, names+2, side2_null, 0,
+                               filemask, dirmask, 1);
+               return mask;
+       }
+
+       /* Similar to above but swapping sides 1 and 2 */
+       if (side2_matches_mbase && filemask == 0x07) {
+               /* use side1 version as resolution */
+               setup_path_info(opt, &pi, dirname, info->pathlen, fullpath,
+                               names, names+1, side1_null, 0,
+                               filemask, dirmask, 1);
+               return mask;
+       }
+
        /*
         * Gather additional information used in rename detection.
         */