]> git.ipfire.org Git - thirdparty/git.git/commitdiff
help: use command-list.txt for the source of guides
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sun, 20 May 2018 18:40:02 +0000 (20:40 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 21 May 2018 04:23:14 +0000 (13:23 +0900)
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>
Documentation/gitattributes.txt
Documentation/gitmodules.txt
Documentation/gitrevisions.txt
Makefile
builtin/help.c
command-list.txt
contrib/completion/git-completion.bash
help.c
help.h
t/t0012-help.sh

index 1094fe2b5b0cc97030dc6694364f473999a9f4d3..083c2f380d218bce30d494813f24e420b331a8a8 100644 (file)
@@ -3,7 +3,7 @@ gitattributes(5)
 
 NAME
 ----
-gitattributes - defining attributes per path
+gitattributes - Defining attributes per path
 
 SYNOPSIS
 --------
index db5d47eb19b8f2aa21c11a9d3eedf40b9d71e84e..4d63def2069a8358afa05154c18653175dda6703 100644 (file)
@@ -3,7 +3,7 @@ gitmodules(5)
 
 NAME
 ----
-gitmodules - defining submodule properties
+gitmodules - Defining submodule properties
 
 SYNOPSIS
 --------
index 27dec5b91d08bbdb114400dd3c86a8cf515e8774..1f6cceaefb028e5f96d802703a25a16e950a3e17 100644 (file)
@@ -3,7 +3,7 @@ gitrevisions(7)
 
 NAME
 ----
-gitrevisions - specifying revisions and ranges for Git
+gitrevisions - Specifying revisions and ranges for Git
 
 SYNOPSIS
 --------
index a60a78ee67d3f103b5e89ff6b77ac2966ea5610f..1efb751e4621934e55c8805bb40e7d34ec0735ca 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1937,7 +1937,7 @@ $(BUILT_INS): git$X
 
 command-list.h: generate-cmdlist.sh command-list.txt
 
-command-list.h: $(wildcard Documentation/git-*.txt)
+command-list.h: $(wildcard Documentation/git*.txt)
        $(QUIET_GEN)$(SHELL_PATH) ./generate-cmdlist.sh command-list.txt >$@+ && mv $@+ $@
 
 SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
index 0e0af8426ac41473c9d365f67d226eaa496bb1ee..5727fb5e515f07f29e92a414674ee15f8c461608 100644 (file)
@@ -402,38 +402,6 @@ static void show_html_page(const char *git_cmd)
        open_html(page_path.buf);
 }
 
-static struct {
-       const char *name;
-       const char *help;
-} common_guides[] = {
-       { "attributes", N_("Defining attributes per path") },
-       { "everyday", N_("Everyday Git With 20 Commands Or So") },
-       { "glossary", N_("A Git glossary") },
-       { "ignore", N_("Specifies intentionally untracked files to ignore") },
-       { "modules", N_("Defining submodule properties") },
-       { "revisions", N_("Specifying revisions and ranges for Git") },
-       { "tutorial", N_("A tutorial introduction to Git (for version 1.5.1 or newer)") },
-       { "workflows", N_("An overview of recommended workflows with Git") },
-};
-
-static void list_common_guides_help(void)
-{
-       int i, longest = 0;
-
-       for (i = 0; i < ARRAY_SIZE(common_guides); i++) {
-               if (longest < strlen(common_guides[i].name))
-                       longest = strlen(common_guides[i].name);
-       }
-
-       puts(_("The common Git guides are:\n"));
-       for (i = 0; i < ARRAY_SIZE(common_guides); i++) {
-               printf("   %s   ", common_guides[i].name);
-               mput_char(' ', longest - strlen(common_guides[i].name));
-               puts(_(common_guides[i].help));
-       }
-       putchar('\n');
-}
-
 static const char *check_git_cmd(const char* cmd)
 {
        char *alias;
index 3bd23201a66b47c7c923f56c99397e9b95fdb13d..99ddc231c1b32bc824801c66029fd05a5cd0e385 100644 (file)
@@ -139,3 +139,19 @@ gitweb                                  ancillaryinterrogators
 git-whatchanged                         ancillaryinterrogators
 git-worktree                            mainporcelain
 git-write-tree                          plumbingmanipulators
+gitattributes                           guide
+gitcli                                  guide
+gitcore-tutorial                        guide
+gitcvs-migration                        guide
+gitdiffcore                             guide
+giteveryday                             guide
+gitglossary                             guide
+githooks                                guide
+gitignore                               guide
+gitmodules                              guide
+gitnamespaces                           guide
+gitrepository-layout                    guide
+gitrevisions                            guide
+gittutorial-2                           guide
+gittutorial                             guide
+gitworkflows                            guide
index 62ca8641f434192251972f2c8fa9f675220646ec..4e724a5b7648b96539e635bc3328fb066d576864 100644 (file)
@@ -1575,6 +1575,13 @@ _git_grep ()
        __git_complete_refs
 }
 
