[PATCH 6 of 6] procutil: make stdout line-buffered on Windows if connected to TTY

Yuya Nishihara yuya at tcha.org
Mon Jul 6 11:26:28 UTC 2020


On Sun, 05 Jul 2020 04:51:42 +0200, Manuel Jacob wrote:
> # HG changeset patch
> # User Manuel Jacob <me at manueljacob.de>
> # Date 1593855699 -7200
> #      Sat Jul 04 11:41:39 2020 +0200
> # Node ID f330f7c409a975aa8dfad6161d798192ac801ef7
> # Parent  7fb9114235241b6d4354b22e2ba08138bde58642
> # EXP-Topic stdio
> 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.
> 
> diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
> --- a/mercurial/utils/procutil.py
> +++ b/mercurial/utils/procutil.py
> @@ -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):

Not directly related to this patch, but NUL device is a tty on Windows. :)

https://stackoverflow.com/q/3648711

The patch itself looks good to me.



More information about the Mercurial-devel mailing list