diff options
| author | Junio C Hamano <gitster@pobox.com> | 2025-02-12 10:08:54 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-02-12 10:08:55 -0800 |
| commit | 39de0ffbe33fbb6498a3027207deb3a5d30ff678 (patch) | |
| tree | f19be747f14fd643f97690732731e526d6a7c928 /help.c | |
| parent | Merge branch 'ms/remote-valid-remote-name' (diff) | |
| parent | help: interpret boolean string values for help.autocorrect (diff) | |
| download | git-39de0ffbe33fbb6498a3027207deb3a5d30ff678.tar.gz git-39de0ffbe33fbb6498a3027207deb3a5d30ff678.zip | |
Merge branch 'sc/help-autocorrect-one'
"[help] autocorrect = 1" used to be a way to say "please wait for
0.1 second after suggesting a typofix of the command name before
running that command"; now it means "yes, if there is a plausible
typofix for the command name, please run it immediately".
* sc/help-autocorrect-one:
help: interpret boolean string values for help.autocorrect
Diffstat (limited to 'help.c')
| -rw-r--r-- | help.c | 42 |
1 files changed, 30 insertions, 12 deletions
@@ -556,6 +556,27 @@ struct help_unknown_cmd_config { #define AUTOCORRECT_NEVER (-2) #define AUTOCORRECT_IMMEDIATELY (-1) +static int parse_autocorrect(const char *value) +{ + switch (git_parse_maybe_bool_text(value)) { + case 1: + return AUTOCORRECT_IMMEDIATELY; + case 0: + return AUTOCORRECT_NEVER; + default: /* other random text */ + break; + } + + if (!strcmp(value, "prompt")) + return AUTOCORRECT_PROMPT; + if (!strcmp(value, "never")) + return AUTOCORRECT_NEVER; + if (!strcmp(value, "immediate")) + return AUTOCORRECT_IMMEDIATELY; + + return 0; +} + static int git_unknown_cmd_config(const char *var, const char *value, const struct config_context *ctx, void *cb) @@ -564,20 +585,17 @@ static int git_unknown_cmd_config(const char *var, const char *value, const char *p; if (!strcmp(var, "help.autocorrect")) { - if (!value) - return config_error_nonbool(var); - if (!strcmp(value, "never")) { - cfg->autocorrect = AUTOCORRECT_NEVER; - } else if (!strcmp(value, "immediate")) { - cfg->autocorrect = AUTOCORRECT_IMMEDIATELY; - } else if (!strcmp(value, "prompt")) { - cfg->autocorrect = AUTOCORRECT_PROMPT; - } else { - int v = git_config_int(var, value, ctx->kvi); - cfg->autocorrect = (v < 0) - ? AUTOCORRECT_IMMEDIATELY : v; + int v = parse_autocorrect(value); + + if (!v) { + v = git_config_int(var, value, ctx->kvi); + if (v < 0 || v == 1) + v = AUTOCORRECT_IMMEDIATELY; } + + cfg->autocorrect = v; } + /* Also use aliases for command lookup */ if (skip_prefix(var, "alias.", &p)) add_cmdname(&cfg->aliases, p, strlen(p)); |
