git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Chandra Pratap via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Chandra Pratap <chandrapratap376@gmail.com>,
	Chandra Pratap <chandrapratap3519@gmail.com>
Subject: [PATCH v3] write-or-die: make GIT_FLUSH a Boolean environment variable
Date: Thu, 04 Jan 2024 10:20:17 +0000	[thread overview]
Message-ID: <pull.1628.v3.git.1704363617842.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1628.v2.git.1704268708720.gitgitgadget@gmail.com>

From: Chandra Pratap <chandrapratap3519@gmail.com>

Among Git's environment variable, 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>
---
    write-or-die: make GIT_FLUSH a Boolean environment variable

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1628%2FChand-ra%2Fgit_flush-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1628/Chand-ra/git_flush-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/1628

Range-diff vs v2:

 1:  585c76fff68 ! 1:  c98885c0ede write-or-die: make GIT_FLUSH a Boolean environment variable
     @@ Documentation/git.txt: for further details.
      -	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
     + 	'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
     --	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.
     -+	'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
     -+	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.
     - 
     - `GIT_TRACE`::
     - 	Enables general trace messages, e.g. alias expansion, built-in
     ++	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.
      
       ## write-or-die.c ##
     -@@ write-or-die.c: void maybe_flush_or_die(FILE *f, const char *desc)
     +@@
     + void maybe_flush_or_die(FILE *f, const char *desc)
       {
       	static int skip_stdout_flush = -1;
     - 	struct stat st;
     +-	struct stat st;
      -	char *cp;
       
       	if (f == stdout) {
     @@ write-or-die.c: void maybe_flush_or_die(FILE *f, const char *desc)
      -			if (cp)
      -				skip_stdout_flush = (atoi(cp) == 0);
      -			else if ((fstat(fileno(stdout), &st) == 0) &&
     -+			if (!git_env_bool("GIT_FLUSH", -1))
     -+				skip_stdout_flush = 1;
     -+			else if (!fstat(fileno(stdout), &st) &&
     - 				 S_ISREG(st.st_mode))
     - 				skip_stdout_flush = 1;
     - 			else
     +-				 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;


 Documentation/git.txt |  5 ++---
 write-or-die.c        | 19 ++++++++-----------
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/Documentation/git.txt b/Documentation/git.txt
index 2535a30194f..d06eea024f7 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -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.
diff --git a/write-or-die.c b/write-or-die.c
index 42a2dc73cd3..39421528653 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;

base-commit: 1a87c842ece327d03d08096395969aca5e0a6996
-- 
gitgitgadget


  parent reply	other threads:[~2024-01-04 10:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-30 16:54 [PATCH] write-or-die: make GIT_FLUSH a Boolean environment variable Chandra Pratap via GitGitGadget
2024-01-01  8:24 ` Torsten Bögershausen
2024-01-02 16:29   ` Junio C Hamano
2024-01-03  7:58 ` [PATCH v2] " Chandra Pratap via GitGitGadget
2024-01-03  8:22   ` Patrick Steinhardt
2024-01-03 17:15     ` Taylor Blau
2024-01-03 18:42       ` Torsten Bögershausen
2024-01-03 19:18         ` Junio C Hamano
2024-01-04 17:35           ` Taylor Blau
2024-01-03 17:13   ` Junio C Hamano
2024-01-04 10:20   ` Chandra Pratap via GitGitGadget [this message]
2024-01-04 17:36     ` [PATCH v3] " Taylor Blau
2024-01-04 18:35     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.1628.v3.git.1704363617842.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=chandrapratap3519@gmail.com \
    --cc=chandrapratap376@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).