filemerge: add union-other-first as internal merge tool
See inline documentation for details.
--- a/mercurial/filemerge.py Fri Jan 13 00:07:07 2023 +0100
+++ b/mercurial/filemerge.py Thu Jan 26 00:23:07 2023 +0100
@@ -478,8 +478,9 @@
"""
Uses the internal non-interactive simple merge algorithm for merging
files. It will fail if there are any conflicts and leave markers in
- the partially merged file. Markers will have two sections, one for each side
- of merge, unless mode equals 'union' which suppresses the markers."""
+ the partially merged file. Markers will have two sections, one for each
+ side of merge, unless mode equals 'union' or 'union-other-first' which
+ suppresses the markers."""
ui = repo.ui
try:
@@ -510,12 +511,28 @@
def _iunion(repo, mynode, local, other, base, toolconf, backup):
"""
Uses the internal non-interactive simple merge algorithm for merging
- files. It will use both left and right sides for conflict regions.
+ files. It will use both local and other sides for conflict regions by
+ adding local on top of other.
No markers are inserted."""
return _merge(repo, local, other, base, b'union')
@internaltool(
+ b'union-other-first',
+ fullmerge,
+ _(
+ b"warning: conflicts while merging %s! "
+ b"(edit, then use 'hg resolve --mark')\n"
+ ),
+ precheck=_mergecheck,
+)
+def _iunion_other_first(repo, mynode, local, other, base, toolconf, backup):
+ """
+ Like :union, but add other on top of local."""
+ return _merge(repo, local, other, base, b'union-other-first')
+
+
+@internaltool(
b'merge',
fullmerge,
_(
--- a/mercurial/simplemerge.py Fri Jan 13 00:07:07 2023 +0100
+++ b/mercurial/simplemerge.py Thu Jan 26 00:23:07 2023 +0100
@@ -512,6 +512,8 @@
conflicts = False
if mode == b'union':
lines = _resolve(m3, (1, 2))
+ elif mode == b'union-other-first':
+ lines = _resolve(m3, (2, 1))
elif mode == b'local':
lines = _resolve(m3, (1,))
elif mode == b'other':
--- a/relnotes/next Fri Jan 13 00:07:07 2023 +0100
+++ b/relnotes/next Thu Jan 26 00:23:07 2023 +0100
@@ -2,6 +2,9 @@
== New Features ==
+ * There is a new internal merge tool called `internal:union-other-first`.
+ It works like `internal:union` but add other side on top of local.
+
== Default Format Change ==
These changes affect newly created repositories (or new clones) done with
--- a/tests/test-help.t Fri Jan 13 00:07:07 2023 +0100
+++ b/tests/test-help.t Thu Jan 26 00:23:07 2023 +0100
@@ -2172,8 +2172,11 @@
":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.
+ files. It will use both local and other sides for conflict regions by
+ adding local on top of other. No markers are inserted.
+
+ ":union-other-first"
+ Like :union, but add other on top of local.
Internal tools are always available and do not require a GUI but will by
default not handle symlinks or binary files. See next section for detail
--- a/tests/test-merge-internal-tools-pattern.t Fri Jan 13 00:07:07 2023 +0100
+++ b/tests/test-merge-internal-tools-pattern.t Thu Jan 26 00:23:07 2023 +0100
@@ -140,3 +140,23 @@
third line
line 4b
line 4a
+
+Merge using internal:union-other-first tool:
+
+ $ hg update -C 4
+ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+ $ echo "[merge-patterns]" > .hg/hgrc
+ $ echo "* = internal:union-other-first" >> .hg/hgrc
+
+ $ hg merge 3
+ merging f
+ 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
+ (branch merge, don't forget to commit)
+
+ $ cat f
+ line 1
+ line 2
+ third line
+ line 4a
+ line 4b