[PATCH 4 of 5] wireproto: rename argument to groupchunks()
Gregory Szorc
gregory.szorc at gmail.com
Sun Sep 25 16:42:16 EDT 2016
# HG changeset patch
# User Gregory Szorc <gregory.szorc at 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.
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)
More information about the Mercurial-devel
mailing list