mercurial/hook.py
branchstable
changeset 17963 6180dcb29ec5
parent 17428 72803c8edaa4
child 17964 2c63896783e3
--- a/mercurial/hook.py	Mon Nov 26 15:42:52 2012 -0600
+++ b/mercurial/hook.py	Mon Nov 26 16:14:22 2012 -0600
@@ -142,25 +142,26 @@
         return False
 
     r = False
-
     oldstdout = -1
-    if _redirect:
-        try:
-            stdoutno = sys.__stdout__.fileno()
-            stderrno = sys.__stderr__.fileno()
-            # temporarily redirect stdout to stderr, if possible
-            if stdoutno >= 0 and stderrno >= 0:
-                sys.__stdout__.flush()
-                oldstdout = os.dup(stdoutno)
-                os.dup2(stderrno, stdoutno)
-        except AttributeError:
-            # __stdout__/__stderr__ doesn't have fileno(), it's not a real file
-            pass
 
     try:
         for hname, cmd in _allhooks(ui):
             if hname.split('.')[0] != name or not cmd:
                 continue
+
+            if oldstdout == -1 and _redirect:
+                try:
+                    stdoutno = sys.__stdout__.fileno()
+                    stderrno = sys.__stderr__.fileno()
+                    # temporarily redirect stdout to stderr, if possible
+                    if stdoutno >= 0 and stderrno >= 0:
+                        sys.__stdout__.flush()
+                        oldstdout = os.dup(stdoutno)
+                        os.dup2(stderrno, stdoutno)
+                except AttributeError:
+                    # __stdout__/__stderr__ has no fileno(), not a real file
+                    pass
+
             if util.safehasattr(cmd, '__call__'):
                 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r
             elif cmd.startswith('python:'):