From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"SZEDER Gábor" <szeder.dev@gmail.com>,
"Eric Sunshine" <sunshine@sunshineco.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 10/17] help: use command-list.txt for the source of guides
Date: Sun, 20 May 2018 20:40:02 +0200 [thread overview]
Message-ID: <20180520184009.976-11-pclouds@gmail.com> (raw)
In-Reply-To: <20180520184009.976-1-pclouds@gmail.com>
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>
---
Documentation/gitattributes.txt | 2 +-
Documentation/gitmodules.txt | 2 +-
Documentation/gitrevisions.txt | 2 +-
Makefile | 2 +-
builtin/help.c | 32 --------------------------
command-list.txt | 16 +++++++++++++
contrib/completion/git-completion.bash | 15 ++++++++----
help.c | 21 +++++++++++++----
help.h | 1 +
t/t0012-help.sh | 6 +++++
10 files changed, 54 insertions(+), 45 deletions(-)
diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 1094fe2b5b..083c2f380d 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -3,7 +3,7 @@ gitattributes(5)
NAME
----
-gitattributes - defining attributes per path
+gitattributes - Defining attributes per path
SYNOPSIS
--------
diff --git a/Documentation/gitmodules.txt b/Documentation/gitmodules.txt
index db5d47eb19..4d63def206 100644
--- a/Documentation/gitmodules.txt
+++ b/Documentation/gitmodules.txt
@@ -3,7 +3,7 @@ gitmodules(5)
NAME
----
-gitmodules - defining submodule properties
+gitmodules - Defining submodule properties
SYNOPSIS
--------
diff --git a/Documentation/gitrevisions.txt b/Documentation/gitrevisions.txt
index 27dec5b91d..1f6cceaefb 100644
--- a/Documentation/gitrevisions.txt
+++ b/Documentation/gitrevisions.txt
@@ -3,7 +3,7 @@ gitrevisions(7)
NAME
----
-gitrevisions - specifying revisions and ranges for Git
+gitrevisions - Specifying revisions and ranges for Git
SYNOPSIS
--------
diff --git a/Makefile b/Makefile
index a60a78ee67..1efb751e46 100644
--- 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):\
diff --git a/builtin/help.c b/builtin/help.c
index 0e0af8426a..5727fb5e51 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -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;
diff --git a/command-list.txt b/command-list.txt
index 3bd23201a6..99ddc231c1 100644
--- a/command-list.txt
+++ b/command-list.txt
@@ -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
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 62ca8641f4..4e724a5b76 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -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 c7df1d2338..23924dd300 100644
--- 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 40917fc38c..b2293e99be 100644
--- 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);
diff --git a/t/t0012-help.sh b/t/t0012-help.sh
index 060df24c2d..bc27df7f38 100755
--- a/t/t0012-help.sh
+++ b/t/t0012-help.sh
@@ -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
--
2.17.0.705.g3525833791
next prev parent reply other threads:[~2018-05-20 18:40 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-19 4:27 [PATCH 00/14] nd/command-list updates Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 01/14] generate-cmds.sh: factor out synopsis extract code Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 02/14] generate-cmds.sh: export all commands to command-list.h Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 03/14] help: use command-list.h for common command list Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 04/14] Remove common-cmds.h Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 05/14] git.c: convert --list-* to --list-cmds=* Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 06/14] git --list-cmds: collect command list in a string_list Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 07/14] completion: implement and use --list-cmds=main,others Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 08/14] git: support --list-cmds=list-<category> Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 09/14] help: add "-a --verbose" to list all commands with synopsis Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 10/14] help: use command-list.txt for the source of guides Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 11/14] command-list.txt: documentation and guide line Nguyễn Thái Ngọc Duy
2018-05-19 4:27 ` [PATCH 12/14] completion: let git provide the completable command list Nguyễn Thái Ngọc Duy
2018-05-20 13:20 ` SZEDER Gábor
2018-05-20 15:57 ` Duy Nguyen
2018-05-19 4:27 ` [PATCH 13/14] completion: reduce " Nguyễn Thái Ngọc Duy
2018-05-20 13:24 ` SZEDER Gábor
2018-05-21 1:06 ` Junio C Hamano
2018-05-19 4:27 ` [PATCH 14/14] completion: allow to customize the " Nguyễn Thái Ngọc Duy
2018-05-20 14:27 ` SZEDER Gábor
2018-05-20 15:52 ` Duy Nguyen
2018-05-20 18:39 ` [PATCH v2 00/17] nd/command-list updates Nguyễn Thái Ngọc Duy
2018-05-20 18:39 ` [PATCH v2 01/17] generate-cmds.sh: factor out synopsis extract code Nguyễn Thái Ngọc Duy
2018-05-20 18:39 ` [PATCH v2 02/17] generate-cmds.sh: export all commands to command-list.h Nguyễn Thái Ngọc Duy
2018-05-20 18:39 ` [PATCH v2 03/17] help: use command-list.h for common command list Nguyễn Thái Ngọc Duy
2018-05-20 18:39 ` [PATCH v2 04/17] Remove common-cmds.h Nguyễn Thái Ngọc Duy
2018-05-20 18:39 ` [PATCH v2 05/17] git.c: convert --list-* to --list-cmds=* Nguyễn Thái Ngọc Duy
2018-05-20 18:39 ` [PATCH v2 06/17] git --list-cmds: collect command list in a string_list Nguyễn Thái Ngọc Duy
2018-05-20 18:39 ` [PATCH v2 07/17] completion: implement and use --list-cmds=main,others Nguyễn Thái Ngọc Duy
2018-05-20 18:40 ` [PATCH v2 08/17] git: support --list-cmds=list-<category> Nguyễn Thái Ngọc Duy
2018-05-20 18:40 ` [PATCH v2 09/17] help: add "-a --verbose" to list all commands with synopsis Nguyễn Thái Ngọc Duy
2018-05-20 18:40 ` Nguyễn Thái Ngọc Duy [this message]
2018-11-20 19:34 ` [PATCH v2 10/17] help: use command-list.txt for the source of guides Ævar Arnfjörð Bjarmason
2018-05-20 18:40 ` [PATCH v2 11/17] command-list.txt: documentation and guide line Nguyễn Thái Ngọc Duy
2018-05-20 18:40 ` [PATCH v2 12/17] completion: let git provide the completable command list Nguyễn Thái Ngọc Duy
2018-05-20 18:40 ` [PATCH v2 13/17] completion: reduce " Nguyễn Thái Ngọc Duy
2018-05-20 18:40 ` [PATCH v2 14/17] Move declaration for alias.c to alias.h Nguyễn Thái Ngọc Duy
2018-05-20 18:40 ` [PATCH v2 15/17] completion: add and use --list-cmds=nohelpers Nguyễn Thái Ngọc Duy
2018-05-20 18:40 ` [PATCH v2 16/17] completion: add and use --list-cmds=alias Nguyễn Thái Ngọc Duy
2018-05-20 18:40 ` [PATCH v2 17/17] completion: allow to customize the completable command list Nguyễn Thái Ngọc Duy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180520184009.976-11-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=sunshine@sunshineco.com \
--cc=szeder.dev@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).