diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py --- a/mercurial/sshpeer.py +++ b/mercurial/sshpeer.py @@ -232,13 +232,7 @@ class sshpeer(wireproto.wirepeer): __del__ = cleanup def _submitbatch(self, req): - cmds = [] - for op, argsdict in req: - args = ','.join('%s=%s' % (wireproto.escapearg(k), - wireproto.escapearg(v)) - for k, v in argsdict.iteritems()) - cmds.append('%s %s' % (op, args)) - rsp = self._callstream("batch", cmds=';'.join(cmds)) + rsp = self._callstream("batch", cmds=wireproto.encodebatchcmds(req)) available = self._getamount() # TODO this response parsing is probably suboptimal for large # batches with large responses. diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py --- a/mercurial/wireproto.py +++ b/mercurial/wireproto.py @@ -187,6 +187,16 @@ def unescapearg(escaped): .replace(':o', ',') .replace(':c', ':')) +def encodebatchcmds(req): + """Return a ``cmds`` argument value for the ``batch`` command.""" + cmds = [] + for op, argsdict in req: + args = ','.join('%s=%s' % (escapearg(k), escapearg(v)) + for k, v in argsdict.iteritems()) + cmds.append('%s %s' % (op, args)) + + return ';'.join(cmds) + # mapping of options accepted by getbundle and their types # # Meant to be extended by extensions. It is extensions responsibility to ensure @@ -226,12 +236,7 @@ class wirepeer(peer.peerrepository): Returns an iterator of the raw responses from the server. """ - cmds = [] - for op, argsdict in req: - args = ','.join('%s=%s' % (escapearg(k), escapearg(v)) - for k, v in argsdict.iteritems()) - cmds.append('%s %s' % (op, args)) - rsp = self._callstream("batch", cmds=';'.join(cmds)) + rsp = self._callstream("batch", cmds=encodebatchcmds(req)) chunk = rsp.read(1024) work = [chunk] while chunk: