Skip to content

Commit 6dec263

Browse files
committed
Merge branch 'sg/help-group'
Group list of commands shown by "git help" along the workflow elements to help early learners. * sg/help-group: help: respect new common command grouping command-list.txt: drop the "common" tag generate-cmdlist: parse common group commands command-list.txt: add the common groups block command-list: prepare machinery for upcoming "common groups" section
2 parents abcbafe + 2241477 commit 6dec263

File tree

7 files changed

+117
-51
lines changed

7 files changed

+117
-51
lines changed

Documentation/cmd-list.perl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ sub format_one {
3838
}
3939
}
4040

41+
while (<>) {
42+
last if /^### command list/;
43+
}
44+
4145
my %cmds = ();
4246
for (sort <>) {
4347
next if /^#/;

Documentation/howto/new-command.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ your language, document it in the INSTALL file.
9595
that categorizes commands by type, so they can be listed in appropriate
9696
subsections in the documentation's summary command list. Add an entry
9797
for yours. To understand the categories, look at git-commands.txt
98-
in the main directory.
98+
in the main directory. If the new command is part of the typical Git
99+
workflow and you believe it common enough to be mentioned in 'git help',
100+
map this command to a common group in the column [common].
99101

100102
7. Give the maintainer one paragraph to include in the RelNotes file
101103
to describe the new feature; a good place to do so is in the cover

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,10 +1694,10 @@ $(BUILT_INS): git$X
16941694
ln -s $< $@ 2>/dev/null || \
16951695
cp $< $@
16961696

1697-
common-cmds.h: ./generate-cmdlist.sh command-list.txt
1697+
common-cmds.h: generate-cmdlist.perl command-list.txt
16981698

16991699
common-cmds.h: $(wildcard Documentation/git-*.txt)
1700-
$(QUIET_GEN)./generate-cmdlist.sh > $@+ && mv $@+ $@
1700+
$(QUIET_GEN)$(PERL_PATH) generate-cmdlist.perl command-list.txt > $@+ && mv $@+ $@
17011701

17021702
SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
17031703
$(localedir_SQ):$(NO_CURL):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\
@@ -2455,15 +2455,16 @@ check-docs::
24552455
esac ; \
24562456
test -f "Documentation/$$v.txt" || \
24572457
echo "no doc: $$v"; \
2458-
sed -e '/^#/d' command-list.txt | \
2458+
sed -e '1,/^### command list/d' -e '/^#/d' command-list.txt | \
24592459
grep -q "^$$v[ ]" || \
24602460
case "$$v" in \
24612461
git) ;; \
24622462
*) echo "no link: $$v";; \
24632463
esac ; \
24642464
done; \
24652465
( \
2466-
sed -e '/^#/d' \
2466+
sed -e '1,/^### command list/d' \
2467+
-e '/^#/d' \
24672468
-e 's/[ ].*//' \
24682469
-e 's/^/listed /' command-list.txt; \
24692470
$(MAKE) -C Documentation print-man1 | \

command-list.txt

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
1-
# List of known git commands.
1+
# common commands are grouped by themes
2+
# these groups are output by 'git help' in the order declared here.
3+
# map each common command in the command list to one of these groups.
4+
### common groups (do not change this line)
5+
init start a working area (see also: git help tutorial)
6+
worktree work on the current change (see also: git help everyday)
7+
info examine the history and state (see also: git help revisions)
8+
history grow, mark and tweak your common history
9+
remote collaborate (see also: git help workflows)
10+
11+
### command list (do not change this line)
212
# command name category [deprecated] [common]
3-
git-add mainporcelain common
13+
git-add mainporcelain worktree
414
git-am mainporcelain
515
git-annotate ancillaryinterrogators
616
git-apply plumbingmanipulators
717
git-archimport foreignscminterface
818
git-archive mainporcelain
9-
git-bisect mainporcelain common
19+
git-bisect mainporcelain info
1020
git-blame ancillaryinterrogators
11-
git-branch mainporcelain common
21+
git-branch mainporcelain history
1222
git-bundle mainporcelain
1323
git-cat-file plumbinginterrogators
1424
git-check-attr purehelpers
1525
git-check-ignore purehelpers
1626
git-check-mailmap purehelpers
17-
git-checkout mainporcelain common
27+
git-checkout mainporcelain history
1828
git-checkout-index plumbingmanipulators
1929
git-check-ref-format purehelpers
2030
git-cherry ancillaryinterrogators
2131
git-cherry-pick mainporcelain
2232
git-citool mainporcelain
2333
git-clean mainporcelain
24-
git-clone mainporcelain common
34+
git-clone mainporcelain init
2535
git-column purehelpers
26-
git-commit mainporcelain common
36+
git-commit mainporcelain history
2737
git-commit-tree plumbingmanipulators
2838
git-config ancillarymanipulators
2939
git-count-objects ancillaryinterrogators
@@ -35,14 +45,14 @@ git-cvsimport foreignscminterface
3545
git-cvsserver foreignscminterface
3646
git-daemon synchingrepositories
3747
git-describe mainporcelain
38-
git-diff mainporcelain common
48+
git-diff mainporcelain history
3949
git-diff-files plumbinginterrogators
4050
git-diff-index plumbinginterrogators
4151
git-diff-tree plumbinginterrogators
4252
git-difftool ancillaryinterrogators
4353
git-fast-export ancillarymanipulators
4454
git-fast-import ancillarymanipulators
45-
git-fetch mainporcelain common
55+
git-fetch mainporcelain remote
4656
git-fetch-pack synchingrepositories
4757
git-filter-branch ancillarymanipulators
4858
git-fmt-merge-msg purehelpers
@@ -51,7 +61,7 @@ git-format-patch mainporcelain
5161
git-fsck ancillaryinterrogators
5262
git-gc mainporcelain
5363
git-get-tar-commit-id ancillaryinterrogators
54-
git-grep mainporcelain common
64+
git-grep mainporcelain info
5565
git-gui mainporcelain
5666
git-hash-object plumbingmanipulators
5767
git-help ancillaryinterrogators
@@ -60,17 +70,17 @@ git-http-fetch synchelpers
6070
git-http-push synchelpers
6171
git-imap-send foreignscminterface
6272
git-index-pack plumbingmanipulators
63-
git-init mainporcelain common
73+
git-init mainporcelain init
6474
git-instaweb ancillaryinterrogators
6575
git-interpret-trailers purehelpers
6676
gitk mainporcelain
67-
git-log mainporcelain common
77+
git-log mainporcelain info
6878
git-ls-files plumbinginterrogators
6979
git-ls-remote plumbinginterrogators
7080
git-ls-tree plumbinginterrogators
7181
git-mailinfo purehelpers
7282
git-mailsplit purehelpers
73-
git-merge mainporcelain common
83+
git-merge mainporcelain history
7484
git-merge-base plumbinginterrogators
7585
git-merge-file plumbingmanipulators
7686
git-merge-index plumbingmanipulators
@@ -79,7 +89,7 @@ git-mergetool ancillarymanipulators
7989
git-merge-tree ancillaryinterrogators
8090
git-mktag plumbingmanipulators
8191
git-mktree plumbingmanipulators
82-
git-mv mainporcelain common
92+
git-mv mainporcelain worktree
8393
git-name-rev plumbinginterrogators
8494
git-notes mainporcelain
8595
git-p4 foreignscminterface
@@ -90,11 +100,11 @@ git-parse-remote synchelpers
90100
git-patch-id purehelpers
91101
git-prune ancillarymanipulators
92102
git-prune-packed plumbingmanipulators
93-
git-pull mainporcelain common
94-
git-push mainporcelain common
103+
git-pull mainporcelain remote
104+
git-push mainporcelain remote
95105
git-quiltimport foreignscminterface
96106
git-read-tree plumbingmanipulators
97-
git-rebase mainporcelain common
107+
git-rebase mainporcelain history
98108
git-receive-pack synchelpers
99109
git-reflog ancillarymanipulators
100110
git-relink ancillarymanipulators
@@ -103,28 +113,28 @@ git-repack ancillarymanipulators
103113
git-replace ancillarymanipulators
104114
git-request-pull foreignscminterface
105115
git-rerere ancillaryinterrogators
106-
git-reset mainporcelain common
116+
git-reset mainporcelain worktree
107117
git-revert mainporcelain
108118
git-rev-list plumbinginterrogators
109119
git-rev-parse ancillaryinterrogators
110-
git-rm mainporcelain common
120+
git-rm mainporcelain worktree
111121
git-send-email foreignscminterface
112122
git-send-pack synchingrepositories
113123
git-shell synchelpers
114124
git-shortlog mainporcelain
115-
git-show mainporcelain common
125+
git-show mainporcelain info
116126
git-show-branch ancillaryinterrogators
117127
git-show-index plumbinginterrogators
118128
git-show-ref plumbinginterrogators
119129
git-sh-i18n purehelpers
120130
git-sh-setup purehelpers
121131
git-stash mainporcelain
122-
git-status mainporcelain common
132+
git-status mainporcelain info
123133
git-stripspace purehelpers
124134
git-submodule mainporcelain
125135
git-svn foreignscminterface
126136
git-symbolic-ref plumbingmanipulators
127-
git-tag mainporcelain common
137+
git-tag mainporcelain history
128138
git-unpack-file plumbinginterrogators
129139
git-unpack-objects plumbingmanipulators
130140
git-update-index plumbingmanipulators

generate-cmdlist.perl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
use warnings;
4+
5+
print <<"EOT";
6+
/* Automatically generated by $0 */
7+
8+
struct cmdname_help {
9+
char name[16];
10+
char help[80];
11+
unsigned char group;
12+
};
13+
14+
static char *common_cmd_groups[] = {
15+
EOT
16+
17+
my $n = 0;
18+
my %grp;
19+
while (<>) {
20+
last if /^### command list/;
21+
next if (1../^### common groups/) || /^#/ || /^\s*$/;
22+
chop;
23+
my ($k, $v) = split ' ', $_, 2;
24+
$grp{$k} = $n++;
25+
print "\tN_(\"$v\"),\n";
26+
}
27+
28+
print "};\n\nstatic struct cmdname_help common_cmds[] = {\n";
29+
30+
while (<>) {
31+
next if /^#/ || /^\s*$/;
32+
my @tags = split;
33+
my $cmd = shift @tags;
34+
for my $t (@tags) {
35+
if (exists $grp{$t}) {
36+
my $s;
37+
open my $f, '<', "Documentation/$cmd.txt" or die;
38+
while (<$f>) {
39+
($s) = /^$cmd - (.+)$/;
40+
last if $s;
41+
}
42+
close $f;
43+
$cmd =~ s/^git-//;
44+
print "\t{\"$cmd\", N_(\"$s\"), $grp{$t}},\n";
45+
last;
46+
}
47+
}
48+
}
49+
50+
print "};\n";

generate-cmdlist.sh

Lines changed: 0 additions & 23 deletions
This file was deleted.

help.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,39 @@ void list_commands(unsigned int colopts,
218218
}
219219
}
220220

221+
static int cmd_group_cmp(const void *elem1, const void *elem2)
222+
{
223+
const struct cmdname_help *e1 = elem1;
224+
const struct cmdname_help *e2 = elem2;
225+
226+
if (e1->group < e2->group)
227+
return -1;
228+
if (e1->group > e2->group)
229+
return 1;
230+
return strcmp(e1->name, e2->name);
231+
}
232+
221233
void list_common_cmds_help(void)
222234
{
223235
int i, longest = 0;
236+
int current_grp = -1;
224237

225238
for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
226239
if (longest < strlen(common_cmds[i].name))
227240
longest = strlen(common_cmds[i].name);
228241
}
229242

230-
puts(_("The most commonly used git commands are:"));
243+
qsort(common_cmds, ARRAY_SIZE(common_cmds),
244+
sizeof(common_cmds[0]), cmd_group_cmp);
245+
246+
puts(_("These are common Git commands used in various situations:"));
247+
231248
for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
249+
if (common_cmds[i].group != current_grp) {
250+
printf("\n%s\n", _(common_cmd_groups[common_cmds[i].group]));
251+
current_grp = common_cmds[i].group;
252+
}
253+
232254
printf(" %s ", common_cmds[i].name);
233255
mput_char(' ', longest - strlen(common_cmds[i].name));
234256
puts(_(common_cmds[i].help));

0 commit comments

Comments
 (0)