Patchwork [evolve-ext] wireproto: chunking and compression is forthwith to be handled by hgweb

login
register
mail settings
Submitter Martijn Pieters
Date Nov. 29, 2016, 4:10 p.m.
Message ID <28a092ed406e930894c5.1480435845@mjpieters-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/17794/
State Superseded
Headers show

Comments

Martijn Pieters - Nov. 29, 2016, 4:10 p.m.
# HG changeset patch
# User Martijn Pieters <mjpieters@fb.com>
# Date 1480435818 0
#      Tue Nov 29 16:10:18 2016 +0000
# Node ID 28a092ed406e930894c59eb88d645221abddc307
# Parent  cb2bac3253fbd52894ffcb4719a148fe6a3da38b
wireproto: chunking and compression is forthwith to be handled by hgweb

Various functions disappeared in the process. Use the new streamres API but fall back to the old way if the keyword arguments are not accepted.

See https://www.mercurial-scm.org/repo/hg/rev/2add671bf55b
Kostia Balytskyi - Nov. 29, 2016, 11:23 p.m.
This looks good to me, although I would maybe perform a more thorough check than just catching a TypeError. For example, something like check:
    if “v1compressible” in wireproto.streamres.__init__.__code__.co_varnames:
        pass this arg
    else:
        don’t pass it


On 11/29/16, 4:10 PM, "Mercurial-devel on behalf of Martijn Pieters" <mercurial-devel-bounces@mercurial-scm.org on behalf of mj@zopatista.com> wrote:

    # HG changeset patch
    # User Martijn Pieters <mjpieters@fb.com>
    # Date 1480435818 0
    #      Tue Nov 29 16:10:18 2016 +0000
    # Node ID 28a092ed406e930894c59eb88d645221abddc307
    # Parent  cb2bac3253fbd52894ffcb4719a148fe6a3da38b
    wireproto: chunking and compression is forthwith to be handled by hgweb
    
    Various functions disappeared in the process. Use the new streamres API but fall back to the old way if the keyword arguments are not accepted.
    
    See https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.org_repo_hg_rev_2add671bf55b&d=DgIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=Pp-gQYFgs4tKlSFPF5kfCw&m=itsfqjECZoIFxlvcK1F6-xHmasBtG5DrNpHJ5crQ8Qk&s=L9z5Oyy5EDFtbdleAKmWKcYdz4ScmzGLZznUUuk5k_8&e= 
    
    diff --git a/hgext/evolve.py b/hgext/evolve.py
    --- a/hgext/evolve.py
    +++ b/hgext/evolve.py
    @@ -3848,7 +3848,12 @@
         finaldata.write('%20i' % len(obsdata))
         finaldata.write(obsdata)
         finaldata.seek(0)
    -    return wireproto.streamres(proto.groupchunks(finaldata))
    +    try:
    +        return wireproto.streamres(reader=finaldata, v1compressible=True)
    +    except TypeError:
    +        # older mercurial version, expected to do our own compression
    +        return wireproto.streamres(proto.groupchunks(finaldata))
    +
     
     def _obsrelsethashtreefm0(repo):
         return _obsrelsethashtree(repo, obsolete._fm0encodeonemarker)
    diff --git a/hgext/simple4server.py b/hgext/simple4server.py
    --- a/hgext/simple4server.py
    +++ b/hgext/simple4server.py
    @@ -175,7 +175,11 @@
         finaldata.write('%20i' % len(obsdata))
         finaldata.write(obsdata)
         finaldata.seek(0)
    -    return wireproto.streamres(proto.groupchunks(finaldata))
    +    try:
    +        return wireproto.streamres(reader=finaldata, v1compressible=True)
    +    except TypeError:
    +        # older mercurial version, expected to do our own compression
    +        return wireproto.streamres(proto.groupchunks(finaldata))
     
     
     # from evolve extension: 3249814dabd1
    _______________________________________________
    Mercurial-devel mailing list
    Mercurial-devel@mercurial-scm.org
    https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.org_mailman_listinfo_mercurial-2Ddevel&d=DgIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=Pp-gQYFgs4tKlSFPF5kfCw&m=itsfqjECZoIFxlvcK1F6-xHmasBtG5DrNpHJ5crQ8Qk&s=Ja50nSg2ysFrAQC62ZhOs8UsS5w1-omMglM6HYBbfjg&e=
Martijn Pieters - Nov. 30, 2016, 10:50 a.m.
On 29 November 2016 at 23:23, Kostia Balytskyi <ikostia@fb.com> wrote:
>
> This looks good to me, although I would maybe perform a more thorough
check than just catching a TypeError. For example, something like check:
>     if “v1compressible” in
wireproto.streamres.__init__.__code__.co_varnames:
>         pass this arg
>     else:
>         don’t pass it


We could just store a test for `proto.groupchunks`:

    if util.safehasattr(proto, 'groupchunks'):
        streamres = lambda reader:
