hook.py: fix redirections introduced by
323b9c55b328
The only non-obvious part is the use of sys.{__stderr__,__stdout__},
which is needed because sshserver overrides sys.stdout.
This makes a test that I added back in revision
7939c71f3132 ineffective.
--- a/mercurial/hook.py Mon Feb 25 09:55:57 2008 -0500
+++ b/mercurial/hook.py Fri Mar 14 21:57:46 2008 -0300
@@ -85,6 +85,7 @@
_redirect = False
def redirect(state):
+ global _redirect
_redirect = state
def hook(ui, repo, name, throw=False, **args):
@@ -92,8 +93,8 @@
if _redirect:
# temporarily redirect stdout to stderr
- oldstdout = os.dup(sys.stdout.fileno())
- os.dup2(sys.stderr.fileno(), sys.stdout.fileno())
+ oldstdout = os.dup(sys.__stdout__.fileno())
+ os.dup2(sys.__stderr__.fileno(), sys.__stdout__.fileno())
hooks = [(hname, cmd) for hname, cmd in ui.configitems("hooks")
if hname.split(".", 1)[0] == name and cmd]
@@ -106,8 +107,9 @@
args, throw) or r
else:
r = _exthook(ui, repo, hname, cmd, args, throw) or r
- return r
if _redirect:
- os.dup2(oldstdout, sys.stdout.fileno())
+ os.dup2(oldstdout, sys.__stdout__.fileno())
os.close(oldstdout)
+
+ return r
--- a/tests/test-ssh Mon Feb 25 09:55:57 2008 -0500
+++ b/tests/test-ssh Fri Mar 14 21:57:46 2008 -0300
@@ -29,7 +29,7 @@
cat <<EOF > badhook
import sys
-sys.stdout.write("KABOOM")
+sys.stdout.write("KABOOM\n")
EOF
echo "# creating 'remote'"
--- a/tests/test-ssh.out Mon Feb 25 09:55:57 2008 -0500
+++ b/tests/test-ssh.out Fri Mar 14 21:57:46 2008 -0300
@@ -78,8 +78,7 @@
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 1 changes to 1 files
-abort: unexpected response:
-'KABOOM1\n'
+remote: KABOOM
changeset: 3:ac7448082955
tag: tip
parent: 1:572896fe480d