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

login
register
mail settings
Submitter Mads Kiilerich
Date April 17, 2014, 6:08 p.m.
Message ID <99a34ba33e8ea1dd81c6.1397758081@localhost.localdomain>
Download mbox | patch
Permalink /patch/4403/
State Deferred
Headers show

Comments

Mads Kiilerich - April 17, 2014, 6:08 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@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.
Martin Geisler - April 18, 2014, 12:38 p.m.
Mads Kiilerich <mads@kiilerich.com> writes:

> # HG changeset patch
> # User Mads Kiilerich <madski@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.

You call it ui.bestancestors in the code.

> +            for r in self._repo.ui.config('ui', 'bestancestors', '').split():
> +                ctx = changectx(self._repo, r)
Mads Kiilerich - April 18, 2014, 4:34 p.m.
On 04/18/2014 02:38 PM, Martin Geisler wrote:
> Mads Kiilerich <mads@kiilerich.com> writes:
>
>> # HG changeset patch
>> # User Mads Kiilerich <madski@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.
> You call it ui.bestancestors in the code.

Yes, it was a frantic attempt at getting in before the deadline.

But it made it, as merge.preferancestor - 
http://selenic.com/repo/hg/rev/99b5eaf372a7 .

/Mads

Patch

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 ..