use QSORT
Apply the semantic patch contrib/coccinelle/qsort.cocci to the code base, replacing calls of qsort(3) with QSORT. The resulting code is shorter and supports empty arrays with NULL pointers. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
dbc540c7a5
commit
9ed0d8d6e6
15
help.c
15
help.c
@ -170,8 +170,7 @@ void load_command_list(const char *prefix,
|
||||
|
||||
if (exec_path) {
|
||||
list_commands_in_dir(main_cmds, exec_path, prefix);
|
||||
qsort(main_cmds->names, main_cmds->cnt,
|
||||
sizeof(*main_cmds->names), cmdname_compare);
|
||||
QSORT(main_cmds->names, main_cmds->cnt, cmdname_compare);
|
||||
uniq(main_cmds);
|
||||
}
|
||||
|
||||
@ -190,8 +189,7 @@ void load_command_list(const char *prefix,
|
||||
}
|
||||
free(paths);
|
||||
|
||||
qsort(other_cmds->names, other_cmds->cnt,
|
||||
sizeof(*other_cmds->names), cmdname_compare);
|
||||
QSORT(other_cmds->names, other_cmds->cnt, cmdname_compare);
|
||||
uniq(other_cmds);
|
||||
}
|
||||
exclude_cmds(other_cmds, main_cmds);
|
||||
@ -238,8 +236,7 @@ void list_common_cmds_help(void)
|
||||
longest = strlen(common_cmds[i].name);
|
||||
}
|
||||
|
||||
qsort(common_cmds, ARRAY_SIZE(common_cmds),
|
||||
sizeof(common_cmds[0]), cmd_group_cmp);
|
||||
QSORT(common_cmds, ARRAY_SIZE(common_cmds), cmd_group_cmp);
|
||||
|
||||
puts(_("These are common Git commands used in various situations:"));
|
||||
|
||||
@ -324,8 +321,7 @@ const char *help_unknown_cmd(const char *cmd)
|
||||
|
||||
add_cmd_list(&main_cmds, &aliases);
|
||||
add_cmd_list(&main_cmds, &other_cmds);
|
||||
qsort(main_cmds.names, main_cmds.cnt,
|
||||
sizeof(*main_cmds.names), cmdname_compare);
|
||||
QSORT(main_cmds.names, main_cmds.cnt, cmdname_compare);
|
||||
uniq(&main_cmds);
|
||||
|
||||
/* This abuses cmdname->len for levenshtein distance */
|
||||
@ -359,8 +355,7 @@ const char *help_unknown_cmd(const char *cmd)
|
||||
levenshtein(cmd, candidate, 0, 2, 1, 3) + 1;
|
||||
}
|
||||
|
||||
qsort(main_cmds.names, main_cmds.cnt,
|
||||
sizeof(*main_cmds.names), levenshtein_compare);
|
||||
QSORT(main_cmds.names, main_cmds.cnt, levenshtein_compare);
|
||||
|
||||
if (!main_cmds.cnt)
|
||||
die(_("Uh oh. Your system reports no Git commands at all."));
|
||||
|
||||
Reference in New Issue
Block a user