simplemerge: use 3-way markers if mode=='merge3', ignoring number of labels
authorMartin von Zweigbergk <martinvonz@google.com>
Tue, 14 Dec 2021 13:12:56 -0800
changeset 48583 c91418480cb0
parent 48582 0dc698c91ca0
child 48584 ce8c82a5cd65
simplemerge: use 3-way markers if mode=='merge3', ignoring number of labels Before this patch, we use a combination of `mode` and `labels` to decide which marker style to use. That's mostly my own fault because I was the one who added the `mergediff` as a "mode" instead of adding a separate argument for marker style. Still, let's make these arguments more orthogonal by ignoring the number of labels when deciding which marker style to use. This refactoring makes it a little clearer in the simplemerge *extension* that passing more than 2 `--label` arguments changes the marker style. Differential Revision: https://phab.mercurial-scm.org/D11972
contrib/simplemerge
mercurial/filemerge.py
mercurial/simplemerge.py
--- a/contrib/simplemerge	Fri Jan 14 10:25:45 2022 -0800
+++ b/contrib/simplemerge	Tue Dec 14 13:12:56 2021 -0800
@@ -80,6 +80,8 @@
         sys.exit(0)
     if len(args) != 3:
         raise ParseError(_(b'wrong number of arguments').decode('utf8'))
+    if len(opts[b'label']) > 2:
+        opts[b'mode'] = b'merge3'
     local, base, other = args
     sys.exit(
         simplemerge.simplemerge(
--- a/mercurial/filemerge.py	Fri Jan 14 10:25:45 2022 -0800
+++ b/mercurial/filemerge.py	Tue Dec 14 13:12:56 2021 -0800
@@ -421,14 +421,15 @@
             )
 
     if premerge:
+        if not labels:
+            labels = _defaultconflictlabels
+        if len(labels) < 3:
+            labels.append(b'base')
         mode = b'merge'
-        if premerge in {b'keep-merge3', b'keep-mergediff'}:
-            if not labels:
-                labels = _defaultconflictlabels
-            if len(labels) < 3:
-                labels.append(b'base')
-            if premerge == b'keep-mergediff':
-                mode = b'mergediff'
+        if premerge == b'keep-mergediff':
+            mode = b'mergediff'
+        elif premerge == b'keep-merge3':
+            mode = b'merge3'
         r = simplemerge.simplemerge(
             ui, fcd, fca, fco, quiet=True, label=labels, mode=mode
         )
@@ -532,7 +533,9 @@
         labels = _defaultconflictlabels
     if len(labels) < 3:
         labels.append(b'base')
-    return _imerge(repo, mynode, fcd, fco, fca, toolconf, backup, labels)
+    return _merge(
+        repo, mynode, fcd, fco, fca, toolconf, backup, labels, b'merge3'
+    )
 
 
 @internaltool(
--- a/mercurial/simplemerge.py	Fri Jan 14 10:25:45 2022 -0800
+++ b/mercurial/simplemerge.py	Tue Dec 14 13:12:56 2021 -0800
@@ -506,7 +506,7 @@
             extrakwargs = {
                 'minimize': True,
             }
-            if name_base is not None:
+            if mode == b'merge3':
                 extrakwargs['base_marker'] = b'|||||||'
                 extrakwargs['name_base'] = name_base
                 extrakwargs['minimize'] = False