wireproto.streamres(proto.groupchunks(reader))
    else:
        streamres = functools.partial(wireproto.streamres,
v1compressible=True)

then use

    streamres(reader=finaldata)

That avoids a) checking for a mercurial version-specific attribute on each
send, and b) making it slightly more readable for future maintainers. I'll
send a V2.


> On 11/29/16, 4:10 PM, "Mercurial-devel on behalf of Martijn Pieters" <
mercurial-devel-bounces@mercurial-scm.org on behalf of mj@zopatista.com>
wrote:
>
>     # HG changeset patch
>     # User Martijn Pieters <mjpieters@fb.com>
>     # Date 1480435818 0
>     #      Tue Nov 29 16:10:18 2016 +0000
>     # Node ID 28a092ed406e930894c59eb88d645221abddc307
>     # Parent  cb2bac3253fbd52894ffcb4719a148fe6a3da38b
>     wireproto: chunking and compression is forthwith to be handled by
hgweb
>
>     Various functions disappeared in the process. Use the new streamres
API but fall back to the old way if the keyword arguments are not accepted.
>
>     See
https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.org_repo_hg_rev_2add671bf55b&d=DgIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=Pp-gQYFgs4tKlSFPF5kfCw&m=itsfqjECZoIFxlvcK1F6-xHmasBtG5DrNpHJ5crQ8Qk&s=L9z5Oyy5EDFtbdleAKmWKcYdz4ScmzGLZznUUuk5k_8&e=
>
>     diff --git a/hgext/evolve.py b/hgext/evolve.py
>     --- a/hgext/evolve.py
>     +++ b/hgext/evolve.py
>     @@ -3848,7 +3848,12 @@
>          finaldata.write('%20i' % len(obsdata))
>          finaldata.write(obsdata)
>          finaldata.seek(0)
>     -    return wireproto.streamres(proto.groupchunks(finaldata))
>     +    try:
>     +        return wireproto.streamres(reader=finaldata,
v1compressible=True)
>     +    except TypeError:
>     +        # older mercurial version, expected to do our own compression
>     +        return wireproto.streamres(proto.groupchunks(finaldata))
>     +
>
>      def _obsrelsethashtreefm0(repo):
>          return _obsrelsethashtree(repo, obsolete._fm0encodeonemarker)
>     diff --git a/hgext/simple4server.py b/hgext/simple4server.py
>     --- a/hgext/simple4server.py
>     +++ b/hgext/simple4server.py
>     @@ -175,7 +175,11 @@
>          finaldata.write('%20i' % len(obsdata))
>          finaldata.write(obsdata)
>          finaldata.seek(0)
>     -    return wireproto.streamres(proto.groupchunks(finaldata))
>     +    try:
>     +        return wireproto.streamres(reader=finaldata,
v1compressible=True)
>     +    except TypeError:
>     +        # older mercurial version, expected to do our own compression
>     +        return wireproto.streamres(proto.groupchunks(finaldata))
>
>
>      # from evolve extension: 3249814dabd1
>     _______________________________________________
>     Mercurial-devel mailing list
>     Mercurial-devel@mercurial-scm.org
>
https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.org_mailman_listinfo_mercurial-2Ddevel&d=DgIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=Pp-gQYFgs4tKlSFPF5kfCw&m=itsfqjECZoIFxlvcK1F6-xHmasBtG5DrNpHJ5crQ8Qk&s=Ja50nSg2ysFrAQC62ZhOs8UsS5w1-omMglM6HYBbfjg&e=
>
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel




--
Martijn Pieters

Patch

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -3848,7 +3848,12 @@ 
     finaldata.write('%20i' % len(obsdata))
     finaldata.write(obsdata)
     finaldata.seek(0)
-    return wireproto.streamres(proto.groupchunks(finaldata))
+    try:
+        return wireproto.streamres(reader=finaldata, v1compressible=True)
+    except TypeError:
+        # older mercurial version, expected to do our own compression
+        return wireproto.streamres(proto.groupchunks(finaldata))
+
 
 def _obsrelsethashtreefm0(repo):
     return _obsrelsethashtree(repo, obsolete._fm0encodeonemarker)
diff --git a/hgext/simple4server.py b/hgext/simple4server.py
--- a/hgext/simple4server.py
+++ b/hgext/simple4server.py
@@ -175,7 +175,11 @@ 
     finaldata.write('%20i' % len(obsdata))
     finaldata.write(obsdata)
     finaldata.seek(0)
-    return wireproto.streamres(proto.groupchunks(finaldata))
+    try:
+        return wireproto.streamres(reader=finaldata, v1compressible=True)
+    except TypeError:
+        # older mercurial version, expected to do our own compression
+        return wireproto.streamres(proto.groupchunks(finaldata))
 
 
 # from evolve extension: 3249814dabd1