changeset 48584:74973a6d4e67

filemerge: always define a "base" label It simplifies the code and improves the conflict markers to always have the "base" label defined. Differential Revision: https://phab.mercurial-scm.org/D12016
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 20 Jan 2022 14:13:12 -0800
parents a809f1465a76
children 07069fcd9a6e
files mercurial/filemerge.py tests/test-annotate.t tests/test-diff-change.t tests/test-fastannotate-hg.t tests/test-merge-changedelete.t tests/test-merge-force.t tests/test-merge-tools.t tests/test-rebase-collapse.t tests/test-rebase-conflicts.t tests/test-update-branches.t
diffstat 10 files changed, 33 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/filemerge.py	Thu Jan 20 13:43:43 2022 -0800
+++ b/mercurial/filemerge.py	Thu Jan 20 14:13:12 2022 -0800
@@ -421,8 +421,6 @@
             )
 
     if premerge:
-        if len(labels) < 3:
-            labels.append(b'base')
         mode = b'merge'
         if premerge == b'keep-mergediff':
             mode = b'mergediff'
@@ -473,14 +471,11 @@
     ui = repo.ui
 
     local = simplemerge.MergeInput(fcd)
-    if len(labels) > 0:
-        local.label = labels[0]
+    local.label = labels[0]
     other = simplemerge.MergeInput(fco)
-    if len(labels) > 1:
-        other.label = labels[1]
+    other.label = labels[1]
     base = simplemerge.MergeInput(fca)
-    if len(labels) > 2:
-        base.label = labels[2]
+    base.label = labels[2]
     r = simplemerge.simplemerge(ui, local, base, other, mode=mode)
     return True, r, False
 
@@ -535,8 +530,6 @@
     files. It will fail if there are any conflicts and leave markers in
     the partially merged file. Marker will have three sections, one from each
     side of the merge and one for the base content."""
-    if len(labels) < 3:
-        labels.append(b'base')
     return _merge(repo, fcd, fco, fca, labels, b'merge3')
 
 
@@ -575,8 +568,6 @@
     the partially merged file. The marker will have two sections, one with the
     content from one side of the merge, and one with a diff from the base
     content to the content on the other side. (experimental)"""
-    if len(labels) < 3:
-        labels.append(b'base')
     return _merge(repo, fcd, fco, fca, labels, b'mergediff')
 
 
@@ -736,10 +727,7 @@
         basepath, otherpath, localoutputpath = temppaths
         outpath = b""
         mylabel, otherlabel = labels[:2]
