Mercurial > hg
diff mercurial/utils/storageutil.py @ 39881:d63153611ed5
storageutil: extract revision number iteration
This code is a bit quirky (and possibly buggy). It will likely be used
by multiple storage backends. Let's extract it so it is reusable.
Differential Revision: https://phab.mercurial-scm.org/D4757
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 24 Sep 2018 15:19:52 -0700 |
parents | 1b65fb4d43d6 |
children | 0e8836be9541 |
line wrap: on
line diff
--- a/mercurial/utils/storageutil.py Mon Sep 24 14:54:28 2018 -0700 +++ b/mercurial/utils/storageutil.py Mon Sep 24 15:19:52 2018 -0700 @@ -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)