From patchwork Mon Feb 24 22:19:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [5, of, 7] context: warn when .ancestor picks an arbitrary of multiple common ancestors From: Mads Kiilerich X-Patchwork-Id: 3748 Message-Id: To: mercurial-devel@selenic.com Date: Mon, 24 Feb 2014 23:19:14 +0100 # HG changeset patch # User Mads Kiilerich # 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 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"""