write-or-die: fix the polarity of GIT_FLUSH environment variable

When GIT_FLUSH is set to 1, true, on, yes, then we should disable skip_stdout_flush, but the conversion somehow did the opposite. With the understanding of the original motivation behind "skip" in 06f59e9f (Don't fflush(stdout) when it's not helpful, 2007-06-29), we can sympathize with the current naming (we wanted to avoid useless flushing of stdout by default, with an escape hatch to always flush), but it is still not a good excuse. Retire the "skip_stdout_flush" variable and replace it with "flush_stdout" that tells if we do or do not want to run fflush(). Reported-by: Xiaoguang WANG <wxiaoguang@gmail.com> Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Feb 13, 2024 at 11:48 UTC b40ba17e44cd2614d2f422a0225f6db49ca694a8
1 file changed +8 -8
write-or-die.c
+8 -8
@@ -18,20 +18,20 @@
18 */
19 void maybe_flush_or_die(FILE *f, const char *desc)
20 {
21 - static int skip_stdout_flush = -1;
22 -
21 if (f == stdout) {
24 - if (skip_stdout_flush < 0) {
25 - skip_stdout_flush = git_env_bool("GIT_FLUSH", -1);
26 - if (skip_stdout_flush < 0) {
22 + static int force_flush_stdout = -1;
23 +
24 + if (force_flush_stdout < 0) {
25 + force_flush_stdout = git_env_bool("GIT_FLUSH", -1);
26 + if (force_flush_stdout < 0) {
27 struct stat st;
28 if (fstat(fileno(stdout), &st))
29 - skip_stdout_flush = 0;
29 + force_flush_stdout = 1;
30 else
31 - skip_stdout_flush = S_ISREG(st.st_mode);
31 + force_flush_stdout = !S_ISREG(st.st_mode);
32 }
33 }
34 - if (skip_stdout_flush && !ferror(f))
34 + if (!force_flush_stdout && !ferror(f))
35 return;
36 }
37 if (fflush(f)) {