summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8af84da)
raw | patch | inline | side by side (parent: 8af84da)
author | Alex Riesen <raa.lkml@gmail.com> | |
Sun, 31 Aug 2008 13:54:58 +0000 (15:54 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 31 Aug 2008 17:15:13 +0000 (10:15 -0700) |
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>
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>
Documentation/config.txt | patch | blob | history | |
help.c | patch | blob | history |
index af57d943049d5cf39b9681004cb0c7fd30a70c94..8c644ab8f6b171b54d2aeb8cafea9ec2344bf319 100644 (file)
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
Values 'man', 'info', 'web' and 'html' are supported. 'man' is
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.
+
http.proxy::
Override the HTTP proxy, normally configured using the 'http_proxy'
environment variable (see linkgit:curl[1]). This can be overridden
index b1ebca4091e9e1cb623ff89a69306cdb00aa9c68..74499bf840b4be6215b064e90dec79ec87e24c82 100644 (file)
--- a/help.c
+++ b/help.c
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;
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,
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);
"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;
}