This is an archive of the discontinued Mercurial Phabricator instance.

wireprotoserver: add context manager mechanism for redirecting stdio
ClosedPublic

Authored by indygreg on Feb 7 2018, 7:26 PM.

Details

Summary

Today, proto.redirect() sets up redirecting stdio and proto.restore()
undoes that. The API is a bit wonky because restore() is only
implemented on the HTTP protocol. Furthermore, not all calls to
redirect() are obviously paired with calls to restore(). For
example, the call to restore() for "unbundle" requests is handled
by the response handler for the HTTP protocol.

This commit introduces a new method on the protocol handler interface
to maybe capture stdio. It emits a file object or None depending on
whether stdio capture is used by the transport.

To prove it works, the "pushkey" wire protocol command has been
updated to use the new API.

I'm not convinced this is the best mechanism to capture stdio. I may
need to come up with something better once the new wire protocol
emerges into existence. But it is strictly better than before because
it removes variance in the wire protocol handler interface. It
therefore gets us closer to a unified interface between the SSH and
HTTP transports.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

indygreg created this revision.Feb 7 2018, 7:26 PM
indygreg edited the summary of this revision. (Show Details)Feb 7 2018, 11:32 PM
indygreg updated this revision to Diff 5333.
indygreg updated this revision to Diff 5344.Feb 8 2018, 12:20 AM
durin42 accepted this revision.Feb 12 2018, 4:21 PM
This revision is now accepted and ready to land.Feb 12 2018, 4:21 PM
This revision was automatically updated to reflect the committed changes.