Git fork

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>

authored by

Ævar Arnfjörð Bjarmason and committed by
Junio C Hamano
2f8b3ea6 6a475b71

+8 -2
+8 -2
help.c
··· 44 44 static const char *drop_prefix(const char *name, uint32_t category) 45 45 { 46 46 const char *new_name; 47 + const char *prefix = NULL; 47 48 48 49 if (skip_prefix(name, "git-", &new_name)) 49 50 return new_name; 50 - if (category == CAT_guide && skip_prefix(name, "git", &new_name)) 51 + switch (category) { 52 + case CAT_guide: 53 + prefix = "git"; 54 + break; 55 + } 56 + if (prefix && skip_prefix(name, prefix, &new_name)) 51 57 return new_name; 52 - return name; 53 58 59 + return name; 54 60 } 55 61 56 62 static void extract_cmds(struct cmdname_help **p_cmds, uint32_t mask)