diff options
-rw-r--r-- | Documentation/git.txt | 3 | ||||
-rwxr-xr-x | generate-cmdlist.sh | 17 | ||||
-rw-r--r-- | git.c | 7 | ||||
-rw-r--r-- | help.c | 23 | ||||
-rw-r--r-- | help.h | 2 |
5 files changed, 51 insertions, 1 deletions
diff --git a/Documentation/git.txt b/Documentation/git.txt index c01477ab5e..c423810eac 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -168,7 +168,8 @@ foo.bar= ...`) sets `foo.bar` to the empty string which `git config option and may change or be removed in the future. Supported groups are: builtins, parseopt (builtin commands that use parse-options), main (all commands in libexec directory), - others (all other commands in `$PATH` that have git- prefix). + others (all other commands in `$PATH` that have git- prefix), + list-<category> (see categories in command-list.txt) GIT COMMANDS ------------ diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh index 3bcc1ee57d..8d6d8b45ce 100755 --- a/generate-cmdlist.sh +++ b/generate-cmdlist.sh @@ -45,6 +45,21 @@ define_categories () { test "$bit" -gt 32 && die "Urgh.. too many categories?" } +define_category_names () { + echo + echo "/* Category names */" + echo "static const char *category_names[] = {" + bit=0 + category_list "$1" | + while read cat + do + echo " \"$cat\", /* (1UL << $bit) */" + bit=$(($bit+1)) + done + echo " NULL" + echo "};" +} + print_command_list () { echo "static struct cmdname_help command_list[] = {" @@ -70,4 +85,6 @@ struct cmdname_help { " define_categories "$1" echo +define_category_names "$1" +echo print_command_list "$1" @@ -60,6 +60,13 @@ static int list_cmds(const char *spec) list_all_main_cmds(&list); else if (match_token(spec, len, "others")) list_all_other_cmds(&list); + else if (len > 5 && !strncmp(spec, "list-", 5)) { + struct strbuf sb = STRBUF_INIT; + + strbuf_add(&sb, spec + 5, len - 5); + list_cmds_by_category(&list, sb.buf); + strbuf_release(&sb); + } else die(_("unsupported command listing type '%s'"), spec); spec += len; @@ -329,6 +329,29 @@ void list_all_other_cmds(struct string_list *list) clean_cmdnames(&other_cmds); } +void list_cmds_by_category(struct string_list *list, + const char *cat) +{ + int i, n = ARRAY_SIZE(command_list); + uint32_t cat_id = 0; + + for (i = 0; category_names[i]; i++) { + if (!strcmp(cat, category_names[i])) { + cat_id = 1UL << i; + break; + } + } + if (!cat_id) + die(_("unsupported command listing type '%s'"), cat); + + for (i = 0; i < n; i++) { + struct cmdname_help *cmd = command_list + i; + + if (cmd->category & cat_id) + string_list_append(list, drop_prefix(cmd->name)); + } +} + int is_in_cmdlist(struct cmdnames *c, const char *s) { int i; @@ -21,6 +21,8 @@ static inline void mput_char(char c, unsigned int num) extern void list_common_cmds_help(void); extern void list_all_main_cmds(struct string_list *list); extern void list_all_other_cmds(struct string_list *list); +extern void list_cmds_by_category(struct string_list *list, + const char *category); extern const char *help_unknown_cmd(const char *cmd); extern void load_command_list(const char *prefix, struct cmdnames *main_cmds, |