[PATCH] merge: improve conflict markers by pointing to introrev

Simon Farnsworth simonfar at fb.com
Fri Mar 4 16:31:40 UTC 2016


# HG changeset patch
# User Simon Farnsworth <simonfar at fb.com>
# Date 1457034054 0
#      Thu Mar 03 19:40:54 2016 +0000
# Node ID f9c8bf605e5b96530f6a4636c78f9c444767c445
# Parent  9d6c19c8413a039aff8399d6b1db573cb6610fab
merge: improve conflict markers by pointing to introrev

If you're working in a fast moving repository, the nodes chosen for conflict
markers are apparently nonsensical - they're the revisions you're actually
merging, even if the file in conflict did not change in those revisions.

Change the conflict markers to find the introrev for local and other, and
use that as the node instead. This means that the conflict markers now point
to the commits in which the conflicting file was last changed.

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -515,13 +515,13 @@
 
 _defaultconflictlabels = ['local', 'other']
 
-def _formatlabels(repo, fcd, fco, fca, labels):
+def _formatlabels(repo, fcl, fco, fca, labels):
     """Formats the given labels using the conflict marker template.
 
     Returns a list of formatted labels.
     """
-    cd = fcd.changectx()
-    co = fco.changectx()
+    cl = fcl.repo()[fcl.introrev()]
+    co = fco.repo()[fco.introrev()]
     ca = fca.changectx()
 
     ui = repo.ui
@@ -530,7 +530,7 @@
 
     pad = max(len(l) for l in labels)
 
-    newlabels = [_formatconflictmarker(repo, cd, tmpl, labels[0], pad),
+    newlabels = [_formatconflictmarker(repo, cl, tmpl, labels[0], pad),
                  _formatconflictmarker(repo, co, tmpl, labels[1], pad)]
     if len(labels) > 2:
         newlabels.append(_formatconflictmarker(repo, ca, tmpl, labels[2], pad))
@@ -563,6 +563,7 @@
 
     ui = repo.ui
     fd = fcd.path()
+    fcl = fcd.changectx().filectx(orig)
     binary = fcd.isbinary() or fco.isbinary() or fca.isbinary()
     symlink = 'l' in fcd.flags() + fco.flags()
     changedelete = fcd.isabsent() or fco.isabsent()
@@ -621,7 +622,7 @@
         if not labels:
             labels = _defaultconflictlabels
         if markerstyle != 'basic':
-            labels = _formatlabels(repo, fcd, fco, fca, labels)
+            labels = _formatlabels(repo, fcl, fco, fca, labels)
 
         if premerge and mergetype == fullmerge:
             r = _premerge(repo, fcd, fco, fca, toolconf, files, labels=labels)
diff --git a/tests/test-keyword.t b/tests/test-keyword.t
--- a/tests/test-keyword.t
+++ b/tests/test-keyword.t
@@ -1080,7 +1080,7 @@
   bar
   =======
   foo
-  >>>>>>> other: 85d2d2d732a5  - test: simplemerge
+  >>>>>>> other: 7e422f1c943c  - test: 5foo
 
 resolve to local, m must contain hash of last change (local parent)
 


More information about the Mercurial-devel mailing list