Mercurial > hg
changeset 29733:bb04f96df51c
wireproto: consolidate code for obtaining "cmds" argument value
Both wireproto.py and sshpeer.py had code for producing the value to
the "cmds" argument used by the "batch" command. This patch extracts
that code to a standalone function and uses it.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 06 Aug 2016 13:46:28 -0700 |
parents | 0806fa2a39d8 |
children | 62e2e048d068 |
files | mercurial/sshpeer.py mercurial/wireproto.py |
diffstat | 2 files changed, 12 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/sshpeer.py Fri Aug 05 15:35:02 2016 -0400 +++ b/mercurial/sshpeer.py Sat Aug 06 13:46:28 2016 -0700 @@ -232,13 +232,7 @@ __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.
--- a/mercurial/wireproto.py Fri Aug 05 15:35:02 2016 -0400 +++ b/mercurial/wireproto.py Sat Aug 06 13:46:28 2016 -0700 @@ -187,6 +187,16 @@ .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 @@ 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: