[PATCH 2 of 2] simplemerge: Display "base" in case of conflict

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Thu Sep 27 05:06:22 CDT 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1348740176 -7200
# Node ID ce8ea3bbea8d818067750c06ebcf89f4c7471ddf
# Parent  ac1131f2927400cb0e031d6929cfa3ce07cf1a27
simplemerge: Display "base" in case of conflict

This changeset enables a feature already present in `simplemerge;py`: Displaying
common-base content during merges. For this purpose we have to disable an unused
function of simple merge.

Adding the base revision to merge conflict help a lot to understand the source
of a conflict. Being able to compare each side of the merge with the original
code allows to understand the changes introduced by each branches to create a
valid merge.

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -208,12 +208,13 @@ def _imerge(repo, mynode, orig, fcd, fco
     if r:
         a, b, c, back = files
 
         ui = repo.ui
         label = ['local: %s' % fcd.changectx(),
-                 'other: %s' % fco.changectx()]
-        r = simplemerge.simplemerge(ui, a, b, c, label=label)
+                 'other: %s' % fco.changectx(),
+                 'base: %s'  % fca.changectx()]
+        r = simplemerge.simplemerge(ui, a, b, c, label=label, no_minimal=True)
         return True, r
     return False, 0
 
 @internaltool('dump', True)
 def _idump(repo, mynode, orig, fcd, fco, fca, toolconf, files):
diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -413,17 +413,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 labels:
         name_a = labels.pop(0)
     if labels:
         name_b = labels.pop(0)
     if labels:
-        raise util.Abort(_("can only specify two labels."))
+        name_base = labels.pop(0)
+    if labels:
+        raise util.Abort(_("can only specify three labels."))
 
     try:
         localtext = readfile(local)
         basetext = readfile(base)
         othertext = readfile(other)
@@ -436,14 +439,22 @@ def simplemerge(ui, local, base, other, 
         out = opener(os.path.basename(local), "w", atomictemp=True)
     else:
         out = sys.stdout
 
     reprocess = not opts.get('no_minimal')
+    if reprocess and name_base:
+        msg = _("display of base incompatible conflict minimization")
+        raise util.Abort(msg, hint=_("add --no-minimal"))
+
 
     m3 = Merge3Text(basetext, localtext, othertext)
+    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,
-                               reprocess=reprocess):
+                               reprocess=reprocess, **extrakwargs):
         out.write(line)
 
     if not opts.get('print'):
         out.close()
 
diff --git a/tests/test-conflict.t b/tests/test-conflict.t
--- a/tests/test-conflict.t
+++ b/tests/test-conflict.t
@@ -22,10 +22,12 @@
   32e80765d7fe+75234512624c+ tip
 
   $ cat a
   <<<<<<< local: 32e80765d7fe+
   something else
+  ======= base: 54c73cdea408
+  nothing
   =======
   something
   >>>>>>> other: 75234512624c
 
   $ hg status
diff --git a/tests/test-contrib.t b/tests/test-contrib.t
--- a/tests/test-contrib.t
+++ b/tests/test-contrib.t
@@ -223,11 +223,11 @@ 2 labels
   [1]
 
 too many labels
 
   $ python simplemerge -p -L foo -L bar -L baz conflict-local base conflict-other
-  abort: can only specify two labels.
+  abort: display of base incompatible conflict minimization
   [255]
 
 binary file
 
   $ python -c "f = file('binary-local', 'w'); f.write('\x00'); f.close()"
diff --git a/tests/test-keyword.t b/tests/test-keyword.t
--- a/tests/test-keyword.t
+++ b/tests/test-keyword.t
@@ -1033,10 +1033,11 @@ conflict: keyword should stay outside co
   [1]
   $ cat m
   $Id$
   <<<<<<< local: 88a80c8d172e+
   bar
+  ======= base: 38d7794d6dad
   =======
   foo
   >>>>>>> other: 85d2d2d732a5
 
 resolve to local
diff --git a/tests/test-merge-local.t b/tests/test-merge-local.t
--- a/tests/test-merge-local.t
+++ b/tests/test-merge-local.t
@@ -73,10 +73,12 @@ Local merge with bad merge tool:
   +++ b/zzz1_merge_ok
   +new last line
   --- a/zzz2_merge_bad
   +++ b/zzz2_merge_bad
   +another last line
+  +======= base: 432e9bca7678
+  +new last line
   +=======
 
   $ hg st
   M zzz1_merge_ok
   M zzz2_merge_bad
@@ -107,13 +109,18 @@ Local merge with conflicts:
   +++ b/zzz1_merge_ok
   +new last line
   --- a/zzz2_merge_bad
   +++ b/zzz2_merge_bad
   +another last line
+  +======= base: 432e9bca7678
+  +new last line
   +=======
+  +======= base: c929647821fa
   +=======
   +new last line
+  +======= base: 432e9bca7678
+  +new last line
   +=======
 
   $ hg st
   M zzz1_merge_ok
   M zzz2_merge_bad
diff --git a/tests/test-merge-revert2.t b/tests/test-merge-revert2.t
--- a/tests/test-merge-revert2.t
+++ b/tests/test-merge-revert2.t
@@ -52,15 +52,16 @@
 
   $ hg diff --nodates
   diff -r dfab7f3c2efb file1
   --- a/file1
   +++ b/file1
-  @@ -1,3 +1,7 @@
+  @@ -1,3 +1,8 @@
    added file1
    another line of text
   +<<<<<<< local: c3fa057dd86f+
   +changed file1 different
+  +======= base: c3fa057dd86f
   +=======
    changed file1
   +>>>>>>> other: dfab7f3c2efb
 
   $ hg status
diff --git a/tests/test-merge-tools.t b/tests/test-merge-tools.t
--- a/tests/test-merge-tools.t
+++ b/tests/test-merge-tools.t
@@ -66,10 +66,12 @@ running from a devel copy, not a temp in
   [1]
   $ aftermerge
   # cat f
   <<<<<<< local: ef83787e2614+
   revision 1
+  ======= base: ffd2bda21d6e
+  revision 0
   =======
   revision 2
   >>>>>>> other: 0185f4e0cf02
   space
   # hg stat
diff --git a/tests/test-merge7.t b/tests/test-merge7.t
--- a/tests/test-merge7.t
+++ b/tests/test-merge7.t
@@ -97,10 +97,12 @@ pull and merge from test-a again
 
   $ cat test.txt
   one
   <<<<<<< local: 50c3a7e29886+
   two-point-five
+  ======= base: 96b70246a118
+  two
   =======
   two-point-one
   >>>>>>> other: 40d11a4173a8
   three
 
diff --git a/tests/test-subrepo.t b/tests/test-subrepo.t
--- a/tests/test-subrepo.t
+++ b/tests/test-subrepo.t
@@ -258,10 +258,12 @@ merge tests
 should conflict
 
   $ cat t/t
   <<<<<<< local: 20a0db6fbf6c+
   conflict
+  ======= base: 6747d179aa9a
+  t2
   =======
   t3
   >>>>>>> other: 7af322bc1198
 
 clone


More information about the Mercurial-devel mailing list