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

Re: [PATCH v2 2/2] Explicitly `fflush` stdout before expecting interactive input

From
Derrick Stolee <stolee@gmail.com>
Date
Apr 10, 2020, 12:28 UTC
Message-ID
<5350e8fd-2ca6-7c07-497b-1bb35bb07c84@gmail.com>
In-Reply-To
<d3949e42004f31e8741fad08352f782b4b8536eb.1586518072.git.gitgitgadget@gmail.com>
On 4/10/2020 7:27 AM, 마누엘 via GitGitGadget wrote:
Show 30 quoted lines
> From: =?UTF-8?q?=EB=A7=88=EB=88=84=EC=97=98?= <nalla@hamal.uberspace.de>
> 
> At least one interactive command writes a prompt to `stdout` and then
> reads user input on `stdin`: `git clean --interactive`. If the prompt is
> left in the buffer, the user will not realize the program is waiting for
> their input.
> 
> So let's just flush `stdout` before reading the user's input.
> 
> Signed-off-by: 마누엘 <nalla@hamal.uberspace.de>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>  prompt.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/prompt.c b/prompt.c
> index 098dcfb7cf9..5ded21a017f 100644
> --- a/prompt.c
> +++ b/prompt.c
> @@ -77,8 +77,10 @@ char *git_prompt(const char *prompt, int flags)
>  
>  int git_read_line_interactively(struct strbuf *line)
>  {
> -	int ret = strbuf_getline_lf(line, stdin);
> +	int ret;
>  
> +	fflush(stdout);
> +	ret = strbuf_getline_lf(line, stdin);
>  	if (ret != EOF)
>  		strbuf_trim_trailing_newline(line);
Nice and "clean" ;)

LGTM -Stolee

Previous: 마누엘 via GitGitGadgetNext: Johannes Schindelin via GitGitGadget
Message 13 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.