git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Bug report: Incorrect GIT_FLUSH behavior in 2.43.1 (regression and breaking)

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 13, 2024, 19:48 UTC
Message-ID
<xmqqbk8k5eo0.fsf@gitster.g>
In-Reply-To
<xmqqle7o6zs8.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
> Unfortunately the minimum fix is already in 'next', so let me turn
> what you wrote into an update relative to that.  I'll assume your
> patch in the discussion is signed-off already?

Nah, my mistake. The topic still is outside 'next', so I'll replace it with the attached while queuing.

Thanks.
------- >8 ------------- >8 ------------- >8 -------
Subject: [PATCH] write-or-die: fix the polarity of GIT_FLUSH environment variable

When GIT_FLUSH is set to 1, true, on, yes, then we should disable skip_stdout_flush, but the conversion somehow did the opposite.

With the understanding of the original motivation behind "skip" in 06f59e9f (Don't fflush(stdout) when it's not helpful, 2007-06-29), we can sympathize with the current naming (we wanted to avoid useless flushing of stdout by default, with an escape hatch to always flush), but it is still not a good excuse.

Retire the "skip_stdout_flush" variable and replace it with "flush_stdout" that tells if we do or do not want to run fflush().

Reported-by: Xiaoguang WANG <wxiaoguang@gmail.com>
Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 write-or-die.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/write-or-die.c b/write-or-die.c
index 3942152865..01a9a51fa2 100644
--- a/write-or-die.c
+++ b/write-or-die.c
@@ -18,20 +18,20 @@
  */
 void maybe_flush_or_die(FILE *f, const char *desc)
 {
-	static int skip_stdout_flush = -1;
-
 	if (f == stdout) {
-		if (skip_stdout_flush < 0) {
-			skip_stdout_flush = git_env_bool("GIT_FLUSH", -1);
-			if (skip_stdout_flush < 0) {
+		static int force_flush_stdout = -1;
+
+		if (force_flush_stdout < 0) {
+			force_flush_stdout = git_env_bool("GIT_FLUSH", -1);
+			if (force_flush_stdout < 0) {
 				struct stat st;
 				if (fstat(fileno(stdout), &st))
-					skip_stdout_flush = 0;
+					force_flush_stdout = 1;
 				else
-					skip_stdout_flush = S_ISREG(st.st_mode);
+					force_flush_stdout = !S_ISREG(st.st_mode);
 			}
 		}
-		if (skip_stdout_flush && !ferror(f))
+		if (!force_flush_stdout && !ferror(f))
 			return;
 	}
 	if (fflush(f)) {
-- 
2.44.0-rc0-46-g2996f11c1d
Previous: Junio C HamanoNext: Phillip Wood
Message 6 of 7 in “Bug report: Incorrect GIT_FLUSH behavior in 2.43.1 (regression and breaking)”
  1. Xiaoguang WANGFeb 12, 2024
  2. Junio C HamanoFeb 12, 2024
  3. Xiaoguang WANGFeb 12, 2024
  4. Phillip WoodFeb 13, 2024
  5. Junio C HamanoFeb 13, 2024
  6. Junio C HamanoFeb 13, 2024
  7. Phillip WoodFeb 14, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.