changeset 37219:ac71cbad5da3

procutil: unroll uin/uout loop in protectstdio() I'll change uout to be redirected to stderr.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 25 Mar 2018 12:07:18 +0900
parents 97ab6f2dc3c3
children 7f78de1c93aa
files mercurial/utils/procutil.py
diffstat 1 files changed, 10 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/utils/procutil.py	Fri Mar 30 22:46:22 2018 -0700
+++ b/mercurial/utils/procutil.py	Sun Mar 25 12:07:18 2018 +0900
@@ -221,17 +221,18 @@
     "owned" in that print(), exec(), etc. never reach to them.
     """
     uout.flush()
-    newfiles = []
     nullfd = os.open(os.devnull, os.O_RDWR)
-    for f, sysf, mode in [(uin, stdin, r'rb'),
-                          (uout, stdout, r'wb')]:
-        if f is sysf:
-            newfd = os.dup(f.fileno())
-            os.dup2(nullfd, f.fileno())
-            f = os.fdopen(newfd, mode)
-        newfiles.append(f)
+    fin, fout = uin, uout
+    if uin is stdin:
+        newfd = os.dup(uin.fileno())
+        os.dup2(nullfd, uin.fileno())
+        fin = os.fdopen(newfd, r'rb')
+    if uout is stdout:
+        newfd = os.dup(uout.fileno())
+        os.dup2(nullfd, uout.fileno())
+        fout = os.fdopen(newfd, r'wb')
     os.close(nullfd)
-    return tuple(newfiles)
+    return fin, fout
 
 def restorestdio(uin, uout, fin, fout):
     """Restore (uin, uout) streams from possibly duplicated (fin, fout)"""