]> git.ipfire.org Git - thirdparty/git.git/commitdiff
write-or-die: fix the polarity of GIT_FLUSH environment variable
authorJunio C Hamano <gitster@pobox.com>
Tue, 13 Feb 2024 19:48:15 +0000 (11:48 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 13 Feb 2024 19:57:28 +0000 (11:57 -0800)
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>
write-or-die.c

index 39421528653e29cbd724153edf94d2613ea1d6b4..01a9a51fa2fcd758b32ffc8f3e75811710804754 100644 (file)
  */
 void maybe_flush_or_die(FILE *f, const char *desc)
 {
-       static int skip_stdout_flush = -1;
-
        if (f == stdout) {
-               if (skip_stdout_flush < 0) {
-                       skip_stdout_flush = git_env_bool("GIT_FLUSH", -1);
-                       if (skip_stdout_flush < 0) {
+               static int force_flush_stdout = -1;
+
+               if (force_flush_stdout < 0) {
+                       force_flush_stdout = git_env_bool("GIT_FLUSH", -1);
+                       if (force_flush_stdout < 0) {
                                struct stat st;
                                if (fstat(fileno(stdout), &st))
-                                       skip_stdout_flush = 0;
+                                       force_flush_stdout = 1;
                                else
-                                       skip_stdout_flush = S_ISREG(st.st_mode);
+                                       force_flush_stdout = !S_ISREG(st.st_mode);
                        }
                }
-               if (skip_stdout_flush && !ferror(f))
+               if (!force_flush_stdout && !ferror(f))
                        return;
        }
        if (fflush(f)) {