Patchwork [V2] revlog: use raw revision for rawsize

login
register
mail settings
Submitter Jun Wu
Date April 3, 2017, 1:58 a.m.
Message ID <8482a52e811195186399.1491184719@x1c>
Download mbox | patch
Permalink /patch/19924/
State Accepted
Headers show

Comments

Jun Wu - April 3, 2017, 1:58 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1491184623 25200
#      Sun Apr 02 18:57:03 2017 -0700
# Node ID 8482a52e811195186399f21b87a1a6a2760593fa
# Parent  04ec317b81280c189fcea33a05c8cbbac3c186b1
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 8482a52e8111
revlog: use raw revision for rawsize

When writing the revlog-ng index, the third field is len(rawtext). See
revlog._addrevision:

    textlen = len(rawtext)
    ....
    e = (offset_type(offset, flags), l, textlen,
         base, link, p1r, p2r, node)
    self.index.insert(-1, e)

Therefore, revlog.index[rev][2] returned by revlog.rawsize should be
len(rawtext), where "rawtext" is revlog.revision(raw=True).

Unfortunately it's hard to add a test for this code path because "if l >= 0"
catches most cases.
Augie Fackler - April 3, 2017, 8:20 p.m.
On Sun, Apr 02, 2017 at 06:58:39PM -0700, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1491184623 25200
> #      Sun Apr 02 18:57:03 2017 -0700
> # Node ID 8482a52e811195186399f21b87a1a6a2760593fa
> # Parent  04ec317b81280c189fcea33a05c8cbbac3c186b1
> # Available At https://bitbucket.org/quark-zju/hg-draft

queued, thanks

> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r 8482a52e8111
> revlog: use raw revision for rawsize
>
> When writing the revlog-ng index, the third field is len(rawtext). See
> revlog._addrevision:
>
>     textlen = len(rawtext)
>     ....
>     e = (offset_type(offset, flags), l, textlen,
>          base, link, p1r, p2r, node)
>     self.index.insert(-1, e)
>
> Therefore, revlog.index[rev][2] returned by revlog.rawsize should be
> len(rawtext), where "rawtext" is revlog.revision(raw=True).
>
> Unfortunately it's hard to add a test for this code path because "if l >= 0"
> catches most cases.
>
> diff --git a/mercurial/revlog.py b/mercurial/revlog.py
> --- a/mercurial/revlog.py
> +++ b/mercurial/revlog.py
> @@ -445,5 +445,5 @@ class revlog(object):
>              return l
>
> -        t = self.revision(rev)
> +        t = self.revision(rev, raw=True)
>          return len(t)
>      size = rawsize
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -445,5 +445,5 @@  class revlog(object):
             return l
 
-        t = self.revision(rev)
+        t = self.revision(rev, raw=True)
         return len(t)
     size = rawsize