Mercurial > public > mercurial-scm > hg
comparison mercurial/revlog.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 | d269ddbf54f0 |
children | debc4ee597e7 |
comparison
equal
deleted
inserted
replaced
39880:1b65fb4d43d6 | 39881:d63153611ed5 |
---|---|
513 return len(self.index) | 513 return len(self.index) |
514 def __iter__(self): | 514 def __iter__(self): |
515 return iter(pycompat.xrange(len(self))) | 515 return iter(pycompat.xrange(len(self))) |
516 def revs(self, start=0, stop=None): | 516 def revs(self, start=0, stop=None): |
517 """iterate over all rev in this revlog (from start to stop)""" | 517 """iterate over all rev in this revlog (from start to stop)""" |
518 step = 1 | 518 return storageutil.iterrevs(len(self), start=start, stop=stop) |
519 length = len(self) | |
520 if stop is not None: | |
521 if start > stop: | |
522 step = -1 | |
523 stop += step | |
524 if stop > length: | |
525 stop = length | |
526 else: | |
527 stop = length | |
528 return pycompat.xrange(start, stop, step) | |
529 | 519 |
530 @util.propertycache | 520 @util.propertycache |
531 def nodemap(self): | 521 def nodemap(self): |
532 if self.index: | 522 if self.index: |
533 # populate mapping down to the initial node | 523 # populate mapping down to the initial node |