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 v4] help.c: expand options for help.autocorrect
Date: Wed, 18 Nov 2020 10:02:29 -0800	[thread overview]
Message-ID: <xmqq1rgq35my.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <20201118172849.24715-1-sir@cmpwn.com> (Drew DeVault's message of "Wed, 18 Nov 2020 12:28:49 -0500")

Drew DeVault <sir@cmpwn.com> writes:

> Some users would prefer to never suggest corrections at all.

Here is how I would have phrased it.

Key points:

 - The log message starts with the description of the current state
   of the system and introduces the problem the patch tries to
   solve.

 - Then gives orders to the codebase to "be like so"

 - The addition of "never" is the primary change to solve the stated
   problem.  "immediate" is not the essential part but is merely
   adding a synonym while we are in the vicinity.

Thanks.


--- >8 ------ >8 ------ >8 --- cut here --- >8 ------ >8 ------ >8 ---
Subject: [PATCH] help.c: allow help.autocorrect to say "do not even compute  suggestions"

While help.autocorrect can be set to 0 to decline auto-execution of
possibly mistyped commands, it still spends cycles to compute the
suggestions, and it wastes screen real estate.

Update help.autocorrect to accept the string "never" to just exit
with error upon mistyped commands to help users who prefer to never
see suggested corrections at all.

While at it, introduce "immediate" as a more readable way to
immediately execute the auto-corrected command, which can be done
with negative value.

Signed-off-by: Drew DeVault <sir@cmpwn.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
Range-diff:
1:  036b766035 ! 1:  cfe85a6e16 help.c: expand options for help.autocorrect
    @@ Metadata
     Author: Drew DeVault <sir@cmpwn.com>
     
      ## Commit message ##
    -    help.c: expand options for help.autocorrect
    +    help.c: allow help.autocorrect to say "do not even compute suggestions"
     
    -    Some users would prefer to never suggest corrections at all. This
    -    updates help.autocorrect to accept the strings "immediate" and "never",
    -    the former assuming the prior behavior of negative values for
    -    autocorrect, and the latter skipping auto-correction entirely.
    +    While help.autocorrect can be set to 0 to decline auto-execution of
    +    possibly mistyped commands, it still spends cycles to compute the
    +    suggestions, and it wastes screen real estates.
    +
    +    Update help.autocorrect to accept the string "never" to just exit
    +    with error upon mistyped commands to help users who prefer to never
    +    see suggested corrections at all.
    +
    +    While at it, introduce "immediate" as a more readable way to
    +    immediately execute the auto-corrected command, which can be done
    +    with negative value.
     
         Signed-off-by: Drew DeVault <sir@cmpwn.com>
         Signed-off-by: Junio C Hamano <gitster@pobox.com>
    @@ Documentation/config/help.txt: help.format::
     +	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 "immediate", the suggested command
    ++	will be shown, but not executed. If it is a negative integer, or
    ++	"immediate", the suggested command
     +	is run immediately. If "never", suggestions are not shown at all. The
     +	default value is zero.
    -++
    -+Negative integers are interpreted as "immediately" for historical reasons.
      
      help.htmlPath::
      	Specify the path where the HTML documentation resides. File system paths

 Documentation/config/help.txt | 15 ++++++++-------
 help.c                        | 25 ++++++++++++++++++++++---
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/Documentation/config/help.txt b/Documentation/config/help.txt
index 224bbf5a28..783a90a0f9 100644
--- a/Documentation/config/help.txt
+++ b/Documentation/config/help.txt
@@ -8,13 +8,14 @@ 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 it is a negative integer, or
+	"immediate", the suggested command
+	is run immediately. If "never", suggestions are not shown at all. The
+	default value is zero.
 
 help.htmlPath::
 	Specify the path where the HTML documentation resides. File system paths
diff --git a/help.c b/help.c
index 919cbb9206..3c3bdec213 100644
--- a/help.c
+++ b/help.c
@@ -472,12 +472,26 @@ 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 (!strcmp(var, "help.autocorrect")) {
+		if (!value)
+			return config_error_nonbool(var);
+		if (!strcmp(value, "never")) {
+			autocorrect = AUTOCORRECT_NEVER;
+		} else if (!strcmp(value, "immediate")) {
+			autocorrect = AUTOCORRECT_IMMEDIATELY;
+		} else {
+			int v = git_config_int(var, value);
+			autocorrect = (v < 0)
+				? AUTOCORRECT_IMMEDIATELY : v;
+		}
+	}
 	/* Also use aliases for command lookup */
 	if (skip_prefix(var, "alias.", &p))
 		add_cmdname(&aliases, p, strlen(p));
@@ -525,6 +539,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);
@@ -594,7 +613,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'."),
-- 
2.29.2-461-g858fb5bde9


  reply	other threads:[~2020-11-18 18:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-18 17:28 [PATCH v4] help.c: expand options for help.autocorrect Drew DeVault
2020-11-18 18:02 ` Junio C Hamano [this message]
2020-11-18 18:15   ` Junio C Hamano
2020-11-25 18:33     ` SZEDER Gábor
2020-11-25 20:49       ` 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=xmqq1rgq35my.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).