Skip to content

Commit 1b81d8c

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 63eae83 commit 1b81d8c

File tree

10 files changed

+54
-45
lines changed

10 files changed

+54
-45
lines changed

Documentation/gitattributes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ gitattributes(5)
33

44
NAME
55
----
6-
gitattributes - defining attributes per path
6+
gitattributes - Defining attributes per path
77

88
SYNOPSIS
99
--------

Documentation/gitmodules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ gitmodules(5)
33

44
NAME
55
----
6-
gitmodules - defining submodule properties
6+
gitmodules - Defining submodule properties
77

88
SYNOPSIS
99
--------

Documentation/gitrevisions.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ gitrevisions(7)
33

44
NAME
55
----
6-
gitrevisions - specifying revisions and ranges for Git
6+
gitrevisions - Specifying revisions and ranges for Git
77

88
SYNOPSIS
99
--------

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1937,7 +1937,7 @@ $(BUILT_INS): git$X
19371937

19381938
command-list.h: generate-cmdlist.sh command-list.txt
19391939

1940-
command-list.h: $(wildcard Documentation/git-*.txt)
1940+
command-list.h: $(wildcard Documentation/git*.txt)
19411941
$(QUIET_GEN)$(SHELL_PATH) ./generate-cmdlist.sh command-list.txt >$@+ && mv $@+ $@
19421942

19431943
SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\

builtin/help.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -402,38 +402,6 @@ static void show_html_page(const char *git_cmd)
402402
open_html(page_path.buf);
403403
}
404404

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-
437405
static const char *check_git_cmd(const char* cmd)
438406
{
439407
char *alias;

command-list.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,19 @@ gitweb ancillaryinterrogators
139139
git-whatchanged ancillaryinterrogators
140140
git-worktree mainporcelain
141141
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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,13 @@ _git_grep ()
15751575
__git_complete_refs
15761576
}
15771577

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+
15781585
_git_help ()
15791586
{
15801587
case "$cur" in
@@ -1584,11 +1591,9 @@ _git_help ()
15841591
;;
15851592
esac
15861593
__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
15921597
"
15931598
}
15941599

help.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ static struct category_description main_categories[] = {
3939
{ 0, NULL }
4040
};
4141

42-
static const char *drop_prefix(const char *name)
42+
static const char *drop_prefix(const char *name, uint32_t category)
4343
{
4444
const char *new_name;
4545

4646
if (skip_prefix(name, "git-", &new_name))
4747
return new_name;
48+
if (category == CAT_guide && skip_prefix(name, "git", &new_name))
49+
return new_name;
4850
return name;
4951

5052
}
@@ -66,7 +68,7 @@ static void extract_cmds(struct cmdname_help **p_cmds, uint32_t mask)
6668
continue;
6769

6870
cmds[nr] = *cmd;
69-
cmds[nr].name = drop_prefix(cmd->name);
71+
cmds[nr].name = drop_prefix(cmd->name, cmd->category);
7072

7173
nr++;
7274
}
@@ -358,11 +360,22 @@ void list_cmds_by_category(struct string_list *list,
358360
for (i = 0; i < n; i++) {
359361
struct cmdname_help *cmd = command_list + i;
360362

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));
363366
}
364367
}
365368

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+
366379
void list_all_cmds_help(void)
367380
{
368381
print_cmd_by_category(main_categories);

help.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ static inline void mput_char(char c, unsigned int num)
2020

2121
extern void list_common_cmds_help(void);
2222
extern void list_all_cmds_help(void);
23+
extern void list_common_guides_help(void);
2324

2425
extern void list_all_main_cmds(struct string_list *list);
2526
extern void list_all_other_cmds(struct string_list *list);

t/t0012-help.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ test_expect_success 'git help' '
6666
test_i18ngrep "^ commit " help.output &&
6767
test_i18ngrep "^ fetch " help.output
6868
'
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+
'
6975

7076
test_expect_success 'generate builtin list' '
7177
git --list-cmds=builtins >builtins

0 commit comments

Comments
 (0)