diff mercurial/utils/procutil.py @ 45046:be58fb1eaa73

procutil: make stdout line-buffered on Windows if connected to TTY Windows doesn?t support line buffering. Previously, we worked around that by setting the stream unbuffered. Instead, we can use our own line buffering we already use on Python 3.
author Manuel Jacob <me@manueljacob.de>
date Sat, 04 Jul 2020 11:41:39 +0200
parents c88577199023
children 8403cc54bc83
line wrap: on
line diff
--- a/mercurial/utils/procutil.py	Sat Jul 04 11:21:44 2020 +0200
+++ b/mercurial/utils/procutil.py	Sat Jul 04 11:41:39 2020 +0200
@@ -84,23 +84,21 @@
 stdin = pycompat.stdin
 stdout = pycompat.stdout
 
+if pycompat.iswindows:
+    stdout = platform.winstdout(stdout)
+
 # glibc determines buffering on first write to stdout - if we replace a TTY
 # destined stdout with a pipe destined stdout (e.g. pager), we want line
-# buffering (or unbuffered, on Windows)
+# buffering.
 if isatty(stdout):
-    if pycompat.iswindows:
-        # Windows doesn't support line buffering
-        stdout = os.fdopen(stdout.fileno(), 'wb', 0)
-    elif pycompat.ispy3:
+    if pycompat.ispy3 or pycompat.iswindows:
         # On Python 3, buffered binary streams can't be set line-buffered.
+        # On Python 2, Windows doesn't support line buffering.
         # Therefore we have a wrapper that implements line buffering.
         stdout = make_line_buffered(stdout)
     else:
         stdout = os.fdopen(stdout.fileno(), 'wb', 1)
 
-if pycompat.iswindows:
-    stdout = platform.winstdout(stdout)
-
 
 findexe = platform.findexe
 _gethgcmd = platform.gethgcmd