diff mercurial/context.py @ 21126:99b5eaf372a7

context: introduce merge.preferancestor for controlling which ancestor to pick Multiple revisions can be specified in merge.preferancestor, separated by whitespace. First match wins. This makes it possible to overrule the default of picking the common ancestor with the lowest hash value among the "best" (introduced in 3605d4e7e618). This can for instance help with some merges where the 'wrong' ancestor is used. There will thus be some overlap between this and the problems that can be solved with a future 'consensus merge'. Mercurial will show a note like note: using 40663881a6dd as ancestor of 3b08d01b0ab5 and adfe50279922 alternatively, use --config merge.preferancestor=0f6b37dbe527 when the option is available, listing all the alternative ancestors.
author Mads Kiilerich <madski@unity3d.com>
date Mon, 24 Feb 2014 22:42:14 +0100
parents e94e90a4526e
children 9f12d8665c7b
line wrap: on
line diff
--- a/mercurial/context.py	Thu Apr 17 17:32:04 2014 +0200
+++ b/mercurial/context.py	Mon Feb 24 22:42:14 2014 +0100
@@ -396,7 +396,7 @@
 
     def ancestor(self, c2):
         """
-        return the ancestor context of self and c2
+        return the "best" ancestor context of self and c2
         """
         # deal with workingctxs
         n2 = c2._node
@@ -408,10 +408,19 @@
         elif len(cahs) == 1:
             anc = cahs[0]
         else:
-            anc = self._repo.changelog.ancestor(self._node, n2)
+            for r in self._repo.ui.configlist('merge', 'preferancestor'):
+                ctx = changectx(self._repo, r)
+                anc = ctx.node()
+                if anc in cahs:
+                    break
+            else:
+                anc = self._repo.changelog.ancestor(self._node, n2)
             self._repo.ui.status(
                 (_("note: using %s as ancestor of %s and %s\n") %
-                 (short(anc), short(self._node), short(n2))))
+                 (short(anc), short(self._node), short(n2))) +
+                ''.join(_("      alternatively, use --config "
+                          "merge.preferancestor=%s\n") %
+                        short(n) for n in sorted(cahs) if n != anc))
         return changectx(self._repo, anc)
 
     def descendant(self, other):