Patchwork D11901: simplemerge: add a specialized function for "union", "local", "other"

login
register
mail settings
Submitter phabricator
Date Dec. 11, 2021, 2:02 a.m.
Message ID <differential-rev-PHID-DREV-ku5a5ugxusp6cs7ehr44-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50227/
State New
Headers show

Comments

phabricator - Dec. 11, 2021, 2:02 a.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11901

AFFECTED FILES
  mercurial/simplemerge.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -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'):