From 6981326b92d73e07de4de93c1db69b5f8628cf42 Mon Sep 17 00:00:00 2001 From: Pierre-Yves David Date: Thu, 20 Sep 2012 19:00:59 +0200 Subject: [PATCH] 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. --- mercurial/revlog.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/mercurial/revlog.py b/mercurial/revlog.py index 4cfbfbce45..d2e97c427f 100644 --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -256,6 +256,13 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): # 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 @@ class revlog(object): 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 @@ class revlog(object): 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 @@ class revlog(object): """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: