Patchwork [1,of,3,cah,v2,+,bid] context: tell when .ancestor picks one of multiple common ancestors heads

login
register
mail settings
Submitter Mads Kiilerich
Date April 17, 2014, 8:26 p.m.
Message ID <5c14974073cf5b30d68c.1397766380@localhost.localdomain>
Download mbox | patch
Permalink /patch/4407/
State Accepted
Commit e94e90a4526e2e78d1434a6db6b264edc2a3b588
Headers show

Comments

Mads Kiilerich - April 17, 2014, 8:26 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1397748724 -7200
#      Thu Apr 17 17:32:04 2014 +0200
# Node ID 5c14974073cf5b30d68c114c2a93942acf62bbf7
# Parent  49e13e76ec5a34fa6aab2c86b15c77ed0c6b394a
context: tell when .ancestor picks one of multiple common ancestors heads

Show a message like
  note: using 0f6b37dbe527 as ancestor of adfe50279922 and cf89f02107e5

So far this is just a warning - there is nothing the user can do to select
another ancestor.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -402,8 +402,17 @@  class changectx(basectx):
         n2 = c2._node
         if n2 is None:
             n2 = c2._parents[0]._node
-        n = self._repo.changelog.ancestor(self._node, n2)
-        return changectx(self._repo, n)
+        cahs = self._repo.changelog.commonancestorsheads(self._node, n2)
+        if not cahs:
+            anc = nullid
+        elif len(cahs) == 1:
+            anc = cahs[0]
+        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))))
+        return changectx(self._repo, anc)
 
     def descendant(self, other):
         """True if other is descendant of this changeset"""
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
@@ -23,7 +23,9 @@  Criss cross merging
   $ echo '5 second change' > f1
   $ hg ci -m '5 second change f1'
 
-  $ hg up -qr3
+  $ hg up -r3
+  note: using 0f6b37dbe527 as ancestor of adfe50279922 and cf89f02107e5
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ echo '6 second change' > f2
   $ hg ci -m '6 second change f2'
 
@@ -72,6 +74,7 @@  Criss cross merging
   
 
   $ hg merge -v --debug --tool internal:dump 5
+  note: using 0f6b37dbe527 as ancestor of 3b08d01b0ab5 and adfe50279922
     searching for copies back to rev 3
   resolving manifests
    branchmerge: True, force: False, partial: False