D4757: storageutil: extract revision number iteration
indygreg (Gregory Szorc)
phabricator at mercurial-scm.org
Wed Sep 26 17:13:25 EDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG6037974f8aba: storageutil: extract revision number iteration (authored by indygreg, committed by ).
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D4757?vs=11412&id=11433
REVISION DETAIL
https://phab.mercurial-scm.org/D4757
AFFECTED FILES
mercurial/revlog.py
mercurial/utils/storageutil.py
CHANGE DETAILS
diff --git a/mercurial/utils/storageutil.py b/mercurial/utils/storageutil.py
--- a/mercurial/utils/storageutil.py
+++ b/mercurial/utils/storageutil.py
@@ -13,6 +13,9 @@
from ..node import (
nullid,
)
+from .. import (
+ pycompat,
+)
_nullhash = hashlib.sha1(nullid)
@@ -81,3 +84,18 @@
offset = text.index(b'\x01\n', 2)
return text[offset + 2:]
+
+def iterrevs(storelen, start=0, stop=None):
+ """Iterate over revision numbers in a store."""
+ step = 1
+
+ if stop is not None:
+ if start > stop:
+ step = -1
+ stop += step
+ if stop > storelen:
+ stop = storelen
+ else:
+ stop = storelen
+
+ return pycompat.xrange(start, stop, step)
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -515,17 +515,7 @@
return iter(pycompat.xrange(len(self)))
def revs(self, start=0, stop=None):
"""iterate over all rev in this revlog (from start to stop)"""
- step = 1
- length = len(self)
- if stop is not None:
- if start > stop:
- step = -1
- stop += step
- if stop > length:
- stop = length
- else:
- stop = length
- return pycompat.xrange(start, stop, step)
+ return storageutil.iterrevs(len(self), start=start, stop=stop)
@util.propertycache
def nodemap(self):
To: indygreg, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list