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

[PATCH] clean: explicitly `fflush` stdout

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Apr 8, 2020, 19:33 UTC
Message-ID
<pull.755.git.git.1586374380709.gitgitgadget@gmail.com>
From: =?UTF-8?q?=EB=A7=88=EB=88=84=EC=97=98?= <nalla@hamal.uberspace.de>

For performance reasons `stdout` is buffered by default. That leads to problems if after printing to `stdout` a read on `stdin` is performed.

For that reason interactive commands like `git clean -i` do not function properly anymore if the `stdout` is not flushed by `fflush(stdout)` before trying to read from `stdin`.

So let's precede all reads on `stdin` in `git clean -i` by flushing `stdout`.

Signed-off-by: 마누엘 <nalla@hamal.uberspace.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
    Explicitly fflush stdout in git clean
    
    This is yet another patch that was funneled through a Git for Windows
    PR. It has served us well for almost five years now, and it is beyond
    time that it find its final home in core Git.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-755%2Fdscho%2Ffflush-in-git-clean-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-755/dscho/fflush-in-git-clean-v1
Pull-Request: https://github.com/git/git/pull/755
 builtin/clean.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/builtin/clean.c b/builtin/clean.c
index 5abf087e7c4..2bd06d13395 100644
--- a/builtin/clean.c
+++ b/builtin/clean.c
@@ -580,6 +580,7 @@ static int *list_and_choose(struct menu_opts *opts, struct menu_stuff *stuff)
 			       clean_get_color(CLEAN_COLOR_RESET));
 		}
 
+		fflush(stdout);
 		if (strbuf_getline_lf(&choice, stdin) != EOF) {
 			strbuf_trim(&choice);
 		} else {
@@ -662,6 +663,7 @@ static int filter_by_patterns_cmd(void)
 		clean_print_color(CLEAN_COLOR_PROMPT);
 		printf(_("Input ignore patterns>> "));
 		clean_print_color(CLEAN_COLOR_RESET);
+		fflush(stdout);
 		if (strbuf_getline_lf(&confirm, stdin) != EOF)
 			strbuf_trim(&confirm);
 		else
@@ -760,6 +762,7 @@ static int ask_each_cmd(void)
 			qname = quote_path_relative(item->string, NULL, &buf);
 			/* TRANSLATORS: Make sure to keep [y/N] as is */
 			printf(_("Remove %s [y/N]? "), qname);
+			fflush(stdout);
 			if (strbuf_getline_lf(&confirm, stdin) != EOF) {
 				strbuf_trim(&confirm);
 			} else {

base-commit: 9fadedd637b312089337d73c3ed8447e9f0aa775
-- 
gitgitgadget
Next: Jeff King
Message 1 of 16 in “clean: explicitly `fflush` stdout”
  1. clean: explicitly `fflush` stdoutJohannes Schindelin via GitGitGadget, Apr 8, 2020
  2. Jeff KingApr 8, 2020
  3. Junio C HamanoApr 8, 2020
  4. Jeff KingApr 8, 2020
  5. Johannes SchindelinApr 10, 2020
  6. 0/2 Explicitly fflush stdout in git cleanJohannes Schindelin via GitGitGadget, Apr 10, 2020
  7. 1/2 Refactor code asking the user for input interactivelyJohannes Schindelin via GitGitGadget, Apr 10, 2020
  8. Derrick StoleeApr 10, 2020
  9. Johannes SchindelinApr 10, 2020
  10. Jeff KingApr 10, 2020
  11. Junio C HamanoApr 10, 2020
  12. 2/2 Explicitly `fflush` stdout before expecting interactive input마누엘 via GitGitGadget, Apr 10, 2020
  13. Derrick StoleeApr 10, 2020
  14. 0/2 Explicitly fflush stdout in git cleanJohannes Schindelin via GitGitGadget, Apr 10, 2020
  15. 1/2 Refactor code asking the user for input interactivelyJohannes Schindelin via GitGitGadget, Apr 10, 2020
  16. 2/2 Explicitly `fflush` stdout before expecting interactive input마누엘 via GitGitGadget, Apr 10, 2020

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.