Skip to content

Commit 17539c0

Browse files
nalladscho
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 e2b552d commit 17539c0

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
@@ -574,6 +574,7 @@ static int *list_and_choose(struct menu_opts *opts, struct menu_stuff *stuff)
574574
clean_get_color(CLEAN_COLOR_RESET));
575575
}
576576

577+
fflush(stdout);
577578
if (strbuf_getline(&choice, stdin, '\n') != EOF) {
578579
strbuf_trim(&choice);
579580
} else {
@@ -656,6 +657,7 @@ static int filter_by_patterns_cmd(void)
656657
clean_print_color(CLEAN_COLOR_PROMPT);
657658
printf(_("Input ignore patterns>> "));
658659
clean_print_color(CLEAN_COLOR_RESET);
660+
fflush(stdout);
659661
if (strbuf_getline(&confirm, stdin, '\n') != EOF)
660662
strbuf_trim(&confirm);
661663
else
@@ -754,6 +756,7 @@ static int ask_each_cmd(void)
754756
qname = quote_path_relative(item->string, NULL, &buf);
755757
/* TRANSLATORS: Make sure to keep [y/N] as is */
756758
printf(_("Remove %s [y/N]? "), qname);
759+
fflush(stdout);
757760
if (strbuf_getline(&confirm, stdin, '\n') != EOF) {
758761
strbuf_trim(&confirm);
759762
} else {

0 commit comments

Comments
 (0)