summaryrefslogtreecommitdiff
path: root/help.c
diff options
context:
space:
mode:
authorAlex Riesen <raa.lkml@gmail.com>2008-08-31 15:54:58 +0200
committerJunio C Hamano <gitster@pobox.com>2008-08-31 10:15:13 -0700
commitf0e90716d47b429284702b75425a247c9fc41adb (patch)
treeeb7a133ff0f05aac1dd6c53de1242f997e3191a7 /help.c
parent8af84dadb142f7321ff0ce8690385e99da8ede2f (diff)
downloadgit-f0e90716d47b429284702b75425a247c9fc41adb.tar.gz
Add help.autocorrect to enable/disable autocorrecting
It is off(0) by default, to avoid scaring people unless they asked to. If set to a non-0 value, wait for that amount of deciseconds before running the corrected command. Suggested by Junio, so he has a chance to hit Ctrl-C. Signed-off-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'help.c')
-rw-r--r--help.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/help.c b/help.c
index b1ebca4091..74499bf840 100644
--- a/help.c
+++ b/help.c
@@ -268,6 +268,16 @@ int is_in_cmdlist(struct cmdnames *c, const char *s)
return 0;
}
+static int autocorrect;
+
+static int git_unknown_cmd_config(const char *var, const char *value, void *cb)
+{
+ if (!strcmp(var, "help.autocorrect"))
+ autocorrect = git_config_int(var,value);
+
+ return git_default_config(var, value, cb);
+}
+
static int levenshtein_compare(const void *p1, const void *p2)
{
const struct cmdname *const *c1 = p1, *const *c2 = p2;
@@ -285,6 +295,8 @@ const char *help_unknown_cmd(const char *cmd)
memset(&main_cmds, 0, sizeof(main_cmds));
memset(&other_cmds, 0, sizeof(main_cmds));
+ git_config(git_unknown_cmd_config, NULL);
+
load_command_list("git-", &main_cmds, &other_cmds);
ALLOC_GROW(main_cmds.names, main_cmds.cnt + other_cmds.cnt,
@@ -309,7 +321,7 @@ const char *help_unknown_cmd(const char *cmd)
n = 1;
while (n < main_cmds.cnt && best_similarity == main_cmds.names[n]->len)
++n;
- if (n == 1) {
+ if (autocorrect && n == 1) {
const char *assumed = main_cmds.names[0]->name;
main_cmds.names[0] = NULL;
clean_cmdnames(&main_cmds);
@@ -317,6 +329,11 @@ const char *help_unknown_cmd(const char *cmd)
"which does not exist.\n"
"Continuing under the assumption that you meant '%s'\n",
cmd, assumed);
+ if (autocorrect > 0) {
+ fprintf(stderr, "in %0.1f seconds automatically...\n",
+ (float)autocorrect/10.0);
+ poll(NULL, 0, autocorrect * 100);
+ }
return assumed;
}