Patchwork [01,of,16] ancestor.lazyancestors: take parentrevs function rather than changelog

login
register
mail settings
Submitter Siddharth Agarwal
Date Nov. 16, 2014, 9:17 a.m.
Message ID <020cd14053562f3e0b9c.1416129423@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/6749/
State Accepted
Commit 3a7d9c0c57a59c5b43eeef3df7b578ab715ae2c0
Headers show

Comments

Siddharth Agarwal - Nov. 16, 2014, 9:17 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1416004585 28800
#      Fri Nov 14 14:36:25 2014 -0800
# Node ID 020cd14053562f3e0b9ce91e63585f658ad8d9c9
# Parent  d733796b4362918f2eb10e5d6323becb02054bcc
ancestor.lazyancestors: take parentrevs function rather than changelog

Principle of least privilege, and it also brings this in line with
missingancestors.

Patch

diff --git a/mercurial/ancestor.py b/mercurial/ancestor.py
--- a/mercurial/ancestor.py
+++ b/mercurial/ancestor.py
@@ -216,7 +216,7 @@ 
     return missing
 
 class lazyancestors(object):
-    def __init__(self, cl, revs, stoprev=0, inclusive=False):
+    def __init__(self, pfunc, revs, stoprev=0, inclusive=False):
         """Create a new object generating ancestors for the given revs. Does
         not generate revs lower than stoprev.
 
@@ -228,7 +228,7 @@ 
         than stoprev will not be generated.
 
         Result does not include the null revision."""
-        self._parentrevs = cl.parentrevs
+        self._parentrevs = pfunc
         self._initrevs = revs
         self._stoprev = stoprev
         self._inclusive = inclusive
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -407,7 +407,7 @@ 
 
         See the documentation for ancestor.lazyancestors for more details."""
 
-        return ancestor.lazyancestors(self, revs, stoprev=stoprev,
+        return ancestor.lazyancestors(self.parentrevs, revs, stoprev=stoprev,
                                       inclusive=inclusive)
 
     def descendants(self, revs):
diff --git a/tests/test-ancestor.py b/tests/test-ancestor.py
--- a/tests/test-ancestor.py
+++ b/tests/test-ancestor.py
@@ -34,9 +34,6 @@ 
          13: [8]}
 pfunc = graph.get
 
-class mockchangelog(object):
-    parentrevs = graph.get
-
 def runmissingancestors(revs, bases):
     print "%% ancestors of %s and not of %s" % (revs, bases)
     print ancestor.missingancestors(revs, bases, pfunc)
@@ -76,7 +73,7 @@ 
 def genlazyancestors(revs, stoprev=0, inclusive=False):
     print ("%% lazy ancestor set for %s, stoprev = %s, inclusive = %s" %
            (revs, stoprev, inclusive))
-    return ancestor.lazyancestors(mockchangelog, revs, stoprev=stoprev,
+    return ancestor.lazyancestors(graph.get, revs, stoprev=stoprev,
                                   inclusive=inclusive)
 
 def printlazyancestors(s, l):