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

Re: [PATCH] RFC: help.autocorrect prompt

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Sep 6, 2010, 02:59 UTC
Message-ID
<20100906025949.GA23594@burratino>
In-Reply-To
<1283740106-11411-1-git-send-email-david.barr@cordelta.com>
(+cc: Dscho and Heiko)
David Barr wrote:
> A value of 'prompt' causes git to wait for confirmation
> before executing the assumed command.
Nice idea.
> ---
Sign-off?
Show 13 quoted lines
> --- a/help.c
> +++ b/help.c
> @@ -267,8 +267,12 @@ static struct cmdnames aliases;
>  
>  static int git_unknown_cmd_config(const char *var, const char *value, void *cb)
>  {
> -	if (!strcmp(var, "help.autocorrect"))
> -		autocorrect = git_config_int(var,value);
> +	if (!strcmp(var, "help.autocorrect")) {
> +		if (!strcmp(value, "prompt"))
> +			autocorrect = INT_MAX;
> +		else
> +			autocorrect = git_config_int(var,value);

Any particular significance to INT_MAX rather than, e.g., -1 here? (Just curious; it seems unlikely someone would use INT_MAX and accidentally trip on this.)

Not a problem introduced by your patch: should we be checking for out-of-range (e.g., negative) values?

Show 8 quoted lines
> @@ -342,7 +346,10 @@ const char *help_unknown_cmd(const char *cmd)
>  			"which does not exist.\n"
>  			"Continuing under the assumption that you meant '%s'\n",
>  			cmd, assumed);
> -		if (autocorrect > 0) {
> +		if (autocorrect == INT_MAX) {
> +			if (strcmp("y", git_getpass("Continue? (y/n) ")))
> +				exit(1);
Funny. :)

It might be better to actually always write this prompt to the terminal, rather than popping up a gui $GIT_ASKPASS if the user has set that up. Maybe something like Heiko Voigt's "mingw: make failures to unlike or move raise a question" (9229029, 2010-02-21 from 4msysgit.git):

	if (!isatty(STDIN_FILENO) || !isatty(STDERR_FILENO))
		exit(1);
	fprintf(stderr, "Continue? (y/n) ");
	if (!fgets(answer, sizeof(answer), stdin))
		exit(1)
	if (*answer != 'y' && *answer != 'Y')
		exit(1);
> +		} else if (autocorrect > 0) {
>  			fprintf(stderr, "in %0.1f seconds automatically...\n",
>  				(float)autocorrect/10.0);
>  			poll(NULL, 0, autocorrect * 100);

Thanks for a pleasant read. Jonathan

Previous: David BarrNext: David Barr
Message 2 of 4 in “RFC: help.autocorrect prompt”
  1. RFC: help.autocorrect promptDavid Barr, Sep 6, 2010
  2. Jonathan NiederSep 6, 2010
  3. David BarrSep 6, 2010
  4. help.autocorrect promptDavid Barr, Sep 6, 2010

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.