[PATCH 6 of 6 mergedriver] filemerge: call premerge directly from main merge function

Siddharth Agarwal sid0 at fb.com
Thu Oct 8 02:33:17 CDT 2015


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1444278136 25200
#      Wed Oct 07 21:22:16 2015 -0700
# Node ID 8b73dc446e92cf163589e5ac97daad7b54317077
# Parent  57d94e0c31e4072ffdf0aa4a7fa2934e22dfe068
filemerge: call premerge directly from main merge function

The merge code currently does (in pseudocode):

for f in tomerge:
    premerge f
    merge f

We'd like to change this to look more like:

for f in tomerge:
    premerge f

for f in tomerge:
    merge f

This makes sure as many files are resolved as possible before prompting for the
others. This restructuring is also necessary for custom merge drivers.

This function separates out the premerge step from the merge step. In future
patches we'll actually turn these into separate steps in the merge driver.

The 'if r:' occurrences will be cleaned up in subsequent patches.

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -247,7 +247,7 @@ def _merge(repo, mynode, orig, fcd, fco,
     files. It will fail if there are any conflicts and leave markers in
     the partially merged file. Markers will have two sections, one for each side
     of merge, unless mode equals 'union' which suppresses the markers."""
-    r = _premerge(repo, toolconf, files, labels=labels)
+    r = 1
     if r:
         a, b, c, back = files
 
@@ -349,7 +349,7 @@ def _idump(repo, mynode, orig, fcd, fco,
     ``a.txt``, these files will accordingly be named ``a.txt.local``,
     ``a.txt.other`` and ``a.txt.base`` and they will be placed in the
     same directory as ``a.txt``."""
-    r = _premerge(repo, toolconf, files, labels=labels)
+    r = 1
     if r:
         a, b, c, back = files
 
@@ -361,7 +361,7 @@ def _idump(repo, mynode, orig, fcd, fco,
     return False, r
 
 def _xmerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
-    r = _premerge(repo, toolconf, files, labels=labels)
+    r = 1
     if r:
         tool, toolpath, binary, symlink = toolconf
         a, b, c, back = files
@@ -519,8 +519,15 @@ def filemerge(repo, mynode, orig, fcd, f
         if markerstyle != 'basic':
             labels = _formatlabels(repo, fcd, fco, fca, labels)
 
-        needcheck, r = func(repo, mynode, orig, fcd, fco, fca, toolconf, files,
-                            labels=labels)
+        r = 1
+        if mergetype == fullmerge:
+            r = _premerge(repo, toolconf, files, labels=labels)
+
+        if not r:  # premerge successfully merged the file
+            needcheck = False
+        else:
+            needcheck, r = func(repo, mynode, orig, fcd, fco, fca, toolconf,
+                                files, labels=labels)
 
         if not needcheck:
             if r:


More information about the Mercurial-devel mailing list