[PATCH 2 of 6 V2] simplermerge: support three label when merging

pierre-yves.david at ens-lyon.org pierre-yves.david at ens-lyon.org
Tue Aug 5 18:30:42 CDT 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1407276650 25200
#      Tue Aug 05 15:10:50 2014 -0700
# Node ID e6fa924a5144ddfeddd4a7c2e9b26af694eef53c
# Parent  3630e859cb13ace36f3171142732dc8718d62979
simplermerge: support three label when merging

If a third label is provided it will be used for the "base" content:

  <<<<<<< local
  content
  from
  local
  ||||||| base
  former
  common
  =======
  other
  conflicting
  >>>>>>> other

diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -377,17 +377,20 @@ def simplemerge(ui, local, base, other, 
                 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:
-        raise util.Abort(_("can only specify two labels."))
+        name_base = labels[2]
+    if len(labels) > 3:
+        raise util.Abort(_("can only specify three labels."))
 
     try:
         localtext = readfile(local)
         basetext = readfile(base)
         othertext = readfile(other)
@@ -400,11 +403,15 @@ def simplemerge(ui, local, base, other, 
         out = opener(os.path.basename(local), "w", atomictemp=True)
     else:
         out = sys.stdout
 
     m3 = Merge3Text(basetext, localtext, othertext)
-    for line in m3.merge_lines(name_a=name_a, name_b=name_b):
+    extrakwargs = {}
+    if 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):
         out.write(line)
 
     if not opts.get('print'):
         out.close()
 
diff --git a/tests/test-contrib.t b/tests/test-contrib.t
--- a/tests/test-contrib.t
+++ b/tests/test-contrib.t
@@ -182,14 +182,29 @@ 2 labels
   end
   >>>>>>> bar
   warning: conflicts during merge.
   [1]
 
+3 labels
+
+  $ python simplemerge -p -L foo -L bar -L base conflict-local base conflict-other
+  base
+  <<<<<<< foo
+  not other
+  end
+  ||||||| base
+  =======
+  other
+  end
+  >>>>>>> bar
+  warning: conflicts during merge.
+  [1]
+
 too many labels
 
-  $ python simplemerge -p -L foo -L bar -L baz conflict-local base conflict-other
-  abort: can only specify two labels.
+  $ python simplemerge -p -L foo -L bar -L baz -L buz conflict-local base conflict-other
+  abort: can only specify three labels.
   [255]
 
 binary file
 
   $ python -c "f = file('binary-local', 'w'); f.write('\x00'); f.close()"


More information about the Mercurial-devel mailing list