From: Junio C Hamano Date: Fri, 29 Jun 2007 07:07:03 GMT Subject: Re: [PATCH] Don't fflush(stdout) when it's not helpful Message-ID: <7vmyyjgrxk.fsf@assigned-by-dhcp.pobox.com> In-Reply-To: <20070629063819.GA23138@coredump.intra.peff.net> Jeff King writes: > On Thu, Jun 28, 2007 at 11:48:38PM -0400, Theodore Tso wrote: > >> +void maybe_flush_or_die(FILE *f, const char *desc) >> +{ >> + static int stdout_is_file = -1; >> + struct stat st; >> + char *cp; >> + >> + if (f == stdout) { >> + if (stdout_is_file < 0) { >> + cp = getenv("GIT_FLUSH"); >> + if (cp) >> + stdout_is_file = (atoi(cp) == 0); >> + else if ((fstat(fileno(stdout), &st) == 0) && >> + S_ISREG(st.st_mode)) >> + stdout_is_file = 1; >> ... > > Looks much better to me, but I have one minor nit: stdout_is_file is a > poor name,... Thanks for bringing it up, as I had the same "Huh?" moment. I would probably call that simply "do_not_flush". Or name the variable "flush_stdout" and swap all the logic. if (f == stdout) { if (flush_stdout < 0) { cp = getenv("GIT_FLUSH_STDOUT"); if (cp) flush_stdout = !!atoi(cp); else if ((fstat(fileno(stdout), &st) == 0) && !S_ISREG(st.st_mode)) flush_stdout = 0; else flush_stdout = 1; } if (!flush_stdout) return; }