simplemerge: support three labels 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
--- a/mercurial/simplemerge.py Tue Aug 05 14:56:25 2014 -0700
+++ b/mercurial/simplemerge.py Tue Aug 05 15:10:50 2014 -0700
@@ -379,13 +379,16 @@
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)
@@ -402,7 +405,11 @@
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'):
--- a/tests/test-contrib.t Tue Aug 05 14:56:25 2014 -0700
+++ b/tests/test-contrib.t Tue Aug 05 15:10:50 2014 -0700
@@ -184,10 +184,25 @@
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