Patchwork [1,of,3,V3] simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers

login
register
mail settings
Submitter Erik Huelsmann
Date Aug. 16, 2015, 8:56 a.m.
Message ID <e764eb7b6562351501a1.1439715380@lsmb-dev-jessie>
Download mbox | patch
Permalink /patch/10217/
State Accepted
Commit 09d6725cbc602e232aa34eb6fffb81639b951529
Delegated to: Matt Mackall
Headers show

Comments

Erik Huelsmann - Aug. 16, 2015, 8:56 a.m.
# HG changeset patch
# User Erik Huelsmann <ehuels@gmail.com>
# Date 1439676034 -7200
#      Sun Aug 16 00:00:34 2015 +0200
# Node ID e764eb7b6562351501a11d58235801e0e06afac5
# Parent  9e7d805925c87cfa0ca30819e8273ac37fd77a62
simplemerge: add 'mode' kwarg which - when 'union' - suppresses markers

This is a step toward adding 'union merge' to the internal merge tool.

'union merge' is a merge strategy which adds both left and right hand side
of a conflict region.  Git implements this merge strategy which is very
practical to have for merging to e.g. the Changelog file.

Note: the identifiers with underscores in this commit are all using existing
   variable names and/or keyword arguments.

Patch

diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -100,9 +100,9 @@ 
                 newline = '\r\n'
             elif self.a[0].endswith('\r'):
                 newline = '\r'
-        if name_a:
+        if name_a and start_marker:
             start_marker = start_marker + ' ' + name_a
-        if name_b:
+        if name_b and end_marker:
             end_marker = end_marker + ' ' + name_b
         if name_base and base_marker:
             base_marker = base_marker + ' ' + name_base
@@ -120,17 +120,20 @@ 
                     yield self.b[i]
             elif what == 'conflict':
                 self.conflicts = True
-                yield start_marker + newline
+                if start_marker is not None:
+                    yield start_marker + newline
                 for i in range(t[3], t[4]):
                     yield self.a[i]
                 if base_marker is not None:
                     yield base_marker + newline
                     for i in range(t[1], t[2]):
                         yield self.base[i]
-                yield mid_marker + newline
+                if mid_marker is not None:
+                    yield mid_marker + newline
                 for i in range(t[5], t[6]):
                     yield self.b[i]
-                yield end_marker + newline
+                if end_marker is not None:
+                    yield end_marker + newline
             else:
                 raise ValueError(what)
 
@@ -353,18 +356,24 @@ 
                 raise util.Abort(msg)
         return text
 
-    name_a = local
-    name_b = other
-    name_base = None
-    labels = opts.get('label', [])
-    if len(labels) > 0:
-        name_a = labels[0]
-    if len(labels) > 1:
-        name_b = labels[1]
-    if len(labels) > 2:
-        name_base = labels[2]
-    if len(labels) > 3:
-        raise util.Abort(_("can only specify three labels."))
+    mode = opts.get('mode','merge')
+    if mode == 'union':
+        name_a = None
+        name_b = None
+        name_base = None
+    else:
+        name_a = local
+        name_b = other
+        name_base = None
+        labels = opts.get('label', [])
+        if len(labels) > 0:
+            name_a = labels[0]
+        if len(labels) > 1:
+            name_b = labels[1]
+        if len(labels) > 2:
+            name_base = labels[2]
+        if len(labels) > 3:
+            raise util.Abort(_("can only specify three labels."))
 
     try:
         localtext = readfile(local)
@@ -382,7 +391,11 @@ 
 
     m3 = Merge3Text(basetext, localtext, othertext)
     extrakwargs = {}
-    if name_base is not None:
+    if mode == 'union':
+        extrakwargs['start_marker'] = None
+        extrakwargs['mid_marker'] = None
+        extrakwargs['end_marker'] = None
+    elif name_base is not None:
         extrakwargs['base_marker'] = '|||||||'
         extrakwargs['name_base'] = name_base
     for line in m3.merge_lines(name_a=name_a, name_b=name_b, **extrakwargs):
@@ -391,7 +404,7 @@ 
     if not opts.get('print'):
         out.close()
 
-    if m3.conflicts:
+    if m3.conflicts and not mode == 'union':
         if not opts.get('quiet'):
             ui.warn(_("warning: conflicts during merge.\n"))
         return 1