[PATCH 9 of 9 cah] context: introduce [ui]topancestors for controlling which ancestor to pick

Mads Kiilerich mads at kiilerich.com
Thu Apr 17 13:08:01 CDT 2014


# HG changeset patch
# User Mads Kiilerich <madski at unity3d.com>
# Date 1393278134 -3600
#      Mon Feb 24 22:42:14 2014 +0100
# Node ID 99a34ba33e8ea1dd81c648cb6558b47809d7923b
# Parent  ba5e0b1e2289a34a35522d94d7e7b96ba244120d
context: introduce [ui]topancestors for controlling which ancestor to pick

Multiple revisions can be specified in ui.topancestors, separated by whitespace.
First match wins.

This makes it possible to overrule the default of picking the common ancestor
with the lowest hash value (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'.

This feature is currently an undocumented power tool.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -396,7 +396,7 @@ class changectx(basectx):
 
     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,6 +408,13 @@ class changectx(basectx):
         elif len(ancs) == 1:
             anc = ancs[0]
         else:
+            for r in self._repo.ui.config('ui', 'bestancestors', '').split():
+                ctx = changectx(self._repo, r)
+                if ctx.node() in ancs:
+                    self._repo.ui.status(
+                        _('note: %s is best ancestor of %s and %s\n') %
+                        (short(ctx.node()), short(self._node), short(n2)))
+                    return ctx
             anc = self._repo.changelog.ancestor(self._node, n2)
             self._repo.ui.status(
                 _("note: %s is best ancestor of %s and %s, not %s\n") %
diff --git a/tests/test-merge-criss-cross.t b/tests/test-merge-criss-cross.t
--- a/tests/test-merge-criss-cross.t
+++ b/tests/test-merge-criss-cross.t
@@ -111,4 +111,13 @@ Criss cross merging
   ==> f2.other <==
   2 first change
 
+  $ hg up -qC .
+  $ hg merge -v --tool internal:dump 5 --config ui.bestancestors="null 40663881 3b08d"
+  note: 40663881a6dd is best ancestor of 3b08d01b0ab5 and adfe50279922
+  resolving manifests
+  merging f1
+  0 files updated, 0 files merged, 0 files removed, 1 files unresolved
+  use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon
+  [1]
+
   $ cd ..


More information about the Mercurial-devel mailing list