comparison mercurial/hook.py @ 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 2c565b9598b8
children f67d1468ac50
comparison
equal deleted inserted replaced
6265:be76e54570f0 6266:9f76df0edb7d
83 ui.warn(_('warning: %s hook %s\n') % (name, desc)) 83 ui.warn(_('warning: %s hook %s\n') % (name, desc))
84 return r 84 return r
85 85
86 _redirect = False 86 _redirect = False
87 def redirect(state): 87 def redirect(state):
88 global _redirect
88 _redirect = state 89 _redirect = state
89 90
90 def hook(ui, repo, name, throw=False, **args): 91 def hook(ui, repo, name, throw=False, **args):
91 r = False 92 r = False
92 93
93 if _redirect: 94 if _redirect:
94 # temporarily redirect stdout to stderr 95 # temporarily redirect stdout to stderr
95 oldstdout = os.dup(sys.stdout.fileno()) 96 oldstdout = os.dup(sys.__stdout__.fileno())
96 os.dup2(sys.stderr.fileno(), sys.stdout.fileno()) 97 os.dup2(sys.__stderr__.fileno(), sys.__stdout__.fileno())
97 98
98 hooks = [(hname, cmd) for hname, cmd in ui.configitems("hooks") 99 hooks = [(hname, cmd) for hname, cmd in ui.configitems("hooks")
99 if hname.split(".", 1)[0] == name and cmd] 100 if hname.split(".", 1)[0] == name and cmd]
100 hooks.sort() 101 hooks.sort()
101 for hname, cmd in hooks: 102 for hname, cmd in hooks:
104 elif cmd.startswith('python:'): 105 elif cmd.startswith('python:'):
105 r = _pythonhook(ui, repo, name, hname, cmd[7:].strip(), 106 r = _pythonhook(ui, repo, name, hname, cmd[7:].strip(),
106 args, throw) or r 107 args, throw) or r
107 else: 108 else:
108 r = _exthook(ui, repo, hname, cmd, args, throw) or r 109 r = _exthook(ui, repo, hname, cmd, args, throw) or r
109 return r
110 110
111 if _redirect: 111 if _redirect:
112 os.dup2(oldstdout, sys.stdout.fileno()) 112 os.dup2(oldstdout, sys.__stdout__.fileno())
113 os.close(oldstdout) 113 os.close(oldstdout)
114
115 return r