Patchwork [4,of,7] revlog: introduce commonancestors method for getting all common ancestor heads

login
register
mail settings
Submitter Mads Kiilerich
Date Feb. 24, 2014, 10:19 p.m.
Message ID <2d32ff9a384a604e70b0.1393280353@mk-desktop>
Download mbox | patch
Permalink /patch/3746/
State Accepted
Commit 514d32de6646500cd46f521c49dff46860ae70ba
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 2d32ff9a384a604e70b0caeb5da345b5d69b8d50
# Parent  15f7ab614d3c5278809575c7e577b4648b85f832
revlog: introduce commonancestors method for getting all common ancestor heads
Matt Mackall - Feb. 24, 2014, 10:29 p.m.
On Mon, 2014-02-24 at 23:19 +0100, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <madski@unity3d.com>
> # Date 1393278134 -3600
> #      Mon Feb 24 22:42:14 2014 +0100
> # Node ID 2d32ff9a384a604e70b0caeb5da345b5d69b8d50
> # Parent  15f7ab614d3c5278809575c7e577b4648b85f832
> revlog: introduce commonancestors method for getting all common ancestor heads

I've queued up to here, thanks.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -734,17 +734,21 @@ 
                 break
         return False
 
-    def ancestor(self, a, b):
-        """calculate the least common ancestor of nodes a and b"""
-
+    def commonancestors(self, a, b):
+        """calculate the least common ancestors of nodes a and b"""
         a, b = self.rev(a), self.rev(b)
         try:
             ancs = self.index.ancestors(a, b)
-        except (AttributeError, OverflowError):
+        except (AttributeError, OverflowError): # C implementation failed
             ancs = ancestor.ancestors(self.parentrevs, a, b)
+        return map(self.node, ancs)
+
+    def ancestor(self, a, b):
+        """calculate a least common ancestor of nodes a and b"""
+        ancs = self.commonancestors(a, b)
         if ancs:
             # choose a consistent winner when there's a tie
-            return min(map(self.node, ancs))
+            return min(ancs)
         return nullid
 
     def _match(self, id):