hook: lower inflated use of sys.__stdout__ and __stderr__
authorYuya Nishihara <yuya@tcha.org>
Tue, 08 Nov 2016 22:41:45 +0900
changeset 30365 5564fcd031df
parent 30364 ad56204f733e
child 30366 038547a14d85
hook: lower inflated use of sys.__stdout__ and __stderr__ They were introduced at 9f76df0edb7d, where sys.stdout could be replaced by sys.stderr. After that, we've changed the way of stdout redirection by afccc64eea73, so we no longer need to reference the original __stdout__ and __stderr__ objects. Let's move away from using __std*__ objects so we can simply wrap sys.std* objects for Python 3 porting.
mercurial/hook.py
--- a/mercurial/hook.py	Tue Nov 08 22:22:22 2016 +0900
+++ b/mercurial/hook.py	Tue Nov 08 22:41:45 2016 +0900
@@ -209,11 +209,11 @@
         for hname, cmd in hooks:
             if oldstdout == -1 and _redirect:
                 try:
-                    stdoutno = sys.__stdout__.fileno()
-                    stderrno = sys.__stderr__.fileno()
+                    stdoutno = sys.stdout.fileno()
+                    stderrno = sys.stderr.fileno()
                     # temporarily redirect stdout to stderr, if possible
                     if stdoutno >= 0 and stderrno >= 0:
-                        sys.__stdout__.flush()
+                        sys.stdout.flush()
                         oldstdout = os.dup(stdoutno)
                         os.dup2(stderrno, stdoutno)
                 except (OSError, AttributeError):
@@ -258,7 +258,7 @@
             sys.stderr.flush()
     finally:
         if _redirect and oldstdout >= 0:
-            sys.__stdout__.flush()  # write hook output to stderr fd
+            sys.stdout.flush()  # write hook output to stderr fd
             os.dup2(oldstdout, stdoutno)
             os.close(oldstdout)