Patchwork D1861: wireproto: drop support for reader interface from streamres (API)

login
register
mail settings
Submitter phabricator
Date Jan. 15, 2018, 11:20 p.m.
Message ID <differential-rev-PHID-DREV-r444f3leuif7rsfc4opp-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/26776/
State Superseded
Headers show

Comments

phabricator - Jan. 15, 2018, 11:20 p.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  https://phab.mercurial-scm.org/rHG2add671bf55bc2a5506405aa04c64b41c6d22420 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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1861

AFFECTED FILES
  mercurial/hgweb/protocol.py
  mercurial/sshserver.py
  mercurial/wireproto.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -520,17 +520,16 @@ 
 
     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
     application/mercurial-0.1 media type). This flag should NOT be used on
     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,16 +801,18 @@ 
     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):
     bases = decodelist(bases)
     heads = decodelist(heads)
     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):
diff --git a/mercurial/sshserver.py b/mercurial/sshserver.py
--- a/mercurial/sshserver.py
+++ b/mercurial/sshserver.py
@@ -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()
 
diff --git a/mercurial/hgweb/protocol.py b/mercurial/hgweb/protocol.py
--- a/mercurial/hgweb/protocol.py
+++ b/mercurial/hgweb/protocol.py
@@ -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.