{"thread":{"id":"54667","subject":"[PATCH v5] help.c: expand options for help.autocorrect","startedAt":"2020-11-18T17:50:57Z","lastAt":"2020-11-18T17:50:57Z","messageCount":1,"participants":["Drew DeVault"],"isPatch":true,"patchVersion":5,"patchTotal":null},"messages":[{"id":"410248","messageId":"20201118174913.3372-1-sir@cmpwn.com","threadId":"54667","inReplyTo":null,"subject":"[PATCH v5] help.c: expand options for help.autocorrect","fromName":"Drew DeVault","fromEmail":"sir@cmpwn.com","sentAt":"2020-11-18T17:49:14Z","receivedAt":"2020-11-18T17:50:57Z","isPatch":true,"sender":{"key":"sir@cmpwn.com","avatar":"https://avatars.githubusercontent.com/u/1310872?v=4"},"body":"Some users would prefer to never suggest corrections at all. For\nexample, they may want the mistake over with sooner so that they can\nissue the correct command, especially on low-end hardware which may take\na while to calculate suggestions.\n\nThis updates help.autocorrect to accept the strings \"immediate\" and\n\"never\" for this purpose, the former assuming the prior behavior of\nnegative values for autocorrect, and the latter skipping auto-correction\nentirely.\n\nSigned-off-by: Drew DeVault <sir@cmpwn.com>\n---\nv4 -> v5: More detailed commit message.\n\n Documentation/config/help.txt | 16 +++++++++-------\n help.c                        | 25 ++++++++++++++++++++++---\n 2 files changed, 31 insertions(+), 10 deletions(-)\n\ndiff --git a/Documentation/config/help.txt b/Documentation/config/help.txt\nindex 224bbf5a28..e07abd32d7 100644\n--- a/Documentation/config/help.txt\n+++ b/Documentation/config/help.txt\n@@ -8,13 +8,15 @@ help.format::\n \tthe default. 'web' and 'html' are the same.\n \n help.autoCorrect::\n-\tAutomatically correct and execute mistyped commands after\n-\twaiting for the given number of deciseconds (0.1 sec). If more\n-\tthan one command can be deduced from the entered text, nothing\n-\twill be executed.  If the value of this option is negative,\n-\tthe corrected command will be executed immediately. If the\n-\tvalue is 0 - the command will be just shown but not executed.\n-\tThis is the default.\n+\tIf git detects typos and can identify exactly one valid command similar\n+\tto the error, git will automatically run the intended command after\n+\twaiting a duration of time defined by this configuration value in\n+\tdeciseconds (0.1 sec).  If this value is 0, the suggested corrections\n+\twill be shown, but not executed. If \"immediate\", the suggested command\n+\tis run immediately. If \"never\", suggestions are not shown at all. The\n+\tdefault value is zero.\n++\n+Negative integers are interpreted as \"immediately\" for historical reasons.\n \n help.htmlPath::\n \tSpecify the path where the HTML documentation resides. File system paths\ndiff --git a/help.c b/help.c\nindex 919cbb9206..3c3bdec213 100644\n--- a/help.c\n+++ b/help.c\n@@ -472,12 +472,26 @@ int is_in_cmdlist(struct cmdnames *c, const char *s)\n static int autocorrect;\n static struct cmdnames aliases;\n \n+#define AUTOCORRECT_NEVER (-2)\n+#define AUTOCORRECT_IMMEDIATELY (-1)\n+\n static int git_unknown_cmd_config(const char *var, const char *value, void *cb)\n {\n \tconst char *p;\n \n-\tif (!strcmp(var, \"help.autocorrect\"))\n-\t\tautocorrect = git_config_int(var,value);\n+\tif (!strcmp(var, \"help.autocorrect\")) {\n+\t\tif (!value)\n+\t\t\treturn config_error_nonbool(var);\n+\t\tif (!strcmp(value, \"never\")) {\n+\t\t\tautocorrect = AUTOCORRECT_NEVER;\n+\t\t} else if (!strcmp(value, \"immediate\")) {\n+\t\t\tautocorrect = AUTOCORRECT_IMMEDIATELY;\n+\t\t} else {\n+\t\t\tint v = git_config_int(var, value);\n+\t\t\tautocorrect = (v < 0)\n+\t\t\t\t? AUTOCORRECT_IMMEDIATELY : v;\n+\t\t}\n+\t}\n \t/* Also use aliases for command lookup */\n \tif (skip_prefix(var, \"alias.\", &p))\n \t\tadd_cmdname(&aliases, p, strlen(p));\n@@ -525,6 +539,11 @@ const char *help_unknown_cmd(const char *cmd)\n \n \tread_early_config(git_unknown_cmd_config, NULL);\n \n+\tif (autocorrect == AUTOCORRECT_NEVER) {\n+\t\tfprintf_ln(stderr, _(\"git: '%s' is not a git command. See 'git --help'.\"), cmd);\n+\t\texit(1);\n+\t}\n+\n \tload_command_list(\"git-\", &main_cmds, &other_cmds);\n \n \tadd_cmd_list(&main_cmds, &aliases);\n@@ -594,7 +613,7 @@ const char *help_unknown_cmd(const char *cmd)\n \t\t\t   _(\"WARNING: You called a Git command named '%s', \"\n \t\t\t     \"which does not exist.\"),\n \t\t\t   cmd);\n-\t\tif (autocorrect < 0)\n+\t\tif (autocorrect == AUTOCORRECT_IMMEDIATELY)\n \t\t\tfprintf_ln(stderr,\n \t\t\t\t   _(\"Continuing under the assumption that \"\n \t\t\t\t     \"you meant '%s'.\"),\n-- \n2.29.2\n\n"}]}