comparison mercurial/hook.py @ 17964:2c63896783e3 stable

hooks: be even more forgiven of non-fd descriptors (issue3711) Looks like there are instances where sys.stdout/stderr contain file handles that are invalid. We should be tolerant of this for hook I/O redirection, as our primary concern is not garbling our own output stream.
author Matt Mackall <mpm@selenic.com>
date Mon, 26 Nov 2012 17:48:39 -0600
parents 6180dcb29ec5
children d7c28954d901
comparison
equal deleted inserted replaced
17963:6180dcb29ec5 17964:2c63896783e3
156 # temporarily redirect stdout to stderr, if possible 156 # temporarily redirect stdout to stderr, if possible
157 if stdoutno >= 0 and stderrno >= 0: 157 if stdoutno >= 0 and stderrno >= 0:
158 sys.__stdout__.flush() 158 sys.__stdout__.flush()
159 oldstdout = os.dup(stdoutno) 159 oldstdout = os.dup(stdoutno)
160 os.dup2(stderrno, stdoutno) 160 os.dup2(stderrno, stdoutno)
161 except AttributeError: 161 except (OSError, AttributeError):
162 # __stdout__/__stderr__ has no fileno(), not a real file 162 # files seem to be bogus, give up on redirecting (WSGI, etc)
163 pass 163 pass
164 164
165 if util.safehasattr(cmd, '__call__'): 165 if util.safehasattr(cmd, '__call__'):
166 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r 166 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r
167 elif cmd.startswith('python:'): 167 elif cmd.startswith('python:'):