git@vger.kernel.org mailing list mirror (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] help.c: add advice.correctTypos option
Date: Mon, 16 Nov 2020 15:41:46 -0800	[thread overview]
Message-ID: <xmqqlff07ttx.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <20201116185521.2276-1-sir@cmpwn.com> (Drew DeVault's message of "Mon, 16 Nov 2020 13:55:21 -0500")

Drew DeVault <sir@cmpwn.com> writes:

> This allows users to disable guessing the commands or options that they
> meant to use.
> ---
> Questions:
>
> - Is advice.* the right namespace?
> - How should this interact with help.autocorrect?

If you are declining help.autocorrect altogether, do you need to
still invent a new and separate configuration variable?  Isn't a new
value (e.g. 'never') given to help.autocorrect sufficient?

Something along this line (not even compile tested though)?

 help.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git c/help.c w/help.c
index 4fb93d5560..06f86152a6 100644
--- c/help.c
+++ w/help.c
@@ -469,6 +469,8 @@ int is_in_cmdlist(struct cmdnames *c, const char *s)
 	return 0;
 }
 
+#define AUTOCORRECT_NEVER (-2)
+#define AUTOCORRECT_IMMEDIATELY (-1)
 static int autocorrect;
 static struct cmdnames aliases;
 
@@ -476,8 +478,19 @@ 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 (!strcmp(var, "help.autocorrect")) {
+		if (!value)
+			return config_error_nonbool(var);
+		if (!strcmp(value, "never"))
+			autocorrect = AUTOCORRECT_NEVER;
+		else {
+			int v = git_config_int(var,value);
+			if (v < 0)
+				autocorrect = AUTOCORRECT_IMMEDIATELY;
+			else
+				autocorrect = v;
+		}
+	}
 	/* Also use aliases for command lookup */
 	if (skip_prefix(var, "alias.", &p))
 		add_cmdname(&aliases, p, strlen(p));
@@ -519,6 +532,9 @@ const char *help_unknown_cmd(const char *cmd)
 	struct cmdnames main_cmds, other_cmds;
 	struct cmdname_help *common_cmds;
 
+	if (autocorrect == AUTOCORRECT_NEVER)
+		exit(1);
+
 	memset(&main_cmds, 0, sizeof(main_cmds));
 	memset(&other_cmds, 0, sizeof(other_cmds));
 	memset(&aliases, 0, sizeof(aliases));
@@ -594,7 +610,7 @@ const char *help_unknown_cmd(const char *cmd)
 			   _("WARNING: You called a Git command named '%s', "
 			     "which does not exist."),
 			   cmd);
-		if (autocorrect < 0)
+		if (autocorrect == AUTOCORRECT_IMMEDIATELY)
 			fprintf_ln(stderr,
 				   _("Continuing under the assumption that "
 				     "you meant '%s'."),

      reply	other threads:[~2020-11-16 23:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-16 18:55 [PATCH] help.c: add advice.correctTypos option Drew DeVault
2020-11-16 23:41 ` Junio C Hamano [this message]

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=xmqqlff07ttx.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=contact+git@hacktivis.me \
    --cc=git@vger.kernel.org \
    --cc=sir@cmpwn.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public 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).