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

Re: [PATCH v2 1/2] Refactor code asking the user for input interactively

From
Derrick Stolee <stolee@gmail.com>
Date
Apr 10, 2020, 12:27 UTC
Message-ID
<cf6bdc4c-bacf-5de0-b0b3-255e66c7bc18@gmail.com>
In-Reply-To
<9d2ee78a9e414c0b6aacbc9c878ab08eb70703d5.1586518072.git.gitgitgadget@gmail.com>
On 4/10/2020 7:27 AM, Johannes Schindelin via GitGitGadget wrote:
Show 9 quoted lines
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
> 
> There are quite a few code locations (e.g. `git clean --interactive`)
> where Git asks the user for an answer. In preparation for fixing a bug
> shared by all of them, and also to DRY up the code, let's refactor it.
> 
> Please note that most of these callers trimmed white-space both at the
> beginning and at the end of the answer, instead of trimming only the
> end (as the caller in `add-patch.c` does).
add-patch also only trims the newline! This is still a good change.
> THerefore, technically speaking, we change behavior in this patch. At
Strange capitalization here.
> the same time, it can be argued that this is actually a bug fix.
> 
Show 8 quoted lines
> @@ -1158,9 +1159,8 @@ static int read_single_character(struct add_p_state *s)
>  		return res;
>  	}
>  
> -	if (strbuf_getline(&s->answer, stdin) == EOF)
> +	if (git_read_line_interactively(&s->answer) == EOF)
>  		return EOF;
> -	strbuf_trim_trailing_newline(&s->answer);
(Pointing out the trailing newline trim here.)
Show 10 quoted lines
> +
> +int git_read_line_interactively(struct strbuf *line)
> +{
> +	int ret = strbuf_getline_lf(line, stdin);
> +
> +	if (ret != EOF)
> +		strbuf_trim_trailing_newline(line);
> +
> +	return ret;
> +}

This looks good. Do we need a trailing newline or something? The way the diff ends abruptly after the "}" line made me think so.

Thanks, -Stolee

Previous: Johannes Schindelin via GitGitGadgetNext: Johannes Schindelin
Message 8 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.