Patchwork [4,of,4] revlog: introduce isancestor method for efficiently determining node lineage

login
register
mail settings
Submitter Mads Kiilerich
Date Aug. 31, 2014, 3:07 p.m.
Message ID <c7299b3134c110f37aa1.1409497630@localhost.localdomain>
Download mbox | patch
Permalink /patch/5670/
State Accepted
Headers show

Comments

Mads Kiilerich - Aug. 31, 2014, 3:07 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1408403590 -7200
#      Tue Aug 19 01:13:10 2014 +0200
# Node ID c7299b3134c110f37aa1ba5a20ced93711973da7
# Parent  04bb92b2a16df80368e47ea1aafc82e2e81f7d98
revlog: introduce isancestor method for efficiently determining node lineage

Hide the not so obvious use of commonancestorsheads.
Pierre-Yves David - Sept. 2, 2014, 7:10 p.m.
On 08/31/2014 05:07 PM, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski@unity3d.com>
> # Date 1408403590 -7200
> #      Tue Aug 19 01:13:10 2014 +0200
> # Node ID c7299b3134c110f37aa1ba5a20ced93711973da7
> # Parent  04bb92b2a16df80368e47ea1aafc82e2e81f7d98
> revlog: introduce isancestor method for efficiently determining node lineage

Sound sensible to me. pushed to the Clowncopter

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -454,7 +454,7 @@  def backout(ui, repo, node=None, rev=Non
     node = scmutil.revsingle(repo, rev).node()
 
     op1, op2 = repo.dirstate.parents()
-    if node not in repo.changelog.commonancestorsheads(op1, node):
+    if not repo.changelog.isancestor(node, op1):
         raise util.Abort(_('cannot backout change that is not an ancestor'))
 
     p1, p2 = repo.changelog.parents(node)
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -745,6 +745,13 @@  class revlog(object):
             ancs = ancestor.commonancestorsheads(self.parentrevs, a, b)
         return map(self.node, ancs)
 
+    def isancestor(self, a, b):
+        """return True if node a is an ancestor of node b
+
+        The implementation of this is trivial but the use of
+        commonancestorsheads is not."""
+        return a in self.commonancestorsheads(a, b)
+
     def ancestor(self, a, b):
         """calculate the "best" common ancestor of nodes a and b"""