File tree Expand file tree Collapse file tree 5 files changed +51
-1
lines changed
Expand file tree Collapse file tree 5 files changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -168,7 +168,8 @@ foo.bar= ...`) sets `foo.bar` to the empty string which `git config
168168 option and may change or be removed in the future. Supported
169169 groups are: builtins, parseopt (builtin commands that use
170170 parse-options), main (all commands in libexec directory),
171- others (all other commands in `$PATH` that have git- prefix).
171+ others (all other commands in `$PATH` that have git- prefix),
172+ list-<category> (see categories in command-list.txt)
172173
173174GIT COMMANDS
174175------------
Original file line number Diff line number Diff line change @@ -45,6 +45,21 @@ define_categories () {
4545 test " $bit " -gt 32 && die " Urgh.. too many categories?"
4646}
4747
48+ define_category_names () {
49+ echo
50+ echo " /* Category names */"
51+ echo " static const char *category_names[] = {"
52+ bit=0
53+ category_list " $1 " |
54+ while read cat
55+ do
56+ echo " \" $cat \" , /* (1UL << $bit ) */"
57+ bit=$(( $bit + 1 ))
58+ done
59+ echo " NULL"
60+ echo " };"
61+ }
62+
4863print_command_list () {
4964 echo " static struct cmdname_help command_list[] = {"
5065
@@ -70,4 +85,6 @@ struct cmdname_help {
7085"
7186define_categories " $1 "
7287echo
88+ define_category_names " $1 "
89+ echo
7390print_command_list " $1 "
Original file line number Diff line number Diff line change @@ -60,6 +60,13 @@ static int list_cmds(const char *spec)
6060 list_all_main_cmds (& list );
6161 else if (match_token (spec , len , "others" ))
6262 list_all_other_cmds (& list );
63+ else if (len > 5 && !strncmp (spec , "list-" , 5 )) {
64+ struct strbuf sb = STRBUF_INIT ;
65+
66+ strbuf_add (& sb , spec + 5 , len - 5 );
67+ list_cmds_by_category (& list , sb .buf );
68+ strbuf_release (& sb );
69+ }
6370 else
6471 die (_ ("unsupported command listing type '%s'" ), spec );
6572 spec += len ;
Original file line number Diff line number Diff line change @@ -329,6 +329,29 @@ void list_all_other_cmds(struct string_list *list)
329329 clean_cmdnames (& other_cmds );
330330}
331331
332+ void list_cmds_by_category (struct string_list * list ,
333+ const char * cat )
334+ {
335+ int i , n = ARRAY_SIZE (command_list );
336+ uint32_t cat_id = 0 ;
337+
338+ for (i = 0 ; category_names [i ]; i ++ ) {
339+ if (!strcmp (cat , category_names [i ])) {
340+ cat_id = 1UL << i ;
341+ break ;
342+ }
343+ }
344+ if (!cat_id )
345+ die (_ ("unsupported command listing type '%s'" ), cat );
346+
347+ for (i = 0 ; i < n ; i ++ ) {
348+ struct cmdname_help * cmd = command_list + i ;
349+
350+ if (cmd -> category & cat_id )
351+ string_list_append (list , drop_prefix (cmd -> name ));
352+ }
353+ }
354+
332355int is_in_cmdlist (struct cmdnames * c , const char * s )
333356{
334357 int i ;
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ static inline void mput_char(char c, unsigned int num)
2121extern void list_common_cmds_help (void );
2222extern void list_all_main_cmds (struct string_list * list );
2323extern void list_all_other_cmds (struct string_list * list );
24+ extern void list_cmds_by_category (struct string_list * list ,
25+ const char * category );
2426extern const char * help_unknown_cmd (const char * cmd );
2527extern void load_command_list (const char * prefix ,
2628 struct cmdnames * main_cmds ,
You can’t perform that action at this time.
0 commit comments