changeset 46140:3ca5ca380a34

filemerge: add support for the new "mergediff" marker style to premerge This adds support for the new "mergediff" conflict marker style to "merge-tools.<tool>.premerge" (the new value is called "keep-mergediff"). Differential Revision: https://phab.mercurial-scm.org/D9606
author Martin von Zweigbergk <martinvonz@google.com>
date Mon, 14 Dec 2020 18:09:37 -0800
parents 34f2c634c8f6
children ec14c37958ec
files mercurial/filemerge.py mercurial/helptext/config.txt relnotes/next tests/test-merge-tools.t
diffstat 4 files changed, 58 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/filemerge.py	Mon Dec 14 14:31:15 2020 +0100
+++ b/mercurial/filemerge.py	Mon Dec 14 18:09:37 2020 -0800
@@ -408,7 +408,7 @@
 
     ui = repo.ui
 
-    validkeep = [b'keep', b'keep-merge3']
+    validkeep = [b'keep', b'keep-merge3', b'keep-mergediff']
 
     # do we attempt to simplemerge first?
     try:
@@ -423,12 +423,17 @@
             )
 
     if premerge:
-        if premerge == b'keep-merge3':
+        mode = b'merge'
+        if premerge in {b'keep-merge3', b'keep-mergediff'}:
             if not labels:
                 labels = _defaultconflictlabels
             if len(labels) < 3:
                 labels.append(b'base')
-        r = simplemerge.simplemerge(ui, fcd, fca, fco, quiet=True, label=labels)
+            if premerge == b'keep-mergediff':
+                mode = b'mergediff'
+        r = simplemerge.simplemerge(
+            ui, fcd, fca, fco, quiet=True, label=labels, mode=mode
+        )
         if not r:
             ui.debug(b" premerge successful\n")
             return 0
--- a/mercurial/helptext/config.txt	Mon Dec 14 14:31:15 2020 +0100
+++ b/mercurial/helptext/config.txt	Mon Dec 14 18:09:37 2020 -0800
@@ -1521,12 +1521,13 @@
 
 ``premerge``
   Attempt to run internal non-interactive 3-way merge tool before
-  launching external tool.  Options are ``true``, ``false``, ``keep`` or
-  ``keep-merge3``. The ``keep`` option will leave markers in the file if the
-  premerge fails. The ``keep-merge3`` will do the same but include information
-  about the base of the merge in the marker (see internal :merge3 in
-  :hg:`help merge-tools`).
-  (default: True)
+  launching external tool.  Options are ``true``, ``false``, ``keep``,
+  ``keep-merge3``, or ``keep-mergediff`` (experimental). The ``keep`` option
+  will leave markers in the file if the premerge fails. The ``keep-merge3``
+  will do the same but include information about the base of the merge in the
+  marker (see internal :merge3 in :hg:`help merge-tools`). The
+  ``keep-mergediff`` option is similar but uses a different marker style
+  (see internal :merge3 in :hg:`help merge-tools`). (default: True)
 
 ``binary``
   This tool can merge binary files. (default: False, unless tool
--- a/relnotes/next	Mon Dec 14 14:31:15 2020 +0100
+++ b/relnotes/next	Mon Dec 14 18:09:37 2020 -0800
@@ -33,7 +33,9 @@
    `internal:merge3`, but it shows conflicts differently. Instead of
    showing 2 or 3 snapshots of the conflicting pieces of code, it
    shows one snapshot and a diff. This may be useful when at least one
-   side of the conflict is similar to the base.
+   side of the conflict is similar to the base. The new marker style
+   is also supported by "premerge" as
+   `merge-tools.<tool>.premerge=keep-mergediff`.
 
 == New Experimental Features ==
 
--- a/tests/test-merge-tools.t	Mon Dec 14 14:31:15 2020 +0100
+++ b/tests/test-merge-tools.t	Mon Dec 14 18:09:37 2020 -0800
@@ -1255,6 +1255,46 @@
   # hg resolve --list
   R f
 
+premerge=keep-mergediff keeps conflict markers with base content:
+
+  $ beforemerge
+  [merge-tools]
+  false.whatever=
+  true.priority=1
+  true.executable=cat
+  # hg update -C 1
+  $ hg merge -r 4 --config merge-tools.true.premerge=keep-mergediff
+  merging f
+  <<<<<<<
+  ------- base
+  +++++++ working copy: ef83787e2614 - test: revision 1
+  -revision 0
+  +revision 1
+   space
+  ======= merge rev:    81448d39c9a0 - test: revision 4
+  revision 4
+  >>>>>>>
+  revision 0
+  space
+  revision 4
+  0 files updated, 1 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ aftermerge
+  # cat f
+  <<<<<<<
+  ------- base
+  +++++++ working copy: ef83787e2614 - test: revision 1
+  -revision 0
+  +revision 1
+   space
+  ======= merge rev:    81448d39c9a0 - test: revision 4
+  revision 4
+  >>>>>>>
+  # hg stat
+  M f
+  # hg resolve --list
+  R f
+
 premerge=keep respects ui.mergemarkers=basic:
 
   $ beforemerge