changeset 23328:3a7d9c0c57a5

ancestor.lazyancestors: take parentrevs function rather than changelog Principle of least privilege, and it also brings this in line with missingancestors.
author Siddharth Agarwal <sid0@fb.com>
date Fri, 14 Nov 2014 14:36:25 -0800
parents bd296bb4b5c8
children c6cd4b8b76f8
files mercurial/ancestor.py mercurial/revlog.py tests/test-ancestor.py
diffstat 3 files changed, 4 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/ancestor.py	Sun Nov 16 00:24:23 2014 -0500
+++ b/mercurial/ancestor.py	Fri Nov 14 14:36:25 2014 -0800
@@ -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
--- a/mercurial/revlog.py	Sun Nov 16 00:24:23 2014 -0500
+++ b/mercurial/revlog.py	Fri Nov 14 14:36:25 2014 -0800
@@ -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):
--- a/tests/test-ancestor.py	Sun Nov 16 00:24:23 2014 -0500
+++ b/tests/test-ancestor.py	Fri Nov 14 14:36:25 2014 -0800
@@ -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):