##// END OF EJS Templates
hooks: delay I/O redirection until we actually run a hook (issue3711)...
Matt Mackall -
r17963:6180dcb2 stable
parent child Browse files
Show More
@@ -142,25 +142,26 b' def hook(ui, repo, name, throw=False, **'
142 return False
142 return False
143
143
144 r = False
144 r = False
145
146 oldstdout = -1
145 oldstdout = -1
147 if _redirect:
148 try:
149 stdoutno = sys.__stdout__.fileno()
150 stderrno = sys.__stderr__.fileno()
151 # temporarily redirect stdout to stderr, if possible
152 if stdoutno >= 0 and stderrno >= 0:
153 sys.__stdout__.flush()
154 oldstdout = os.dup(stdoutno)
155 os.dup2(stderrno, stdoutno)
156 except AttributeError:
157 # __stdout__/__stderr__ doesn't have fileno(), it's not a real file
158 pass
159
146
160 try:
147 try:
161 for hname, cmd in _allhooks(ui):
148 for hname, cmd in _allhooks(ui):
162 if hname.split('.')[0] != name or not cmd:
149 if hname.split('.')[0] != name or not cmd:
163 continue
150 continue
151
152 if oldstdout == -1 and _redirect:
153 try:
154 stdoutno = sys.__stdout__.fileno()
155 stderrno = sys.__stderr__.fileno()
156 # temporarily redirect stdout to stderr, if possible
157 if stdoutno >= 0 and stderrno >= 0:
158 sys.__stdout__.flush()
159 oldstdout = os.dup(stdoutno)
160 os.dup2(stderrno, stdoutno)
161 except AttributeError:
162 # __stdout__/__stderr__ has no fileno(), not a real file
163 pass
164
164 if util.safehasattr(cmd, '__call__'):
165 if util.safehasattr(cmd, '__call__'):
165 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r
166 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r
166 elif cmd.startswith('python:'):
167 elif cmd.startswith('python:'):
General Comments 0
You need to be logged in to leave comments. Login now