[PATCH 3 of 3] sparse-read: ignore trailing empty revs in each read chunk

Paul Morelle paul.morelle at octobus.net
Wed Oct 18 10:36:23 EDT 2017


# HG changeset patch
# User Paul Morelle <paul.morelle at octobus.net>
# Date 1508333299 -7200
#      Wed Oct 18 15:28:19 2017 +0200
# Node ID 243f3a5bee46f9473bf2233041a8705e38194c13
# Parent  1c47a1306c856a240d9191e0f928b07493078fa7
# EXP-Topic optimized-read
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 243f3a5bee46
sparse-read: ignore trailing empty revs in each read chunk

diff -r 1c47a1306c85 -r 243f3a5bee46 mercurial/revlog.py
--- a/mercurial/revlog.py	Wed Oct 18 09:07:48 2017 +0200
+++ b/mercurial/revlog.py	Wed Oct 18 15:28:19 2017 +0200
@@ -162,6 +162,20 @@
     s.update(text)
     return s.digest()
 
+def _trimchunk(revlog, revs, startidx, endidx=None):
+    """returns revs[startidx:endidx] without empty trailing revs
+    """
+    length = revlog.length
+
+    if endidx is None:
+        endidx = len(revs)
+
+    # Trim empty revs at the end
+    while endidx > startidx and length(revs[endidx - 1]) == 0:
+        endidx -= 1
+
+    return revs[startidx:endidx]
+
 def _slicechunk(revlog, revs):
     """slice revs to reduce the amount of unrelated data to be read from disk.
 
@@ -194,6 +208,10 @@
         revstart = start(rev)
         revlen = length(rev)
 
+        # Skip empty revisions to form larger holes
+        if revlen == 0:
+            continue
+
         if prevend is not None:
             gapsize = revstart - prevend
             # only consider holes that are large enough
@@ -222,9 +240,16 @@
     previdx = 0
     while indicesheap:
         idx = heapq.heappop(indicesheap)
-        yield revs[previdx:idx]
+
+        chunk = _trimchunk(revlog, revs, previdx, idx)
+        if chunk:
+            yield chunk
+
         previdx = idx
-    yield revs[previdx:]
+
+    chunk = _trimchunk(revlog, revs, previdx)
+    if chunk:
+        yield chunk
 
 # index v0:
 #  4 bytes: offset


More information about the Mercurial-devel mailing list