mirror of
https://github.com/git/git.git
synced 2024-11-23 18:05:29 +08:00
help.c: refactor drop_prefix() to use a "switch" statement"
Refactor the drop_prefix() function in in help.c to make it easier to strip prefixes from categories that aren't "CAT_guide". There are no functional changes here, by doing this we make a subsequent functional change's diff smaller. As before we first try to strip "git-" unconditionally, if that works we'll return the stripped string. Then we'll strip "git" if the command is in "CAT_guide". This means that we'd in principle strip "git-foo" down to "foo" if it's in CAT_guide. That doesn't make much sense, and we don't have such an entry in command-list.txt, but let's preserve that behavior for now. While we're at it remove a stray newline that had been added after the "return name;" statement. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
6a475b71f8
commit
2f8b3ea662
10
help.c
10
help.c
@ -44,13 +44,19 @@ static struct category_description main_categories[] = {
|
||||
static const char *drop_prefix(const char *name, uint32_t category)
|
||||
{
|
||||
const char *new_name;
|
||||
const char *prefix = NULL;
|
||||
|
||||
if (skip_prefix(name, "git-", &new_name))
|
||||
return new_name;
|
||||
if (category == CAT_guide && skip_prefix(name, "git", &new_name))
|
||||
switch (category) {
|
||||
case CAT_guide:
|
||||
prefix = "git";
|
||||
break;
|
||||
}
|
||||
if (prefix && skip_prefix(name, prefix, &new_name))
|
||||
return new_name;
|
||||
return name;
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
static void extract_cmds(struct cmdname_help **p_cmds, uint32_t mask)
|
||||
|
Loading…
Reference in New Issue
Block a user