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

login
register
mail settings
Submitter Paul Morelle
Date Oct. 18, 2017, 2:36 p.m.
Message ID <243f3a5bee46f9473bf2.1508337383@taranis.localdomain>
Download mbox | patch
Permalink /patch/25170/
State Accepted
Headers show

Comments

Paul Morelle - Oct. 18, 2017, 2:36 p.m.
# HG changeset patch
# User Paul Morelle <paul.morelle@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
Augie Fackler - Oct. 18, 2017, 7:26 p.m.
On Wed, Oct 18, 2017 at 04:36:23PM +0200, Paul Morelle wrote:
> # HG changeset patch
> # User Paul Morelle <paul.morelle@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

I've queued the first two, but I feel like this could use some more
explanation in the commit message. How do these empty revs happen? I
assume they're safe to skip, but maybe elaborate on that too...

(If we can get this in tomorrow, that'll be fine, even if we're
nominally frozen by then.)

>
> 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
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

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