revlog: _segmentspan computes the byte span of a segment
authorPaul Morelle <paul.morelle@octobus.net>
Thu, 17 May 2018 15:10:36 +0200
changeset 38636 25534e0cf0d9
parent 38635 d083ae26c325
child 38637 e33f784f2a44
revlog: _segmentspan computes the byte span of a segment Refactor out this code to be used somewhere else in a next changeset
mercurial/revlog.py
--- a/mercurial/revlog.py	Tue Jul 10 15:17:05 2018 -0700
+++ b/mercurial/revlog.py	Thu May 17 15:10:36 2018 +0200
@@ -210,6 +210,15 @@
 
     return revs[startidx:endidx]
 
+def _segmentspan(revlog, revs):
+    """Get the byte span of a segment of revisions
+
+    revs is a sorted array of revision numbers
+    """
+    if not revs:
+        return 0
+    return revlog.end(revs[-1]) - revlog.start(revs[0])
+
 def _slicechunk(revlog, revs):
     """slice revs to reduce the amount of unrelated data to be read from disk.
 
@@ -223,9 +232,7 @@
         yield revs
         return
 
-    startbyte = start(revs[0])
-    endbyte = start(revs[-1]) + length(revs[-1])
-    readdata = deltachainspan = endbyte - startbyte
+    readdata = deltachainspan = _segmentspan(revlog, revs)
 
     if deltachainspan < revlog._srmingapsize:
         yield revs