Patchwork [4,of,4,V2] merge-tools: add a `premerge=merge3` config option

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 6, 2014, 12:07 a.m.
Message ID <70d7ff6c4ad21382d634.1407283624@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5277/
State Accepted
Headers show

Comments

Pierre-Yves David - Aug. 6, 2014, 12:07 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1407195161 25200
#      Mon Aug 04 16:32:41 2014 -0700
# Node ID 70d7ff6c4ad21382d6341c6740787cfd96f2521e
# Parent  ec36b2fda1e546f1f94af26b3d501ea85c2613a7
merge-tools: add a `premerge=merge3` config option

This value leaves premerge markers that includes the merge base too. This is a
the same as what `internal:merge3` would do.
Matt Mackall - Aug. 6, 2014, 12:26 a.m.
On Tue, 2014-08-05 at 17:07 -0700, pierre-yves.david@ens-lyon.org wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1407195161 25200
> #      Mon Aug 04 16:32:41 2014 -0700
> # Node ID 70d7ff6c4ad21382d6341c6740787cfd96f2521e
> # Parent  ec36b2fda1e546f1f94af26b3d501ea85c2613a7
> merge-tools: add a `premerge=merge3` config option

These are queued for default, thanks.

Patch

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -176,11 +176,11 @@  def _premerge(repo, toolconf, files, lab
         return 1
     a, b, c, back = files
 
     ui = repo.ui
 
-    validkeep = ['keep']
+    validkeep = ['keep', 'keep-merge3']
 
     # do we attempt to simplemerge first?
     try:
         premerge = _toolbool(ui, tool, "premerge", not binary)
     except error.ConfigError:
@@ -190,10 +190,15 @@  def _premerge(repo, toolconf, files, lab
             raise error.ConfigError(_("%s.premerge not valid "
                                       "('%s' is neither boolean nor %s)") %
                                     (tool, premerge, _valid))
 
     if premerge:
+        if premerge == 'keep-merge3':
+            if not labels:
+                labels = _defaultconflictlabels
+            if len(labels) < 3:
+                labels.append('base')
         r = simplemerge.simplemerge(ui, a, b, c, quiet=True, label=labels)
         if not r:
             ui.debug(" premerge successful\n")
             return 0
         if premerge not in validkeep:
diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -952,12 +952,14 @@  Supported arguments:
   commit being rebased.
   Default: ``$local $base $other``
 
 ``premerge``
   Attempt to run internal non-interactive 3-way merge tool before
-  launching external tool.  Options are ``true``, ``false``, or ``keep``
-  to leave markers in the file if the premerge fails.
+  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 incluses information
+  about the base of the merge in the marker (see internal:merge3)
   Default: True
 
 ``binary``
   This tool can merge binary files. Defaults to False, unless tool
   was selected by file pattern match.
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
@@ -739,10 +739,48 @@  Default is silent simplemerge:
   revision 4
   >>>>>>> other: 81448d39c9a0 - test: revision 4
   # hg stat
   M f
 
+.premerge=keep-merge3 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-merge3
+  merging f
+  <<<<<<< local: ef83787e2614  - test: revision 1
+  revision 1
+  space
+  ||||||| base
+  revision 0
+  space
+  =======
+  revision 4
+  >>>>>>> other: 81448d39c9a0 - test: 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
+  <<<<<<< local: ef83787e2614  - test: revision 1
+  revision 1
+  space
+  ||||||| base
+  revision 0
+  space
+  =======
+  revision 4
+  >>>>>>> other: 81448d39c9a0 - test: revision 4
+  # hg stat
+  M f
+
 
 Tool execution
 
 set tools.args explicit to include $base $local $other $output: