Patchwork [05,of,13] revlog: _segmentspan computes the byte span of a segment

login
register
mail settings
Submitter Boris Feld
Date July 10, 2018, 1:27 p.m.
Message ID <3a5b4001c68a7d56793e.1531229234@FB-lair>
Download mbox | patch
Permalink /patch/32744/
State Accepted
Headers show

Comments

Boris Feld - July 10, 2018, 1:27 p.m.
# HG changeset patch
# User Paul Morelle <paul.morelle@octobus.net>
# Date 1526562636 -7200
#      Thu May 17 15:10:36 2018 +0200
# Node ID 3a5b4001c68a7d56793e2a3b8028609932e36abc
# Parent  88131bca12f52021ee6ab0048df4a10146cbd962
# EXP-Topic write-for-sparse-read
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 3a5b4001c68a
revlog: _segmentspan computes the byte span of a segment

Refactor out this code to be used somewhere else in a next changeset

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -210,6 +210,15 @@  def _trimchunk(revlog, revs, startidx, e
 
     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 @@  def _slicechunk(revlog, revs):
         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