git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Drew DeVault <sir@cmpwn.com>
Cc: git@vger.kernel.org, lanodan <contact+git@hacktivis.me>
Subject: Re: [PATCH v2] help.c: configurable suggestions
Date: Tue, 17 Nov 2020 12:04:15 -0800	[thread overview]
Message-ID: <xmqqd00b698g.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <20201117152535.9795-1-sir@cmpwn.com> (Drew DeVault's message of "Tue, 17 Nov 2020 10:25:35 -0500")

Drew DeVault <sir@cmpwn.com> writes:

> This allows users to disable guessing the commands or options that they
> meant to use.
> ---

Missing sign-off.

>  Documentation/config/help.txt | 14 +++++++-------
>  help.c                        | 27 ++++++++++++++++++++++-----
>  2 files changed, 29 insertions(+), 12 deletions(-)
>
> diff --git a/Documentation/config/help.txt b/Documentation/config/help.txt
> index 224bbf5a28..99d1e33750 100644
> --- a/Documentation/config/help.txt
> +++ b/Documentation/config/help.txt
> @@ -8,13 +8,13 @@ help.format::
>  	the default. 'web' and 'html' are the same.
>  
>  help.autoCorrect::
> -	Automatically correct and execute mistyped commands after
> -	waiting for the given number of deciseconds (0.1 sec). If more
> -	than one command can be deduced from the entered text, nothing
> -	will be executed.  If the value of this option is negative,
> -	the corrected command will be executed immediately. If the
> -	value is 0 - the command will be just shown but not executed.
> -	This is the default.
> +	If git detects typos and can identify exactly one valid command similar
> +	to the error, git will automatically run the intended command after
> +	waiting a duration of time defined by this configuration value in
> +	deciseconds (0.1 sec). If this value is 0, the suggested corrections
> +	will be shown, but not executed. If -1, the suggested command is run
> +	immediately. If -2, suggestions are not shown at all. The default value
> +	is zero.

This changes behaviour for those who have relied on our promise that
any negative value means immediate execution.  Now -2 means a totally
different thing.

I thought I already showed you how to make it a "number or keyword"
in my previous review comment to avoid such a needless behaviour
change---did our mails cross?

Thanks.

>  help.htmlPath::
>  	Specify the path where the HTML documentation resides. File system paths
> diff --git a/help.c b/help.c
> index 919cbb9206..2fd27cffb0 100644
> --- a/help.c
> +++ b/help.c
> @@ -472,12 +472,18 @@ int is_in_cmdlist(struct cmdnames *c, const char *s)
>  static int autocorrect;
>  static struct cmdnames aliases;
>  
> +#define AUTOCORRECT_NEVER (-2)
> +#define AUTOCORRECT_IMMEDIATELY (-1)
> +
>  static int git_unknown_cmd_config(const char *var, const char *value, void *cb)
>  {
>  	const char *p;
>  
> -	if (!strcmp(var, "help.autocorrect"))
> -		autocorrect = git_config_int(var,value);
> +	if (!strcasecmp(var, "help.autocorrect")) {
> +		if (!value)
> +			return config_error_nonbool(var);
> +		autocorrect = git_config_int(var, value);
> +	}
>  	/* Also use aliases for command lookup */
>  	if (skip_prefix(var, "alias.", &p))
>  		add_cmdname(&aliases, p, strlen(p));
> @@ -525,6 +531,11 @@ const char *help_unknown_cmd(const char *cmd)
>  
>  	read_early_config(git_unknown_cmd_config, NULL);
>  
> +	if (autocorrect == AUTOCORRECT_NEVER) {
> +		fprintf_ln(stderr, _("git: '%s' is not a git command. See 'git --help'."), cmd);
> +		exit(1);
> +	}
> +
>  	load_command_list("git-", &main_cmds, &other_cmds);
>  
>  	add_cmd_list(&main_cmds, &aliases);
> @@ -586,7 +597,7 @@ const char *help_unknown_cmd(const char *cmd)
>  		     n++)
>  			; /* still counting */
>  	}
> -	if (autocorrect && n == 1 && SIMILAR_ENOUGH(best_similarity)) {
> +	if (autocorrect != 0 && n == 1 && SIMILAR_ENOUGH(best_similarity)) {

I see there is nothing gained by writing "!= 0" explicitly here.


  reply	other threads:[~2020-11-17 20:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-17 15:25 Drew DeVault
2020-11-17 20:04 ` Junio C Hamano [this message]
2020-11-17 20:05   ` Drew DeVault
2020-11-17 21:25 ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqd00b698g.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=contact+git@hacktivis.me \
    --cc=git@vger.kernel.org \
    --cc=sir@cmpwn.com \
    --subject='Re: [PATCH v2] help.c: configurable suggestions' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).