simplemerge: add a specialized function for "union", "local", "other"
authorMartin von Zweigbergk <martinvonz@google.com>
Tue, 07 Dec 2021 22:33:18 -0800
changeset 48514 fb691fa90807
parent 48513 47f2a82ae3e4
child 48515 bd27dad294b7
simplemerge: add a specialized function for "union", "local", "other" Differential Revision: https://phab.mercurial-scm.org/D11901
mercurial/simplemerge.py
--- a/mercurial/simplemerge.py	Sat Dec 18 11:47:03 2021 +0100
+++ b/mercurial/simplemerge.py	Tue Dec 07 22:33:18 2021 -0800
@@ -484,6 +484,17 @@
     return lines, conflicts
 
 
+def _resolve(m3, sides):
+    lines = []
+    for group in m3.merge_groups():
+        if group[0] == b'conflict':
+            for side in sides:
+                lines.extend(group[side + 1])
+        else:
+            lines.extend(group[1])
+    return lines
+
+
 def simplemerge(ui, localctx, basectx, otherctx, **opts):
     """Performs the simplemerge algorithm.
 
@@ -515,30 +526,27 @@
         return 1
 
     m3 = Merge3Text(basetext, localtext, othertext)
-    extrakwargs = {
-        "localorother": None,
-        'minimize': True,
-    }
+    conflicts = False
     if mode == b'union':
-        extrakwargs['start_marker'] = None
-        extrakwargs['mid_marker'] = None
-        extrakwargs['end_marker'] = None
+        lines = _resolve(m3, (1, 2))
     elif mode == b'local':
-        extrakwargs['localorother'] = b'local'
+        lines = _resolve(m3, (1,))
     elif mode == b'other':
-        extrakwargs['localorother'] = b'other'
-    elif name_base is not None:
-        extrakwargs['base_marker'] = b'|||||||'
-        extrakwargs['name_base'] = name_base
-        extrakwargs['minimize'] = False
-
-    if mode == b'mergediff':
+        lines = _resolve(m3, (2,))
+    elif mode == b'mergediff':
         lines, conflicts = _mergediff(m3, name_a, name_b, name_base)
     else:
+        extrakwargs = {
+            'minimize': True,
+        }
+        if name_base is not None:
+            extrakwargs['base_marker'] = b'|||||||'
+            extrakwargs['name_base'] = name_base
+            extrakwargs['minimize'] = False
         lines = list(
             m3.merge_lines(name_a=name_a, name_b=name_b, **extrakwargs)
         )
-        conflicts = m3.conflicts and not mode == b'union'
+        conflicts = m3.conflicts
 
     mergedtext = b''.join(lines)
     if opts.get('print'):