[PATCH 3 of 6 v2] util: always force line buffered stdout when stdout is a tty (BC)

Yuya Nishihara yuya at tcha.org
Fri Feb 3 08:54:37 EST 2017


On Thu, 2 Feb 2017 11:18:57 -0800, Simon Farnsworth wrote:
> # HG changeset patch
> # User Simon Farnsworth <simonfar at fb.com>
> # Date 1486063056 28800
> #      Thu Feb 02 11:17:36 2017 -0800
> # Node ID 722c309600ed9596a02674b04cb2caa9a65e8918
> # Parent  12d0ac224bb34691d44a2cead5b9795a6cfc2490
> util: always force line buffered stdout when stdout is a tty (BC)
> 
> pager replaced stdout with a line buffered version to work around glibc
> deciding on a buffering strategy on the first write to stdout. This is going
> to make my next patch hard, as replacing stdout will make tracking time
> spent blocked on it more challenging.
> 
> Move the line buffering requirement to util.py, and remove it from pager.
> This means that the abuse of ui.formatted=True and pager set to cat or equivalent
> no longer results in a line-buffered output to a pipe, hence (BC), although
> I don't expect anyone to be affected

Sounds okay. A few nits follow.

> --- a/mercurial/util.py
> +++ b/mercurial/util.py
> @@ -69,6 +69,12 @@
>  else:
>      from . import posix as platform
>  
> +# 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 stdout.isatty():

stdout might be replaced with a file-like object. Can we use util.isatty() ?

> +    stdout = os.fdopen(stdout.fileno(), 'wb', 1)

Perhaps this should be done before stdout is wrapped by winstdout().


More information about the Mercurial-devel mailing list