help: use command-list.txt for the source of guides

The help command currently hard codes the list of guides and their summary in C. Let's move this list to command-list.txt. This lets us extract summary lines from Documentation/git*.txt. This also potentially lets us list guides in git.txt, but I'll leave that for now. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed May 20, 2018 at 20:40 UTC 1b81d8cb19d8da6d865b7fca5a095dd5fec8d209
10 files changed +54 -45
Documentation/gitattributes.txt
+1 -1
@@ -3,7 +3,7 @@ gitattributes(5)
3
4 NAME
5 ----
6 -gitattributes - defining attributes per path
6 +gitattributes - Defining attributes per path
7
8 SYNOPSIS
9 --------
Documentation/gitmodules.txt
+1 -1
@@ -3,7 +3,7 @@ gitmodules(5)
3
4 NAME
5 ----
6 -gitmodules - defining submodule properties
6 +gitmodules - Defining submodule properties
7
8 SYNOPSIS
9 --------
Documentation/gitrevisions.txt
+1 -1
@@ -3,7 +3,7 @@ gitrevisions(7)
3
4 NAME
5 ----
6 -gitrevisions - specifying revisions and ranges for Git
6 +gitrevisions - Specifying revisions and ranges for Git
7
8 SYNOPSIS
9 --------
Makefile
+1 -1
@@ -1937,7 +1937,7 @@ $(BUILT_INS): git$X
1937
1938 command-list.h: generate-cmdlist.sh command-list.txt
1939
1940 -command-list.h: $(wildcard Documentation/git-*.txt)
1940 +command-list.h: $(wildcard Documentation/git*.txt)
1941 $(QUIET_GEN)$(SHELL_PATH) ./generate-cmdlist.sh command-list.txt >$@+ && mv $@+ $@
1942
1943 SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
builtin/help.c
-32
@@ -402,38 +402,6 @@ static void show_html_page(const char *git_cmd)
402 open_html(page_path.buf);
403 }
404
405 -static struct {
406 - const char *name;
407 - const char *help;
408 -} common_guides[] = {
409 - { "attributes", N_("Defining attributes per path") },
410 - { "everyday", N_("Everyday Git With 20 Commands Or So") },
411 - { "glossary", N_("A Git glossary") },
412 - { "ignore", N_("Specifies intentionally untracked files to ignore") },
413 - { "modules", N_("Defining submodule properties") },
414 - { "revisions", N_("Specifying revisions and ranges for Git") },
415 - { "tutorial", N_("A tutorial introduction to Git (for version 1.5.1 or newer)") },
416 - { "workflows", N_("An overview of recommended workflows with Git") },
417 -};
418 -
419 -static void list_common_guides_help(void)
420 -{
421 - int i, longest = 0;
422 -
423 - for (i = 0; i < ARRAY_SIZE(common_guides); i++) {
424 - if (longest < strlen(common_guides[i].name))
425 - longest = strlen(common_guides[i].name);
426 - }
427 -
428 - puts(_("The common Git guides are:\n"));
429 - for (i = 0; i < ARRAY_SIZE(common_guides); i++) {
430 - printf(" %s ", common_guides[i].name);
431 - mput_char(' ', longest - strlen(common_guides[i].name));
432 - puts(_(common_guides[i].help));
433 - }
434 - putchar('\n');
435 -}
436 -
405 static const char *check_git_cmd(const char* cmd)
406 {
407 char *alias;
command-list.txt
+16
@@ -139,3 +139,19 @@ gitweb ancillaryinterrogators
139 git-whatchanged ancillaryinterrogators
140 git-worktree mainporcelain
141 git-write-tree plumbingmanipulators
142 +gitattributes guide
143 +gitcli guide
144 +gitcore-tutorial guide
145 +gitcvs-migration guide
146 +gitdiffcore guide
147 +giteveryday guide
148 +gitglossary guide
149 +githooks guide
150 +gitignore guide
151 +gitmodules guide
152 +gitnamespaces guide
153 +gitrepository-layout guide
154 +gitrevisions guide
155 +gittutorial-2 guide
156 +gittutorial guide
157 +gitworkflows guide
contrib/completion/git-completion.bash
+10 -5
@@ -1575,6 +1575,13 @@ _git_grep ()
1575 __git_complete_refs
1576 }
1577
1578 +__git_all_guides=
1579 +__git_compute_all_guides ()
1580 +{
1581 + test -n "$__git_all_guides" ||
1582 + __git_all_guides=$(git --list-cmds=list-guide)
1583 +}
1584 +
1585 _git_help ()
1586 {
1587 case "$cur" in
@@ -1584,11 +1591,9 @@ _git_help ()
1591 ;;
1592 esac
1593 __git_compute_all_commands
1587 - __gitcomp "$__git_all_commands $(__git_aliases)
1588 - attributes cli core-tutorial cvs-migration
1589 - diffcore everyday gitk glossary hooks ignore modules
1590 - namespaces repository-layout revisions tutorial tutorial-2
1591 - workflows
1594 + __git_compute_all_guides
1595 + __gitcomp "$__git_all_commands $(__git_aliases) $__git_all_guides
1596 + gitk
1597 "
1598 }
1599
help.c
+17 -4
@@ -39,12 +39,14 @@ static struct category_description main_categories[] = {
39 { 0, NULL }
40 };
41
42 -static const char *drop_prefix(const char *name)
42 +static const char *drop_prefix(const char *name, uint32_t category)
43 {
44 const char *new_name;
45
46 if (skip_prefix(name, "git-", &new_name))
47 return new_name;
48 + if (category == CAT_guide && skip_prefix(name, "git", &new_name))
49 + return new_name;
50 return name;
51
52 }
@@ -66,7 +68,7 @@ static void extract_cmds(struct cmdname_help **p_cmds, uint32_t mask)
68 continue;
69
70 cmds[nr] = *cmd;
69 - cmds[nr].name = drop_prefix(cmd->name);
71 + cmds[nr].name = drop_prefix(cmd->name, cmd->category);
72
73 nr++;
74 }
@@ -358,11 +360,22 @@ void list_cmds_by_category(struct string_list *list,
360 for (i = 0; i < n; i++) {
361 struct cmdname_help *cmd = command_list + i;
362
361 - if (cmd->category & cat_id)
362 - string_list_append(list, drop_prefix(cmd->name));
363 + if (!(cmd->category & cat_id))
364 + continue;
365 + string_list_append(list, drop_prefix(cmd->name, cmd->category));
366 }
367 }
368
369 +void list_common_guides_help(void)
370 +{
371 + struct category_description catdesc[] = {
372 + { CAT_guide, N_("The common Git guides are:") },
373 + { 0, NULL }
374 + };
375 + print_cmd_by_category(catdesc);
376 + putchar('\n');
377 +}
378 +
379 void list_all_cmds_help(void)
380 {
381 print_cmd_by_category(main_categories);
help.h
+1
@@ -20,6 +20,7 @@ static inline void mput_char(char c, unsigned int num)
20
21 extern void list_common_cmds_help(void);
22 extern void list_all_cmds_help(void);
23 +extern void list_common_guides_help(void);
24
25 extern void list_all_main_cmds(struct string_list *list);
26 extern void list_all_other_cmds(struct string_list *list);
t/t0012-help.sh
+6
@@ -66,6 +66,12 @@ test_expect_success 'git help' '
66 test_i18ngrep "^ commit " help.output &&
67 test_i18ngrep "^ fetch " help.output
68 '
69 +test_expect_success 'git help -g' '
70 + git help -g >help.output &&
71 + test_i18ngrep "^ attributes " help.output &&
72 + test_i18ngrep "^ everyday " help.output &&
73 + test_i18ngrep "^ tutorial " help.output
74 +'
75
76 test_expect_success 'generate builtin list' '
77 git --list-cmds=builtins >builtins