X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=help.c;h=7f4928e45954465d0401964289952aec4bd59e2a;hb=48c250a121a425a1860226b6a7061aecfbab5246;hp=e8db31f60f010887ccb3a943344da566e0937403;hpb=39add7a36feca434ba85267cb76e4fd69bcdc13a;p=git.git diff --git a/help.c b/help.c index e8db31f60..7f4928e45 100644 --- a/help.c +++ b/help.c @@ -297,6 +297,9 @@ static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old) old->names = NULL; } +/* An empirically derived magic number */ +#define SIMILAR_ENOUGH(x) ((x) < 6) + const char *help_unknown_cmd(const char *cmd) { int i, n, best_similarity = 0; @@ -331,7 +334,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 (autocorrect && n == 1) { + if (autocorrect && n == 1 && SIMILAR_ENOUGH(best_similarity)) { const char *assumed = main_cmds.names[0]->name; main_cmds.names[0] = NULL; clean_cmdnames(&main_cmds); @@ -347,9 +350,9 @@ const char *help_unknown_cmd(const char *cmd) return assumed; } - fprintf(stderr, "git: '%s' is not a git-command. See 'git --help'.\n", cmd); + fprintf(stderr, "git: '%s' is not a git command. See 'git --help'.\n", cmd); - if (best_similarity < 6) { + if (SIMILAR_ENOUGH(best_similarity)) { fprintf(stderr, "\nDid you mean %s?\n", n < 2 ? "this": "one of these");