Mercurial > hg
diff hgext/largefiles/proto.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 | a39a9df7ecca |
children | 90ca4986616c |
line wrap: on
line diff
--- a/hgext/largefiles/proto.py Wed Feb 07 20:17:47 2018 -0800 +++ b/hgext/largefiles/proto.py Wed Feb 07 20:19:06 2018 -0800 @@ -34,27 +34,26 @@ def putlfile(repo, proto, sha): '''Server command for putting a largefile into a repository's local store and into the user cache.''' - proto.redirect() - - path = lfutil.storepath(repo, sha) - util.makedirs(os.path.dirname(path)) - tmpfp = util.atomictempfile(path, createmode=repo.store.createmode) + with proto.mayberedirectstdio() as output: + path = lfutil.storepath(repo, sha) + util.makedirs(os.path.dirname(path)) + tmpfp = util.atomictempfile(path, createmode=repo.store.createmode) - try: - proto.getfile(tmpfp) - tmpfp._fp.seek(0) - if sha != lfutil.hexsha1(tmpfp._fp): - raise IOError(0, _('largefile contents do not match hash')) - tmpfp.close() - lfutil.linktousercache(repo, sha) - except IOError as e: - repo.ui.warn(_('largefiles: failed to put %s into store: %s\n') % - (sha, e.strerror)) - return wireproto.pushres(1) - finally: - tmpfp.discard() + try: + proto.getfile(tmpfp) + tmpfp._fp.seek(0) + if sha != lfutil.hexsha1(tmpfp._fp): + raise IOError(0, _('largefile contents do not match hash')) + tmpfp.close() + lfutil.linktousercache(repo, sha) + except IOError as e: + repo.ui.warn(_('largefiles: failed to put %s into store: %s\n') % + (sha, e.strerror)) + return wireproto.pushres(1, output.getvalue() if output else '') + finally: + tmpfp.discard() - return wireproto.pushres(0) + return wireproto.pushres(0, output.getvalue() if output else '') def getlfile(repo, proto, sha): '''Server command for retrieving a largefile from the repository-local