[PATCH v3] util: always force line buffered stdout when stdout is a tty (BC)

Yuya Nishihara yuya at tcha.org
Sun Feb 5 00:37:21 EST 2017


On Fri, 3 Feb 2017 15:15:06 -0800, Simon Farnsworth wrote:
> # HG changeset patch
> # User Simon Farnsworth <simonfar at fb.com>
> # Date 1486163427 28800
> #      Fri Feb 03 15:10:27 2017 -0800
> # Node ID 08b6e1bb20ca6bd1465a3d22bab49debfe776bae
> # Parent  1f51b4658f21bbb797e922d155c1046eddccf91d
> util: always force line buffered stdout when stdout is a tty (BC)

Queued, thanks.

> diff --git a/mercurial/util.py b/mercurial/util.py
> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -63,6 +63,18 @@
>  urlreq = pycompat.urlreq
>  xmlrpclib = pycompat.xmlrpclib
>  
> +def isatty(fp):
> +    try:
> +        return fp.isatty()
> +    except AttributeError:
> +        return False
> +
> +# 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
> +if isatty(stdout):
> +    stdout = os.fdopen(stdout.fileno(), 'wb', 1)
> +
>  if pycompat.osname == 'nt':
>      from . import windows as platform
>      stdout = platform.winstdout(pycompat.stdout)

Fixed this in flight (otherwise stdout would be closed by GC):

 if pycompat.osname == 'nt':
     from . import windows as platform
-    stdout = platform.winstdout(pycompat.stdout)
+    stdout = platform.winstdout(stdout)


More information about the Mercurial-devel mailing list