[PATCH 3 of 3 V3] filemerge: add 'union' merge to internal merge tool

ehuels at gmail.com ehuels at gmail.com
Sun Aug 16 08:56:22 UTC 2015


# HG changeset patch
# User Erik Huelsmann <ehuels at gmail.com>
# Date 1439713140 -7200
#      Sun Aug 16 10:19:00 2015 +0200
# Node ID 0891b795ef6071786eb86a583bfa9c6efa4371e2
# Parent  ef852de2d5f76e1cf6d9ca00b340d4302f6edb3c
filemerge: add 'union' merge to internal merge tool

'union merge' is a merge strategy which adds both left and right hand side
of a conflict region. Git implements this merge strategy which is very
practical to have for merging e.g. the Changelog file.

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -248,6 +248,17 @@
         return True, r
     return False, 0
 
+ at internaltool('union', True,
+              _("merging %s incomplete! "
+                "(edit conflicts, then use 'hg resolve --mark')\n"))
+def _imerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None):
+    """
+    Uses the internal non-interactive simple merge algorithm for merging
+    files. It will use both left and right sides for conflict regions.
+    No markers are inserted."""
+    return __imerge(repo, mynode, orig, fcd, fco, fca, toolconf,
+                    files, labels, 'union')
+
 @internaltool('merge', True,
               _("merging %s incomplete! "
                 "(edit conflicts, then use 'hg resolve --mark')\n"))
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -1202,6 +1202,11 @@
       ":tagmerge"
         Uses the internal tag merge algorithm (experimental).
   
+      ":union"
+        Uses the internal non-interactive simple merge algorithm for merging
+        files. It will use both left and right sides for conflict regions. No
+        markers are inserted.
+  
       Internal tools are always available and do not require a GUI but will by
       default not handle symlinks or binary files.
   
diff --git a/tests/test-merge-internal-tools-pattern.t b/tests/test-merge-internal-tools-pattern.t
--- a/tests/test-merge-internal-tools-pattern.t
+++ b/tests/test-merge-internal-tools-pattern.t
@@ -1,5 +1,6 @@
-Make sure that the internal merge tools (internal:fail, internal:local, and
-internal:other) are used when matched by a merge-pattern in hgrc
+Make sure that the internal merge tools (internal:fail, internal:local,
+internal:union and internal:other) are used when matched by a
+merge-pattern in hgrc
 
 Make sure HGMERGE doesn't interfere with the test:
 
@@ -110,3 +111,31 @@
   $ hg stat
   M f
 
+Merge using internal:union tool:
+
+  $ hg update -C 2
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ echo "line 4a" >>f
+  $ hg ci -Am "Adding fourth line (commit 4)"
+  $ hg update 2
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ echo "line 4b" >>f
+  $ hg ci -Am "Adding fourth line v2 (commit 5)"
+  created new head
+
+  $ echo "[merge-patterns]" > .hg/hgrc
+  $ echo "* = internal:union" >> .hg/hgrc
+
+  $ hg merge 3
+  merging f
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+
+  $ cat f
+  line 1
+  line 2
+  third line
+  line 4b
+  line 4a


More information about the Mercurial-devel mailing list