[PATCH 1 of 5] pager: stdout is line buffered by default

Yuya Nishihara yuya at tcha.org
Fri Jan 20 07:56:48 EST 2017


On Thu, 19 Jan 2017 11:02:07 -0800, Simon Farnsworth wrote:
> # HG changeset patch
> # User Simon Farnsworth <simonfar at fb.com>
> # Date 1484835774 28800
> #      Thu Jan 19 06:22:54 2017 -0800
> # Node ID 76123ae2e0ccaa58db3d4fc26b75b7251e13ad16
> # Parent  036c37bd3ec189480647ff568cee9e0b43a5bc81
> pager: stdout is line buffered by default
> 
> pager only starts when ui.formatted() is true. In normal operation,
> when ui.formatted() is true, stdout is line buffered anyway.

Unfortunately that isn't always true. The buffering mode of FILE object is
decided on the first fwrite() (or perhaps fflush()) as far as on glibc. We
generally attach the pager fd before writing anything, which makes the stdout
fully-buffered.

> The code here doesn't actually do what the commit message in changeset
> 62c5e937 claims it will do; sys.stdout is not yet pager.stdin when we
> reopen, so we affect the original sys.stdout's buffering mode. It's the dup2
> that puts pager.stdin's fd into sys.stdout's fd, and that doesn't affect
> buffering.

No. AFAIK, the buffering mode is defined per FILE object, not per file
descriptor.


More information about the Mercurial-devel mailing list