X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=help.c;h=9da97d7462040d3935e7eaa95b1167357b38a943;hb=38a81b4e82ebf57549f2fa082b329c36dffc0b18;hp=294337e71c0c8f1c3e150dd0b566c04db96c013d;hpb=6b37b3d873e734919dfd43c3d124c4f98e265296;p=git.git diff --git a/help.c b/help.c index 294337e71..9da97d746 100644 --- a/help.c +++ b/help.c @@ -126,8 +126,8 @@ static int is_executable(const char *name) !S_ISREG(st.st_mode)) return 0; -#ifdef __MINGW32__ - /* cannot trust the executable bit, peek into the file instead */ +#ifdef WIN32 +{ /* cannot trust the executable bit, peek into the file instead */ char buf[3] = { 0 }; int n; int fd = open(name, O_RDONLY); @@ -140,6 +140,7 @@ static int is_executable(const char *name) st.st_mode |= S_IXUSR; close(fd); } +} #endif return st.st_mode & S_IXUSR; } @@ -296,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; @@ -330,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); @@ -348,7 +352,7 @@ const char *help_unknown_cmd(const char *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");