changeset 17975:c56b5b65430d

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.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Wed, 21 Nov 2012 00:42:05 +0100
parents 337d728e644f
children 09d5681d5b72
files mercurial/revlog.py
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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):