Skip to content

Commit 556e680

Browse files
Chandra Pratapgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 564d025 commit 556e680

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

Documentation/git.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,13 +724,12 @@ for further details.
724724
waiting for someone with sufficient permissions to fix it.
725725

726726
`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
729728
as 'git blame' (in incremental mode), 'git rev-list', 'git log',
730729
'git check-attr' and 'git check-ignore' will
731730
force a flush of the output stream after each record have been
732731
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
734733
using completely buffered I/O. If this environment variable is
735734
not set, Git will choose buffered or record-oriented flushing
736735
based on whether stdout appears to be redirected to a file or not.

write-or-die.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,17 @@
1919
void maybe_flush_or_die(FILE *f, const char *desc)
2020
{
2121
static int skip_stdout_flush = -1;
22-
struct stat st;
23-
char *cp;
2422

2523
if (f == stdout) {
2624
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+
}
3633
}
3734
if (skip_stdout_flush && !ferror(f))
3835
return;

0 commit comments

Comments
 (0)