Mercurial
changeset 6266:9f76df0edb7d
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.
| author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
|---|---|
| date | Fri, 14 Mar 2008 21:57:46 -0300 |
| parents | be76e54570f0 |
| children | d036ea711140 |
| files | mercurial/hook.py tests/test-ssh tests/test-ssh.out |
| diffstat | 3 files changed, 8 insertions(+), 7 deletions(-) [+] |
line diff
1.1 --- a/mercurial/hook.py Mon Feb 25 09:55:57 2008 -0500 1.2 +++ b/mercurial/hook.py Fri Mar 14 21:57:46 2008 -0300 1.3 @@ -85,6 +85,7 @@ 1.4 1.5 _redirect = False 1.6 def redirect(state): 1.7 + global _redirect 1.8 _redirect = state 1.9 1.10 def hook(ui, repo, name, throw=False, **args): 1.11 @@ -92,8 +93,8 @@ 1.12 1.13 if _redirect: 1.14 # temporarily redirect stdout to stderr 1.15 - oldstdout = os.dup(sys.stdout.fileno()) 1.16 - os.dup2(sys.stderr.fileno(), sys.stdout.fileno()) 1.17 + oldstdout = os.dup(sys.__stdout__.fileno()) 1.18 + os.dup2(sys.__stderr__.fileno(), sys.__stdout__.fileno()) 1.19 1.20 hooks = [(hname, cmd) for hname, cmd in ui.configitems("hooks") 1.21 if hname.split(".", 1)[0] == name and cmd] 1.22 @@ -106,8 +107,9 @@ 1.23 args, throw) or r 1.24 else: 1.25 r = _exthook(ui, repo, hname, cmd, args, throw) or r 1.26 - return r 1.27 1.28 if _redirect: 1.29 - os.dup2(oldstdout, sys.stdout.fileno()) 1.30 + os.dup2(oldstdout, sys.__stdout__.fileno()) 1.31 os.close(oldstdout) 1.32 + 1.33 + return r
2.1 --- a/tests/test-ssh Mon Feb 25 09:55:57 2008 -0500 2.2 +++ b/tests/test-ssh Fri Mar 14 21:57:46 2008 -0300 2.3 @@ -29,7 +29,7 @@ 2.4 2.5 cat <<EOF > badhook 2.6 import sys 2.7 -sys.stdout.write("KABOOM") 2.8 +sys.stdout.write("KABOOM\n") 2.9 EOF 2.10 2.11 echo "# creating 'remote'"
3.1 --- a/tests/test-ssh.out Mon Feb 25 09:55:57 2008 -0500 3.2 +++ b/tests/test-ssh.out Fri Mar 14 21:57:46 2008 -0300 3.3 @@ -78,8 +78,7 @@ 3.4 remote: adding manifests 3.5 remote: adding file changes 3.6 remote: added 1 changesets with 1 changes to 1 files 3.7 -abort: unexpected response: 3.8 -'KABOOM1\n' 3.9 +remote: KABOOM 3.10 changeset: 3:ac7448082955 3.11 tag: tip 3.12 parent: 1:572896fe480d
