##// END OF EJS Templates
hooks: restore io correctly on exception
Jesse Long -
r7416:196b05a5 default
parent child Browse files
Show More
@@ -96,19 +96,20 b' def hook(ui, repo, name, throw=False, **'
96 oldstdout = os.dup(sys.__stdout__.fileno())
96 oldstdout = os.dup(sys.__stdout__.fileno())
97 os.dup2(sys.__stderr__.fileno(), sys.__stdout__.fileno())
97 os.dup2(sys.__stderr__.fileno(), sys.__stdout__.fileno())
98
98
99 for hname, cmd in util.sort(ui.configitems('hooks')):
99 try:
100 if hname.split('.')[0] != name or not cmd:
100 for hname, cmd in util.sort(ui.configitems('hooks')):
101 continue
101 if hname.split('.')[0] != name or not cmd:
102 if callable(cmd):
102 continue
103 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r
103 if callable(cmd):
104 elif cmd.startswith('python:'):
104 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r
105 r = _pythonhook(ui, repo, name, hname, cmd[7:].strip(),
105 elif cmd.startswith('python:'):
106 args, throw) or r
106 r = _pythonhook(ui, repo, name, hname, cmd[7:].strip(),
107 else:
107 args, throw) or r
108 r = _exthook(ui, repo, hname, cmd, args, throw) or r
108 else:
109
109 r = _exthook(ui, repo, hname, cmd, args, throw) or r
110 if _redirect:
110 finally:
111 os.dup2(oldstdout, sys.__stdout__.fileno())
111 if _redirect:
112 os.close(oldstdout)
112 os.dup2(oldstdout, sys.__stdout__.fileno())
113 os.close(oldstdout)
113
114
114 return r
115 return r
General Comments 0
You need to be logged in to leave comments. Login now