-        if len(labels) >= 3:
-            baselabel = labels[2]
-        else:
-            baselabel = b'base'
+        baselabel = labels[2]
         env = {
             b'HG_FILE': fcd.path(),
             b'HG_MY_NODE': short(mynode),
@@ -861,9 +849,8 @@
     newlabels = [
         _formatlabel(cd, tmpl, labels[0], pad),
         _formatlabel(co, tmpl, labels[1], pad),
+        _formatlabel(ca, tmpl, labels[2], pad),
     ]
-    if len(labels) > 2:
-        newlabels.append(_formatlabel(ca, tmpl, labels[2], pad))
     return newlabels
 
 
@@ -1063,6 +1050,8 @@
 
     if not labels:
         labels = [b'local', b'other']
+    if len(labels) < 3:
+        labels.append(b'base')
     if mergetype == nomerge:
         return func(repo, mynode, fcd, fco, fca, toolconf, labels)
 
--- a/tests/test-annotate.t	Thu Jan 20 13:43:43 2022 -0800
+++ b/tests/test-annotate.t	Thu Jan 20 14:13:12 2022 -0800
@@ -225,7 +225,7 @@
   b4
   c
   b5
-  ||||||| base
+  ||||||| base:         3086dbafde1c - test: b
   =======
   b4
   b5
@@ -750,7 +750,7 @@
   <<<<<<< working copy: 863de62655ef - test: baz:3+->3-
   3- baz:3
   4 baz:4
-  ||||||| base
+  ||||||| base:         56fc739c091f - test: baz:3->3+
   3+ baz:3
   4 baz:4
   =======
@@ -797,7 +797,7 @@
   <<<<<<< working copy: cb8df70ae185 - test: qux:4->4+
   3+ baz:3
   4+ baz:4
-  ||||||| base
+  ||||||| base:         56fc739c091f - test: baz:3->3+
   3+ baz:3
   4 baz:4
   =======
@@ -1176,7 +1176,7 @@
   1
   2
   3
-  ||||||| base
+  ||||||| base:         1ed24be7e7a0 - test: 2
   1
   2
   =======
--- a/tests/test-diff-change.t	Thu Jan 20 13:43:43 2022 -0800
+++ b/tests/test-diff-change.t	Thu Jan 20 14:13:12 2022 -0800
@@ -284,7 +284,7 @@
    7
   -<<<<<<< local: fd1f17c90d7c - test: new file
    z
-  -||||||| base
+  -||||||| base:  ae119d680c82 - test: lots of text
   -8
   -=======
   -y
--- a/tests/test-fastannotate-hg.t	Thu Jan 20 13:43:43 2022 -0800
+++ b/tests/test-fastannotate-hg.t	Thu Jan 20 14:13:12 2022 -0800
@@ -169,7 +169,7 @@
   b4
   c
   b5
-  ||||||| base
+  ||||||| base:         3086dbafde1c - test: b
   =======
   b4
   b5
@@ -793,7 +793,7 @@
   1
   2
   3
-  ||||||| base
+  ||||||| base:         1ed24be7e7a0 - test: 2
   1
   2
   =======
--- a/tests/test-merge-changedelete.t	Thu Jan 20 13:43:43 2022 -0800
+++ b/tests/test-merge-changedelete.t	Thu Jan 20 14:13:12 2022 -0800
@@ -682,7 +682,7 @@
   3
   <<<<<<< working copy: 13910f48cf7b - test: changed file1, removed file2, chan...
   changed2
-  ||||||| base
+  ||||||| base:         ab57bf49aa27 - test: added files
   =======
   changed1
   >>>>>>> merge rev:    10f9a0a634e8 - test: removed file1, changed file2, chan...
--- a/tests/test-merge-force.t	Thu Jan 20 13:43:43 2022 -0800
+++ b/tests/test-merge-force.t	Thu Jan 20 14:13:12 2022 -0800
@@ -400,7 +400,7 @@
   M content1_content2_content1_content4-tracked
   <<<<<<< working copy: 0447570f1af6 - test: local
   content4
-  ||||||| base
+  ||||||| base:         8ef80617fa20 - test: base
   content1
   =======
   content2
@@ -430,7 +430,7 @@
   M content1_content2_content2_content4-tracked
   <<<<<<< working copy: 0447570f1af6 - test: local
   content4
-  ||||||| base
+  ||||||| base:         8ef80617fa20 - test: base
   content1
   =======
   content2
@@ -460,7 +460,7 @@
   M content1_content2_content3_content3-tracked
   <<<<<<< working copy: 0447570f1af6 - test: local
   content3
-  ||||||| base
+  ||||||| base:         8ef80617fa20 - test: base
   content1
   =======
   content2
@@ -472,7 +472,7 @@
   M content1_content2_content3_content4-tracked
   <<<<<<< working copy: 0447570f1af6 - test: local
   content4
-  ||||||| base
+  ||||||| base:         8ef80617fa20 - test: base
   content1
   =======
   content2
@@ -502,7 +502,7 @@
   M content1_content2_missing_content4-tracked
   <<<<<<< working copy: 0447570f1af6 - test: local
   content4
-  ||||||| base
+  ||||||| base:         8ef80617fa20 - test: base
   content1
   =======
   content2
@@ -586,7 +586,7 @@
   M missing_content2_content2_content4-tracked
   <<<<<<< working copy: 0447570f1af6 - test: local
   content4
-  ||||||| base
+  ||||||| base:         000000000000 - : 
   =======
   content2
   >>>>>>> merge rev:    85100b8c675b - test: remote
@@ -609,7 +609,7 @@
   M missing_content2_content3_content3-tracked
   <<<<<<< working copy: 0447570f1af6 - test: local
   content3
-  ||||||| base
+  ||||||| base:         000000000000 - : 
   =======
   content2
   >>>>>>> merge rev:    85100b8c675b - test: remote
@@ -620,7 +620,7 @@
   M missing_content2_content3_content4-tracked
   <<<<<<< working copy: 0447570f1af6 - test: local
   content4
-  ||||||| base
+  ||||||| base:         000000000000 - : 
   =======
   content2
   >>>>>>> merge rev:    85100b8c675b - test: remote
@@ -643,7 +643,7 @@
   M missing_content2_missing_content4-tracked
   <<<<<<< working copy: 0447570f1af6 - test: local
   content4
-  ||||||| base
+  ||||||| base:         000000000000 - : 
   =======
   content2
   >>>>>>> merge rev:    85100b8c675b - test: remote
@@ -651,7 +651,7 @@
   M missing_content2_missing_content4-untracked
   <<<<<<< working copy: 0447570f1af6 - test: local
   content4
-  ||||||| base
+  ||||||| base:         000000000000 - : 
   =======
   content2
   >>>>>>> merge rev:    85100b8c675b - test: remote
--- a/tests/test-merge-tools.t	Thu Jan 20 13:43:43 2022 -0800
+++ b/tests/test-merge-tools.t	Thu Jan 20 14:13:12 2022 -0800
@@ -1226,7 +1226,7 @@
   <<<<<<< working copy: ef83787e2614 - test: revision 1
   revision 1
   space
-  ||||||| base
+  ||||||| base:         ffd2bda21d6e - test: revision 0
   revision 0
   space
   =======
@@ -1242,7 +1242,7 @@
   <<<<<<< working copy: ef83787e2614 - test: revision 1
   revision 1
   space
-  ||||||| base
+  ||||||| base:         ffd2bda21d6e - test: revision 0
   revision 0
   space
   =======
@@ -1264,7 +1264,7 @@
   $ hg merge -r 4 --config merge-tools.true.premerge=keep-mergediff
   merging f
   <<<<<<<
-  ------- base
+  ------- base:         ffd2bda21d6e - test: revision 0
   +++++++ working copy: ef83787e2614 - test: revision 1
   -revision 0
   +revision 1
@@ -1280,7 +1280,7 @@
   $ aftermerge
   # cat f
   <<<<<<<
-  ------- base
+  ------- base:         ffd2bda21d6e - test: revision 0
   +++++++ working copy: ef83787e2614 - test: revision 1
   -revision 0
   +revision 1
--- a/tests/test-rebase-collapse.t	Thu Jan 20 13:43:43 2022 -0800
+++ b/tests/test-rebase-collapse.t	Thu Jan 20 14:13:12 2022 -0800
@@ -719,7 +719,7 @@
   $ cat A
   <<<<<<< dest:   82b8abf9c185 D - test: D
   D
-  ||||||| base
+  ||||||| base:   4a2df7238c3b A - test: A
   A
   =======
   B
@@ -747,7 +747,7 @@
   $ cat A
   <<<<<<< dest:   82b8abf9c185 D - test: D
   BC
-  ||||||| base
+  ||||||| base:   f899f3910ce7 B - test: B
   B
   =======
   C
--- a/tests/test-rebase-conflicts.t	Thu Jan 20 13:43:43 2022 -0800
+++ b/tests/test-rebase-conflicts.t	Thu Jan 20 14:13:12 2022 -0800
@@ -374,7 +374,7 @@
    a
   +<<<<<<< dest:   328e4ab1f7cc ab - test: ab
    b
-  +||||||| base
+  +||||||| base:   cb9a9f314b8b - test: a
   +=======
   +b
   +c
--- a/tests/test-update-branches.t	Thu Jan 20 13:43:43 2022 -0800
+++ b/tests/test-update-branches.t	Thu Jan 20 14:13:12 2022 -0800
@@ -295,7 +295,7 @@
   <<<<<<< working copy: 6efa171f091b - test: 3
   three
   dirty
-  ||||||| base
+  ||||||| base:         6efa171f091b - test: 3
   three
   =======
   four