wireproto: drop support for reader interface from streamres (API)
2add671bf55b and later commits overhauled support for compression
and output handling in the wire protocol.
Fast forward 14 months and all wire protocol commands except
the legacy "changegroup" and "changegroupsubset" commands feed
a generator to streamres.
I no longer think it is worth maintaining support for the old
"reader" API (which allows you to specify an object having a
read() method to obtain data).
This commit refactors the legacy wire protocol commands to feed
a generator to the streamres. We also drop support for the "reader"
argument and the code that was using it.
As part of the change, chunks over the SSH protocol have increased
in size for these commands. But these commands are really ancient,
so I doubt anyone will notice.
.. api::
wireproto.streamres.__init__ no longer accepts a "reader" argument.
Use the "gen" argument instead.
Differential Revision: https://phab.mercurial-scm.org/D1861
--- a/mercurial/hgweb/protocol.py Mon Jan 08 19:41:47 2018 +0530
+++ b/mercurial/hgweb/protocol.py Mon Jan 15 15:20:02 2018 -0800
@@ -175,10 +175,7 @@
req.respond(HTTP_OK, HGTYPE, body=rsp)
return []
elif isinstance(rsp, wireproto.streamres):
- if rsp.reader:
- gen = iter(lambda: rsp.reader.read(32768), '')
- else:
- gen = rsp.gen
+ gen = rsp.gen
# This code for compression should not be streamres specific. It
# is here because we only compress streamres at the moment.
--- a/mercurial/sshserver.py Mon Jan 08 19:41:47 2018 +0530
+++ b/mercurial/sshserver.py Mon Jan 15 15:20:02 2018 -0800
@@ -76,13 +76,7 @@
def sendstream(self, source):
write = self.fout.write
-
- if source.reader:
- gen = iter(lambda: source.reader.read(4096), '')
- else:
- gen = source.gen
-
- for chunk in gen:
+ for chunk in source.gen:
write(chunk)
self.fout.flush()
--- a/mercurial/wireproto.py Mon Jan 08 19:41:47 2018 +0530
+++ b/mercurial/wireproto.py Mon Jan 15 15:20:02 2018 -0800
@@ -520,7 +520,7 @@
The call was successful and the result is a stream.
- Accepts either a generator or an object with a ``read(size)`` method.
+ Accepts a generator containing chunks of data to be sent to the client.
``v1compressible`` indicates whether this data can be compressed to
"version 1" clients (technically: HTTP peers using
@@ -528,9 +528,8 @@
new commands because new clients should support a more modern compression
mechanism.
"""
- def __init__(self, gen=None, reader=None, v1compressible=False):
+ def __init__(self, gen=None, v1compressible=False):
self.gen = gen
- self.reader = reader
self.v1compressible = v1compressible
class pushres(object):
@@ -802,7 +801,8 @@
outgoing = discovery.outgoing(repo, missingroots=nodes,
missingheads=repo.heads())
cg = changegroupmod.makechangegroup(repo, outgoing, '01', 'serve')
- return streamres(reader=cg, v1compressible=True)
+ gen = iter(lambda: cg.read(32768), '')
+ return streamres(gen=gen, v1compressible=True)
@wireprotocommand('changegroupsubset', 'bases heads')
def changegroupsubset(repo, proto, bases, heads):
@@ -811,7 +811,8 @@
outgoing = discovery.outgoing(repo, missingroots=bases,
missingheads=heads)
cg = changegroupmod.makechangegroup(repo, outgoing, '01', 'serve')
- return streamres(reader=cg, v1compressible=True)
+ gen = iter(lambda: cg.read(32768), '')
+ return streamres(gen=gen, v1compressible=True)
@wireprotocommand('debugwireargs', 'one two *')
def debugwireargs(repo, proto, one, two, others):