wireproto: drop the _decompress method in favor a new call type
We already have multiple call function for multiple return type. The
`_decompress` function is only used for http and seems like a layer violation.
We drop it in favor of a new call type dedicated to "stream that may be useful to
compress".
--- a/mercurial/httppeer.py Fri Mar 28 12:29:34 2014 -0700
+++ b/mercurial/httppeer.py Fri Mar 28 14:24:13 2014 -0700
@@ -211,10 +211,8 @@
fp.close()
os.unlink(tempname)
- def _abort(self, exception):
- raise exception
-
- def _decompress(self, stream):
+ def _callcompressable(self, cmd, **args):
+ stream = self._callstream(cmd, **args)
return util.chunkbuffer(zgenerator(stream))
class httpspeer(httppeer):
--- a/mercurial/sshpeer.py Fri Mar 28 12:29:34 2014 -0700
+++ b/mercurial/sshpeer.py Fri Mar 28 14:24:13 2014 -0700
@@ -157,6 +157,9 @@
return self.pipei
+ def _callcompressable(self, cmd, **args):
+ return self._callstream(cmd, **args)
+
def _call(self, cmd, **args):
self._callstream(cmd, **args)
return self._recv()
@@ -176,8 +179,6 @@
return '', r
return self._recv(), ''
- def _decompress(self, stream):
- return stream
def _recv(self):
l = self.pipei.readline()
--- a/mercurial/wireproto.py Fri Mar 28 12:29:34 2014 -0700
+++ b/mercurial/wireproto.py Fri Mar 28 14:24:13 2014 -0700
@@ -314,16 +314,16 @@
def changegroup(self, nodes, kind):
n = encodelist(nodes)
- f = self._callstream("changegroup", roots=n)
- return changegroupmod.unbundle10(self._decompress(f), 'UN')
+ f = self._callcompressable("changegroup", roots=n)
+ return changegroupmod.unbundle10(f, 'UN')
def changegroupsubset(self, bases, heads, kind):
self.requirecap('changegroupsubset', _('look up remote changes'))
bases = encodelist(bases)
heads = encodelist(heads)
- f = self._callstream("changegroupsubset",
- bases=bases, heads=heads)
- return changegroupmod.unbundle10(self._decompress(f), 'UN')
+ f = self._callcompressable("changegroupsubset",
+ bases=bases, heads=heads)
+ return changegroupmod.unbundle10(f, 'UN')
def getbundle(self, source, heads=None, common=None, bundlecaps=None):
self.requirecap('getbundle', _('look up remote changes'))
@@ -334,8 +334,8 @@
opts['common'] = encodelist(common)
if bundlecaps is not None:
opts['bundlecaps'] = ','.join(bundlecaps)
- f = self._callstream("getbundle", **opts)
- return changegroupmod.unbundle10(self._decompress(f), 'UN')
+ f = self._callcompressable("getbundle", **opts)
+ return changegroupmod.unbundle10(f, 'UN')
def unbundle(self, cg, heads, source):
'''Send cg (a readable file-like object representing the
@@ -388,6 +388,19 @@
returns the server reply as a file like object."""
raise NotImplementedError()
+ def _callcompressable(self, cmd, **args):
+ """execute <cmd> on the server
+
+ The command is expected to return a stream.
+
+ The stream may have been compressed in some implementaitons. This
+ function takes care of the decompression. This is the only difference
+ with _callstream.
+
+ returns the server reply as a file like object.
+ """
+ raise NotImplementedError()
+
def _callpush(self, cmd, fp, **args):
"""execute a <cmd> on server
@@ -404,12 +417,6 @@
"""
raise NotImplementedError()
-
- def _decompress(self, stream):
- """decompress a received stream
- """
- raise NotImplementedError()
-
# server side
# wire protocol command can either return a string or one of these classes.