revlog: allow reverse iteration with revlog.revs
We often need to perform rev iteration in reverse order. This
changeset makes it possible to do so, in order to avoid costly reverse
or reversed() calls later.
--- a/mercurial/revlog.py Sun Nov 18 12:26:50 2012 -1000
+++ b/mercurial/revlog.py Wed Nov 21 00:42:05 2012 +0100
@@ -257,11 +257,14 @@
return iter(xrange(len(self)))
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)
+ step = 1
+ if stop is not None:
+ if start > stop:
+ step = -1
+ stop += step
else:
- stop += 1
- return xrange(start, stop)
+ stop = len(self)
+ return xrange(start, stop, step)
@util.propertycache
def nodemap(self):