Mercurial > public > mercurial-scm > hg
comparison mercurial/wireproto.py @ 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 | 7f6130c7ffe1 |
children | 62e2e048d068 |
comparison
equal
deleted
inserted
replaced
29732:0806fa2a39d8 | 29733:bb04f96df51c |
---|---|
185 .replace(':e', '=') | 185 .replace(':e', '=') |
186 .replace(':s', ';') | 186 .replace(':s', ';') |
187 .replace(':o', ',') | 187 .replace(':o', ',') |
188 .replace(':c', ':')) | 188 .replace(':c', ':')) |
189 | 189 |
190 def encodebatchcmds(req): | |
191 """Return a ``cmds`` argument value for the ``batch`` command.""" | |
192 cmds = [] | |
193 for op, argsdict in req: | |
194 args = ','.join('%s=%s' % (escapearg(k), escapearg(v)) | |
195 for k, v in argsdict.iteritems()) | |
196 cmds.append('%s %s' % (op, args)) | |
197 | |
198 return ';'.join(cmds) | |
199 | |
190 # mapping of options accepted by getbundle and their types | 200 # mapping of options accepted by getbundle and their types |
191 # | 201 # |
192 # Meant to be extended by extensions. It is extensions responsibility to ensure | 202 # Meant to be extended by extensions. It is extensions responsibility to ensure |
193 # such options are properly processed in exchange.getbundle. | 203 # such options are properly processed in exchange.getbundle. |
194 # | 204 # |
224 def _submitbatch(self, req): | 234 def _submitbatch(self, req): |
225 """run batch request <req> on the server | 235 """run batch request <req> on the server |
226 | 236 |
227 Returns an iterator of the raw responses from the server. | 237 Returns an iterator of the raw responses from the server. |
228 """ | 238 """ |
229 cmds = [] | 239 rsp = self._callstream("batch", cmds=encodebatchcmds(req)) |
230 for op, argsdict in req: | |
231 args = ','.join('%s=%s' % (escapearg(k), escapearg(v)) | |
232 for k, v in argsdict.iteritems()) | |
233 cmds.append('%s %s' % (op, args)) | |
234 rsp = self._callstream("batch", cmds=';'.join(cmds)) | |
235 chunk = rsp.read(1024) | 240 chunk = rsp.read(1024) |
236 work = [chunk] | 241 work = [chunk] |
237 while chunk: | 242 while chunk: |
238 while ';' not in chunk and chunk: | 243 while ';' not in chunk and chunk: |
239 chunk = rsp.read(1024) | 244 chunk = rsp.read(1024) |