diff options
author | Chandra Pratap <chandrapratap3519@gmail.com> | 2024-01-04 13:20:17 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-01-04 21:32:21 +0300 |
commit | 556e68032f8248c831e48207e5cb923c9fe0e42c (patch) | |
tree | 89003bcf47137e48f500210811d20594ed99338e /write-or-die.c | |
parent | 564d0252ca632e0264ed670534a51d18a689ef5d (diff) |
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>
Diffstat (limited to 'write-or-die.c')
-rw-r--r-- | write-or-die.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/write-or-die.c b/write-or-die.c index 42a2dc73cd..3942152865 100644 --- a/write-or-die.c +++ b/write-or-die.c @@ -19,20 +19,17 @@ void maybe_flush_or_die(FILE *f, const char *desc) { static int skip_stdout_flush = -1; - struct stat st; - char *cp; if (f == stdout) { if (skip_stdout_flush < 0) { - /* NEEDSWORK: make this a normal Boolean */ - cp = getenv("GIT_FLUSH"); - if (cp) - skip_stdout_flush = (atoi(cp) == 0); - else if ((fstat(fileno(stdout), &st) == 0) && - S_ISREG(st.st_mode)) - skip_stdout_flush = 1; - else - skip_stdout_flush = 0; + skip_stdout_flush = git_env_bool("GIT_FLUSH", -1); + if (skip_stdout_flush < 0) { + struct stat st; + if (fstat(fileno(stdout), &st)) + skip_stdout_flush = 0; + else + skip_stdout_flush = S_ISREG(st.st_mode); + } } if (skip_stdout_flush && !ferror(f)) return; |