Patchwork [2,of,2,V2] revlog: make "size" diverge from "rawsize"

login
register
mail settings
Submitter Jun Wu
Date April 9, 2017, 8:14 p.m.
Message ID <02a64e62a50699e22438.1491768860@x1c>
Download mbox | patch
Permalink /patch/20042/
State Accepted
Headers show

Comments

Jun Wu - April 9, 2017, 8:14 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1491767611 25200
#      Sun Apr 09 12:53:31 2017 -0700
# Node ID 02a64e62a50699e224381821202c984c71460406
# Parent  01c8cf2cb588eea28df5f09853c702d380b631a9
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 02a64e62a506
revlog: make "size" diverge from "rawsize"

Previously, revlog.size equals to revlog.rawsize. However, the flag
processor framework could make a difference - "size" could mean the length
of len(revision(raw=False)), while "rawsize" means len(revision(raw=True)).
This patch makes it so.

This corrects "hg status" output when flag processor is involved. The call
stack looks like:

  basectx.status -> workingctx._buildstatus -> workingctx._dirstatestatus
  -> workingctx._checklookup -> filectx.cmp -> filelog.cmp -> filelog.size
  -> revlog.size
Ryan McElroy - April 10, 2017, 9:04 a.m.
On 4/9/17 9:14 PM, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1491767611 25200
> #      Sun Apr 09 12:53:31 2017 -0700
> # Node ID 02a64e62a50699e224381821202c984c71460406
> # Parent  01c8cf2cb588eea28df5f09853c702d380b631a9
> revlog: make "size" diverge from "rawsize"

This series looks good to me. Marked as pre-reviewed in patchwork.

>
> Previously, revlog.size equals to revlog.rawsize. However, the flag
> processor framework could make a difference - "size" could mean the length
> of len(revision(raw=False)), while "rawsize" means len(revision(raw=True)).
> This patch makes it so.
>
> This corrects "hg status" output when flag processor is involved. The call
> stack looks like:
>
>    basectx.status -> workingctx._buildstatus -> workingctx._dirstatestatus
>    -> workingctx._checklookup -> filectx.cmp -> filelog.cmp -> filelog.size
>    -> revlog.size
>
> diff --git a/mercurial/revlog.py b/mercurial/revlog.py
> --- a/mercurial/revlog.py
> +++ b/mercurial/revlog.py
> @@ -447,5 +447,14 @@ class revlog(object):
>           t = self.revision(rev, raw=True)
>           return len(t)
> -    size = rawsize
> +
> +    def size(self, rev):
> +        """length of non-raw text (processed by a "read" flag processor)"""
> +        # fast path: if no "read" flag processor could change the content,
> +        # size is rawsize. note: ELLIPSIS is known to not change the content.
> +        flags = self.flags(rev)
> +        if flags & (REVIDX_KNOWN_FLAGS ^ REVIDX_ELLIPSIS) == 0:
> +            return self.rawsize(rev)
> +
> +        return len(self.revision(rev, raw=False))
>   
>       def chainbase(self, rev):
> diff --git a/tests/test-flagprocessor.t b/tests/test-flagprocessor.t
> --- a/tests/test-flagprocessor.t
> +++ b/tests/test-flagprocessor.t
> @@ -245,4 +245,3 @@
>   
>     $ hg status
> -  M base64
>     $ hg diff
>
Yuya Nishihara - April 10, 2017, 1 p.m.
On Mon, 10 Apr 2017 10:04:19 +0100, Ryan McElroy wrote:
> On 4/9/17 9:14 PM, Jun Wu wrote:
> > # HG changeset patch
> > # User Jun Wu <quark@fb.com>
> > # Date 1491767611 25200
> > #      Sun Apr 09 12:53:31 2017 -0700
> > # Node ID 02a64e62a50699e224381821202c984c71460406
> > # Parent  01c8cf2cb588eea28df5f09853c702d380b631a9
> > revlog: make "size" diverge from "rawsize"
> 
> This series looks good to me. Marked as pre-reviewed in patchwork.

Queued, thanks.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -447,5 +447,14 @@  class revlog(object):
         t = self.revision(rev, raw=True)
         return len(t)
-    size = rawsize
+
+    def size(self, rev):
+        """length of non-raw text (processed by a "read" flag processor)"""
+        # fast path: if no "read" flag processor could change the content,
+        # size is rawsize. note: ELLIPSIS is known to not change the content.
+        flags = self.flags(rev)
+        if flags & (REVIDX_KNOWN_FLAGS ^ REVIDX_ELLIPSIS) == 0:
+            return self.rawsize(rev)
+
+        return len(self.revision(rev, raw=False))
 
     def chainbase(self, rev):
diff --git a/tests/test-flagprocessor.t b/tests/test-flagprocessor.t
--- a/tests/test-flagprocessor.t
+++ b/tests/test-flagprocessor.t
@@ -245,4 +245,3 @@ 
 
   $ hg status
-  M base64
   $ hg diff