Patchwork [5,of,7] context: warn when .ancestor picks an arbitrary of multiple common ancestors

login
register
mail settings
Submitter Mads Kiilerich
Date Feb. 24, 2014, 10:19 p.m.
Message ID <d6e2126534dce3cc4dea.1393280354@mk-desktop>
Download mbox | patch
Permalink /patch/3748/
State Deferred
Headers show

Comments

Mads Kiilerich - Feb. 24, 2014, 10:19 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1393278134 -3600
#      Mon Feb 24 22:42:14 2014 +0100
# Node ID d6e2126534dce3cc4dea26c5e869f72a44353a47
# Parent  2d32ff9a384a604e70b0caeb5da345b5d69b8d50
context: warn when .ancestor picks an arbitrary of multiple common ancestors

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -396,14 +396,21 @@ 
 
     def ancestor(self, c2):
         """
-        return the ancestor context of self and c2
+        return an ancestor context of self and c2
         """
         # deal with workingctxs
         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)
+        ancs = set(self._repo.changelog.commonancestors(self._node, n2))
+        if not ancs:
+            return changectx(self._repo, nullid)
+        if len(ancs) > 1:
+            self._repo.ui.warn(
+                _("warning: multiple ancestors of %s and %s: %s\n") %
+                (short(self._node), short(n2),
+                 ' '.join(short(n) for n in sorted(ancs))))
+        return changectx(self._repo, min(ancs))
 
     def descendant(self, other):
         """True if other is descendant of this changeset"""