Mercurial > hg
changeset 30363:a1259e502bdf
hook: do not redirect stdout/err/in to ui while running in-process hooks (BC)
It was introduced by a59058fd074a to address command-server issues. After
that, I've made a complete fix by 69f86b937035, so we don't need to replace
sys.stdio objects to protect the IPC channels.
This change means we no longer see data written to sys.stdout/err by an
in-process hook on command server. I think that's okay because the canonical
way is to use ui functions and in-process hooks should respect the Mercurial
API.
This will help Python 3 porting, where sys.stdout is TextIO but ui.fout is
BytesIO.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 20 Oct 2016 22:39:59 +0900 |
parents | 3c6893ba2d36 |
children | ad56204f733e |
files | mercurial/hook.py tests/test-commandserver.t |
diffstat | 2 files changed, 0 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hook.py Thu Nov 10 02:21:15 2016 -0800 +++ b/mercurial/hook.py Thu Oct 20 22:39:59 2016 +0900 @@ -90,12 +90,6 @@ starttime = time.time() try: - # redirect IO descriptors to the ui descriptors so hooks - # that write directly to these don't mess up the command - # protocol when running through the command server - old = sys.stdout, sys.stderr, sys.stdin - sys.stdout, sys.stderr, sys.stdin = ui.fout, ui.ferr, ui.fin - r = obj(ui=ui, repo=repo, hooktype=name, **args) except Exception as exc: if isinstance(exc, error.Abort): @@ -111,7 +105,6 @@ ui.traceback() return True, True finally: - sys.stdout, sys.stderr, sys.stdin = old duration = time.time() - starttime ui.log('pythonhook', 'pythonhook-%s: %s finished in %0.2f seconds\n', name, funcname, duration)
--- a/tests/test-commandserver.t Thu Nov 10 02:21:15 2016 -0800 +++ b/tests/test-commandserver.t Thu Oct 20 22:39:59 2016 +0900 @@ -236,8 +236,6 @@ ... 'id'], ... input=stringio('some input')) *** runcommand --config hooks.pre-identify=python:hook.hook id - hook talking - now try to read something: 'some input' eff892de26ec tip $ rm hook.py*