[PATCH 1 of 3] hook: do not redirect stdout/err/in to ui while running in-process hooks (BC)
Yuya Nishihara
yuya at tcha.org
Thu Nov 10 14:29:17 UTC 2016
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1476970799 -32400
# Thu Oct 20 22:39:59 2016 +0900
# Node ID 2d667ad51c1f2daa8ea5365709365d951f610aaa
# Parent 954002426f7850c92b359e6f52ce1217ac33c11e
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.
diff --git a/mercurial/hook.py b/mercurial/hook.py
--- a/mercurial/hook.py
+++ b/mercurial/hook.py
@@ -90,12 +90,6 @@ def _pythonhook(ui, repo, name, hname, f
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 @@ def _pythonhook(ui, repo, name, hname, f
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)
diff --git a/tests/test-commandserver.t b/tests/test-commandserver.t
--- a/tests/test-commandserver.t
+++ b/tests/test-commandserver.t
@@ -236,8 +236,6 @@ check that local configs for the cached
... '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*
More information about the Mercurial-devel
mailing list