Patchwork [4,of,5] wireproto: rename argument to groupchunks()

login
register
mail settings
Submitter Gregory Szorc
Date Sept. 25, 2016, 8:42 p.m.
Message ID <2dc93677a8836d2365b5.1474836136@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/16786/
State Accepted
Headers show

Comments

Gregory Szorc - Sept. 25, 2016, 8:42 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1474831231 25200
#      Sun Sep 25 12:20:31 2016 -0700
# Node ID 2dc93677a8836d2365b561d1ba79f62ff68a4f23
# Parent  25fddb8433d383adc567fbe0722878512058561d
wireproto: rename argument to groupchunks()

groupchunks() is a generic "turn a file object into a generator"
function. It isn't limited to changegroups. Rename the argument
and update the docstring to reflect this.
Pierre-Yves David - Sept. 27, 2016, 1:16 p.m.
On 09/25/2016 10:42 PM, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1474831231 25200
> #      Sun Sep 25 12:20:31 2016 -0700
> # Node ID 2dc93677a8836d2365b561d1ba79f62ff68a4f23
> # Parent  25fddb8433d383adc567fbe0722878512058561d
> wireproto: rename argument to groupchunks()
>
> groupchunks() is a generic "turn a file object into a generator"
> function. It isn't limited to changegroups. Rename the argument
> and update the docstring to reflect this.

Pushed patch 1-4. Currently looking into patch 5.

Patch

diff --git a/mercurial/hgweb/protocol.py b/mercurial/hgweb/protocol.py
--- a/mercurial/hgweb/protocol.py
+++ b/mercurial/hgweb/protocol.py
@@ -68,23 +68,23 @@  class webproto(wireproto.abstractserverp
             fp.write(s)
     def redirect(self):
         self.oldio = self.ui.fout, self.ui.ferr
         self.ui.ferr = self.ui.fout = stringio()
     def restore(self):
         val = self.ui.fout.getvalue()
         self.ui.ferr, self.ui.fout = self.oldio
         return val
-    def groupchunks(self, cg):
+    def groupchunks(self, fh):
         # Don't allow untrusted settings because disabling compression or
         # setting a very high compression level could lead to flooding
         # the server's network or CPU.
         z = zlib.compressobj(self.ui.configint('server', 'zliblevel', -1))
         while True:
-            chunk = cg.read(32768)
+            chunk = fh.read(32768)
             if not chunk:
                 break
             data = z.compress(chunk)
             # Not all calls to compress() emit data. It is cheaper to inspect
             # that here than to send it via the generator.
             if data:
                 yield data
         yield z.flush()
diff --git a/mercurial/sshserver.py b/mercurial/sshserver.py
--- a/mercurial/sshserver.py
+++ b/mercurial/sshserver.py
@@ -63,18 +63,18 @@  class sshserver(wireproto.abstractserver
         count = int(self.fin.readline())
         while count:
             fpout.write(self.fin.read(count))
             count = int(self.fin.readline())
 
     def redirect(self):
         pass
 
-    def groupchunks(self, changegroup):
-        return iter(lambda: changegroup.read(4096), '')
+    def groupchunks(self, fh):
+        return iter(lambda: fh.read(4096), '')
 
     def sendresponse(self, v):
         self.fout.write("%d\n" % len(v))
         self.fout.write(v)
         self.fout.flush()
 
     def sendstream(self, source):
         write = self.fout.write
diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -73,20 +73,21 @@  class abstractserverproto(object):
     #
     # left commented here on purpose
     #
     #def restore(self):
     #    """reinstall previous stdout and stderr and return intercepted stdout
     #    """
     #    raise NotImplementedError()
 
-    def groupchunks(self, cg):
-        """return 4096 chunks from a changegroup object
+    def groupchunks(self, fh):
+        """Generator of chunks to send to the client.
 
-        Some protocols may have compressed the contents."""
+        Some protocols may have compressed the contents.
+        """
         raise NotImplementedError()
 
 class remotebatch(peer.batcher):
     '''batches the queued calls; uses as few roundtrips as possible'''
     def __init__(self, remote):
         '''remote must support _submitbatch(encbatch) and
         _submitone(op, encargs)'''
         peer.batcher.__init__(self)