changeset 17672:474047947b8f

clfilter: make the revlog class responsible of all its iteration This prepares changelog level filtering. We need the algorithms used in revlog to work on a subset of revisions. To achieve this, the use of explicit range of revision is banned. `range` and `xrange` calls are replaced by a `revlog.irevs` method. Filtered super class can then overwrite the `irevs` method to filter out revision.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Thu, 20 Sep 2012 19:00:59 +0200
parents fdd0fc046cf1
children d686c6876ef6
files mercurial/revlog.py
diffstat 1 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Mon Sep 03 14:05:19 2012 +0200
+++ b/mercurial/revlog.py	Thu Sep 20 19:00:59 2012 +0200
@@ -256,6 +256,13 @@
     def __iter__(self):
         for i in xrange(len(self)):
             yield i
+    def revs(self, start=0, stop=None):
+        """iterate over all rev in this revlog (from start to stop)"""
+        if stop is None:
+            stop = len(self)
+        else:
+            stop += 1
+        return xrange(start, stop)
 
     @util.propertycache
     def nodemap(self):
@@ -374,7 +381,7 @@
             return
 
         seen = set(revs)
-        for i in xrange(first + 1, len(self)):
+        for i in self.revs(start=first + 1):
             for x in self.parentrevs(i):
                 if x != nullrev and x in seen:
                     seen.add(i)
@@ -549,7 +556,7 @@
         # Don't start at nullid since we don't want nullid in our output list,
         # and if nullid shows up in descendants, empty parents will look like
         # they're descendants.
-        for r in xrange(max(lowestrev, 0), highestrev + 1):
+        for r in self.revs(start=max(lowestrev, 0), stop=highestrev + 1):
             n = self.node(r)
             isdescendant = False
             if lowestrev == nullrev:  # Everybody is a descendant of nullid
@@ -606,7 +613,7 @@
             return [nullrev]
         ishead = [1] * (count + 1)
         index = self.index
-        for r in xrange(count):
+        for r in self:
             e = index[r]
             ishead[e[5]] = ishead[e[6]] = 0
         return [r for r in xrange(count) if ishead[r]]
@@ -634,7 +641,7 @@
         heads = set((startrev,))
 
         parentrevs = self.parentrevs
-        for r in xrange(startrev + 1, len(self)):
+        for r in self.revs(start=startrev + 1):
             for p in parentrevs(r):
                 if p in reachable:
                     if r not in stoprevs:
@@ -649,7 +656,7 @@
         """find the children of a given node"""
         c = []
         p = self.rev(node)
-        for r in range(p + 1, len(self)):
+        for r in self.revs(start=p + 1):
             prevs = [pr for pr in self.parentrevs(r) if pr != nullrev]
             if prevs:
                 for pr in prevs: