Skip to content

Commit

Permalink
write-or-die: make GIT_FLUSH a Boolean environment variable
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Chandra Pratap authored and gitster committed Jan 4, 2024
1 parent 564d025 commit 556e680
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
5 changes: 2 additions & 3 deletions Documentation/git.txt
Original file line number Diff line number Diff line change
Expand Up @@ -724,13 +724,12 @@ for further details.
waiting for someone with sufficient permissions to fix it.

`GIT_FLUSH`::
// NEEDSWORK: make it into a usual Boolean environment variable
If this environment variable is set to "1", then commands such
If this Boolean environment variable is set to true, then commands such
as 'git blame' (in incremental mode), 'git rev-list', 'git log',
'git check-attr' and 'git check-ignore' will
force a flush of the output stream after each record have been
flushed. If this
variable is set to "0", the output of these commands will be done
variable is set to false, the output of these commands will be done
using completely buffered I/O. If this environment variable is
not set, Git will choose buffered or record-oriented flushing
based on whether stdout appears to be redirected to a file or not.
Expand Down
19 changes: 8 additions & 11 deletions write-or-die.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 556e680

Please sign in to comment.