Mercurial > hg
comparison mercurial/wireprotoserver.py @ 36067:caca3ac2ac04
wireproto: use maybecapturestdio() for push responses (API)
The "pushres" and "pusherr" response types currently call
proto.restore() in the HTTP protocol. This completes the pairing
with proto.redirect() that occurs in the @wireprotocommand
functions. (But since the SSH protocol has a no-op redirect(),
it doesn't bother calling restore() because it would also be
a no-op.)
Having the disconnect between these paired calls is very confusing.
Knowing that you must use proto.redirect() if returning a "pushres"
or a "pusherr" is even wonkier.
We replace this confusing code with our new context manager for
[maybe] capturing output.
The "pushres" and "pusherr" types have gained an "output" argument
to their constructor and an attribute to hold captured data. The
HTTP protocol now retrieves output from these objects.
.. api::
``wireproto.pushres`` and ``wireproto.pusherr`` now explicitly
track stdio output.
Differential Revision: https://phab.mercurial-scm.org/D2082
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 07 Feb 2018 20:19:06 -0800 |
parents | 2ad145fbde54 |
children | 56fe8a3b2d52 |
comparison
equal
deleted
inserted
replaced
36066:2ad145fbde54 | 36067:caca3ac2ac04 |
---|---|
318 gen = genversion2(gen, engine, engineopts) | 318 gen = genversion2(gen, engine, engineopts) |
319 | 319 |
320 req.respond(HTTP_OK, mediatype) | 320 req.respond(HTTP_OK, mediatype) |
321 return gen | 321 return gen |
322 elif isinstance(rsp, wireproto.pushres): | 322 elif isinstance(rsp, wireproto.pushres): |
323 val = proto.restore() | 323 rsp = '%d\n%s' % (rsp.res, rsp.output) |
324 rsp = '%d\n%s' % (rsp.res, val) | |
325 req.respond(HTTP_OK, HGTYPE, body=rsp) | 324 req.respond(HTTP_OK, HGTYPE, body=rsp) |
326 return [] | 325 return [] |
327 elif isinstance(rsp, wireproto.pusherr): | 326 elif isinstance(rsp, wireproto.pusherr): |
328 # This is the httplib workaround documented in _handlehttperror(). | 327 # This is the httplib workaround documented in _handlehttperror(). |
329 req.drain() | 328 req.drain() |
330 | 329 |
331 proto.restore() | |
332 rsp = '0\n%s\n' % rsp.res | 330 rsp = '0\n%s\n' % rsp.res |
333 req.respond(HTTP_OK, HGTYPE, body=rsp) | 331 req.respond(HTTP_OK, HGTYPE, body=rsp) |
334 return [] | 332 return [] |
335 elif isinstance(rsp, wireproto.ooberror): | 333 elif isinstance(rsp, wireproto.ooberror): |
336 rsp = rsp.message | 334 rsp = rsp.message |