Patchwork [05,of,11,V2] procutil: use mercurial.windows.winstdout only on Python 2 and TTYs

login
register
mail settings
Submitter Manuel Jacob
Date July 12, 2020, 10:41 p.m.
Message ID <d439863e9340a845d2f1.1594593690@tmp>
Download mbox | patch
Permalink /patch/46709/
State Accepted
Headers show

Comments

Manuel Jacob - July 12, 2020, 10:41 p.m.
# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1594368185 -7200
#      Fri Jul 10 10:03:05 2020 +0200
# Node ID d439863e9340a845d2f1986ec45f40f38704e932
# Parent  d7f793516419e60b23c5a667c57972a6d1ac0f0f
# EXP-Topic stdio
procutil: use mercurial.windows.winstdout only on Python 2 and TTYs

Python 3 already works around the bug. The workaround is only needed when
writing to consoles. If stdout is a console, sys.stdout.isatty() is true.

Patch

diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py
+++ b/mercurial/utils/procutil.py
@@ -112,9 +112,6 @@ 
     stdout = sys.stdout
     stderr = sys.stderr
 
-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.
@@ -124,6 +121,8 @@ 
         # The standard library doesn't offer line-buffered binary streams.
         stdout = make_line_buffered(stdout)
     elif pycompat.iswindows:
+        # Work around size limit when writing to console.
+        stdout = platform.winstdout(stdout)
         # Python 2 uses the I/O streams provided by the C library.
         # The Windows C runtime library doesn't support line buffering.
         stdout = make_line_buffered(stdout)