hooks: be even more forgiven of non-fd descriptors (issue3711) stable
authorMatt Mackall <mpm@selenic.com>
Mon, 26 Nov 2012 17:48:39 -0600
branchstable
changeset 17964 2c63896783e3
parent 17963 6180dcb29ec5
child 17979 b3ec0b5fd777
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.
mercurial/hook.py
--- a/mercurial/hook.py	Mon Nov 26 16:14:22 2012 -0600
+++ b/mercurial/hook.py	Mon Nov 26 17:48:39 2012 -0600
@@ -158,8 +158,8 @@
                         sys.__stdout__.flush()
                         oldstdout = os.dup(stdoutno)
                         os.dup2(stderrno, stdoutno)
-                except AttributeError:
-                    # __stdout__/__stderr__ has no fileno(), not a real file
+                except (OSError, AttributeError):
+                    # files seem to be bogus, give up on redirecting (WSGI, etc)
                     pass
 
             if util.safehasattr(cmd, '__call__'):