Skip to content

Commit 54e944f

Browse files
nallaGit for Windows Build Agent
authored andcommitted
mingw: explicitly fflush stdout
For performance reasons `stdout` is not unbuffered 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`. In the case of `git clean -i` all reads on `stdin` were preceded by a `fflush(stdout)` call. Signed-off-by: nalla <[email protected]>
1 parent 14122e6 commit 54e944f

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

builtin/clean.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ static int *list_and_choose(struct menu_opts *opts, struct menu_stuff *stuff)
570570
clean_get_color(CLEAN_COLOR_RESET));
571571
}
572572

573+
fflush(stdout);
573574
if (strbuf_getline_lf(&choice, stdin) != EOF) {
574575
strbuf_trim(&choice);
575576
} else {
@@ -652,6 +653,7 @@ static int filter_by_patterns_cmd(void)
652653
clean_print_color(CLEAN_COLOR_PROMPT);
653654
printf(_("Input ignore patterns>> "));
654655
clean_print_color(CLEAN_COLOR_RESET);
656+
fflush(stdout);
655657
if (strbuf_getline_lf(&confirm, stdin) != EOF)
656658
strbuf_trim(&confirm);
657659
else
@@ -750,6 +752,7 @@ static int ask_each_cmd(void)
750752
qname = quote_path_relative(item->string, NULL, &buf);
751753
/* TRANSLATORS: Make sure to keep [y/N] as is */
752754
printf(_("Remove %s [y/N]? "), qname);
755+
fflush(stdout);
753756
if (strbuf_getline_lf(&confirm, stdin) != EOF) {
754757
strbuf_trim(&confirm);
755758
} else {

0 commit comments

Comments
 (0)