write-or-die: make GIT_FLUSH a Boolean environment variable

Among Git's environment variables, the ones marked as "Boolean" accept values in a way similar to Boolean configuration variables, i.e. values like 'yes', 'on', 'true' and positive numbers are taken as "on" and values like 'no', 'off', 'false' are taken as "off". GIT_FLUSH can be used to force Git to use non-buffered I/O when writing to stdout. It can only accept two values, '1' which causes Git to flush more often and '0' which makes all output buffered. Make GIT_FLUSH accept more values besides '0' and '1' by turning it into a Boolean environment variable, modifying the required logic. Update the related documentation. Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Chandra Pratap committed Jan 4, 2024 at 10:20 UTC 556e68032f8248c831e48207e5cb923c9fe0e42c
2 files changed +10 -14
Documentation/git.txt
+2 -3
@@ -724,13 +724,12 @@ for further details.
724 waiting for someone with sufficient permissions to fix it.
725
726 `GIT_FLUSH`::
727 -// NEEDSWORK: make it into a usual Boolean environment variable
728 - If this environment variable is set to "1", then commands such
727 + If this Boolean environment variable is set to true, then commands such
728 as 'git blame' (in incremental mode), 'git rev-list', 'git log',
729 'git check-attr' and 'git check-ignore' will
730 force a flush of the output stream after each record have been
731 flushed. If this
733 - variable is set to "0", the output of these commands will be done
732 + variable is set to false, the output of these commands will be done
733 using completely buffered I/O. If this environment variable is
734 not set, Git will choose buffered or record-oriented flushing
735 based on whether stdout appears to be redirected to a file or not.
write-or-die.c
+8 -11
@@ -19,20 +19,17 @@
19 void maybe_flush_or_die(FILE *f, const char *desc)
20 {
21 static int skip_stdout_flush = -1;
22 - struct stat st;
23 - char *cp;
22
23 if (f == stdout) {
24 if (skip_stdout_flush < 0) {
27 - /* NEEDSWORK: make this a normal Boolean */
28 - cp = getenv("GIT_FLUSH");
29 - if (cp)
30 - skip_stdout_flush = (atoi(cp) == 0);
31 - else if ((fstat(fileno(stdout), &st) == 0) &&
32 - S_ISREG(st.st_mode))
33 - skip_stdout_flush = 1;
34 - else
35 - skip_stdout_flush = 0;
25 + skip_stdout_flush = git_env_bool("GIT_FLUSH", -1);
26 + if (skip_stdout_flush < 0) {
27 + struct stat st;
28 + if (fstat(fileno(stdout), &st))
29 + skip_stdout_flush = 0;
30 + else
31 + skip_stdout_flush = S_ISREG(st.st_mode);
32 + }
33 }
34 if (skip_stdout_flush && !ferror(f))
35 return;