+__git_all_guides=
+__git_compute_all_guides ()
+{
+       test -n "$__git_all_guides" ||
+       __git_all_guides=$(git --list-cmds=list-guide)
+}
+
 _git_help ()
 {
        case "$cur" in
@@ -1584,11 +1591,9 @@ _git_help ()
                ;;
        esac
        __git_compute_all_commands
-       __gitcomp "$__git_all_commands $(__git_aliases)
-               attributes cli core-tutorial cvs-migration
-               diffcore everyday gitk glossary hooks ignore modules
-               namespaces repository-layout revisions tutorial tutorial-2
-               workflows
+       __git_compute_all_guides
+       __gitcomp "$__git_all_commands $(__git_aliases) $__git_all_guides
+               gitk
                "
 }
 
diff --git a/help.c b/help.c
index c7df1d233884ad7276aab23c9ba2c1a90039c9f8..23924dd30044b9fcf34839671efcf92d3e7d175b 100644 (file)
--- a/help.c
+++ b/help.c
@@ -39,12 +39,14 @@ static struct category_description main_categories[] = {
        { 0, NULL }
 };
 
-static const char *drop_prefix(const char *name)
+static const char *drop_prefix(const char *name, uint32_t category)
 {
        const char *new_name;
 
        if (skip_prefix(name, "git-", &new_name))
                return new_name;
+       if (category == CAT_guide && skip_prefix(name, "git", &new_name))
+               return new_name;
        return name;
 
 }
@@ -66,7 +68,7 @@ static void extract_cmds(struct cmdname_help **p_cmds, uint32_t mask)
                        continue;
 
                cmds[nr] = *cmd;
-               cmds[nr].name = drop_prefix(cmd->name);
+               cmds[nr].name = drop_prefix(cmd->name, cmd->category);
 
                nr++;
        }
@@ -358,11 +360,22 @@ void list_cmds_by_category(struct string_list *list,
        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));
+               if (!(cmd->category & cat_id))
+                       continue;
+               string_list_append(list, drop_prefix(cmd->name, cmd->category));
        }
 }
 
+void list_common_guides_help(void)
+{
+       struct category_description catdesc[] = {
+               { CAT_guide, N_("The common Git guides are:") },
+               { 0, NULL }
+       };
+       print_cmd_by_category(catdesc);
+       putchar('\n');
+}
+
 void list_all_cmds_help(void)
 {
        print_cmd_by_category(main_categories);
diff --git a/help.h b/help.h
index 40917fc38ce0008c1c718470bd2b859aacdeea5e..b2293e99bee97bef1563aef29a6c7ad958eb632f 100644 (file)
--- a/help.h
+++ b/help.h
@@ -20,6 +20,7 @@ static inline void mput_char(char c, unsigned int num)
 
 extern void list_common_cmds_help(void);
 extern void list_all_cmds_help(void);
+extern void list_common_guides_help(void);
 
 extern void list_all_main_cmds(struct string_list *list);
 extern void list_all_other_cmds(struct string_list *list);
index 060df24c2d99f433b0aa24288b93b108255a0afa..bc27df7f383d14fb5fea6266591469c32e562c4e 100755 (executable)
@@ -66,6 +66,12 @@ test_expect_success 'git help' '
        test_i18ngrep "^   commit " help.output &&
        test_i18ngrep "^   fetch  " help.output
 '
+test_expect_success 'git help -g' '
+       git help -g >help.output &&
+       test_i18ngrep "^   attributes " help.output &&
+       test_i18ngrep "^   everyday   " help.output &&
+       test_i18ngrep "^   tutorial   " help.output
+'
 
 test_expect_success 'generate builtin list' '
        git --list-cmds=builtins >builtins