Re: [TOY PATCH] git wrapper: show similar command names for an unknown command
Hi,
On Sat, 7 Jun 2008, Alex Riesen wrote:
Show 22 quoted lines
> diff --git a/help.c b/help.c
> index ac29225..765eed8 100644
> --- a/help.c
> +++ b/help.c
> @@ -640,7 +640,7 @@ static int levenshtein_compare(const void *p1, const void *p2)
>
> void help_unknown_cmd(const char *cmd)
> {
> - int i, header_shown = 0;
> + int i, header_shown = 0, listed = 0;
>
> fprintf(stderr, "git: '%s' is not a git-command. See 'git --help'.\n", cmd);
>
> @@ -667,6 +667,8 @@ void help_unknown_cmd(const char *cmd)
> header_shown = 1;
> }
> fprintf(stderr, "\t%s\n", main_cmds.names[i]->name);
> + if (++listed >= 5)
> + break;
> }
>
> exit(1);How about this instead?
-- snipsnap --
help.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/help.c b/help.c
index bd51852..173e502 100644
--- a/help.c
+++ b/help.c
@@ -655,7 +655,7 @@ void help_unknown_cmd(const char *cmd)
qsort(main_cmds.names, main_cmds.cnt,
sizeof(*main_cmds.names), levenshtein_compare);
- for (i = 0; i < main_cmds.cnt; i++) {
+ for (i = 0; i < main_cmds.cnt && i < 5; i++) {
int s = similarity(main_cmds.names[i]->name);
if (s > 6)
break;