revlog: allow reverse iteration with revlog.revs
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Wed, 21 Nov 2012 00:42:05 +0100
changeset 17975 c56b5b65430d
parent 17974 337d728e644f
child 17976 09d5681d5b72
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.
mercurial/revlog.py
--- 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):