Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 147635
b: refs/heads/master
c: 051cdc3
h: refs/heads/master
i:
  147633: efc90d6
  147631: b4e77ef
v: v3
  • Loading branch information
Ingo Molnar committed Jun 3, 2009
1 parent ca986f9 commit f19a68b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: eed4dcd443da7a46131ef37c7a389b444905960e
refs/heads/master: 051cdc3c2d0e24443ac03aff03ee89807ec8c589
28 changes: 16 additions & 12 deletions trunk/Documentation/perf_counter/util/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ static void add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)

const char *help_unknown_cmd(const char *cmd)
{
int i, n, best_similarity = 0;
int i, n = 0, best_similarity = 0;
struct cmdnames main_cmds, other_cmds;

memset(&main_cmds, 0, sizeof(main_cmds));
Expand All @@ -315,20 +315,24 @@ const char *help_unknown_cmd(const char *cmd)
sizeof(main_cmds.names), cmdname_compare);
uniq(&main_cmds);

/* This reuses cmdname->len for similarity index */
for (i = 0; i < main_cmds.cnt; ++i)
main_cmds.names[i]->len =
levenshtein(cmd, main_cmds.names[i]->name, 0, 2, 1, 4);
if (main_cmds.cnt) {
/* This reuses cmdname->len for similarity index */
for (i = 0; i < main_cmds.cnt; ++i)
main_cmds.names[i]->len =
levenshtein(cmd, main_cmds.names[i]->name, 0, 2, 1, 4);

qsort(main_cmds.names, main_cmds.cnt,
sizeof(*main_cmds.names), levenshtein_compare);
qsort(main_cmds.names, main_cmds.cnt,
sizeof(*main_cmds.names), levenshtein_compare);

best_similarity = main_cmds.names[0]->len;
n = 1;
while (n < main_cmds.cnt && best_similarity == main_cmds.names[n]->len)
++n;
}

best_similarity = main_cmds.names[0]->len;
n = 1;
while (n < main_cmds.cnt && best_similarity == main_cmds.names[n]->len)
++n;
if (autocorrect && n == 1) {
const char *assumed = main_cmds.names[0]->name;

main_cmds.names[0] = NULL;
clean_cmdnames(&main_cmds);
fprintf(stderr, "WARNING: You called a Git program named '%s', "
Expand All @@ -345,7 +349,7 @@ const char *help_unknown_cmd(const char *cmd)

fprintf(stderr, "perf: '%s' is not a perf-command. See 'perf --help'.\n", cmd);

if (best_similarity < 6) {
if (main_cmds.cnt && best_similarity < 6) {
fprintf(stderr, "\nDid you mean %s?\n",
n < 2 ? "this": "one of these");

Expand Down

0 comments on commit f19a68b

Please sign in to comment.