Skip to content

Commit 527ec39

Browse files
sunshinecogitster
authored andcommitted
generate-cmdlist: parse common group commands
Parse the group block to create the array of group descriptions: static char *common_cmd_groups[] = { N_("starting a working area"), N_("working on the current change"), N_("working with others"), N_("examining the history and state"), N_("growing, marking and tweaking your history"), }; then map each element of common_cmds[] to a group via its index: static struct cmdname_help common_cmds[] = { {"add", N_("Add file contents to the index"), 1}, {"branch", N_("List, create, or delete branches"), 4}, {"checkout", N_("Checkout a branch or paths to the ..."), 4}, {"clone", N_("Clone a repository into a new directory"), 0}, {"commit", N_("Record changes to the repository"), 4}, ... }; so that 'git help' can print those commands grouped by theme. Only commands tagged with an attribute from the group block are emitted to common_cmds[]. [commit message by Sébastien Guimmara <[email protected]>] Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Sébastien Guimmara <[email protected]> Reviewed-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 413f50b commit 527ec39

File tree

3 files changed

+52
-25
lines changed

3 files changed

+52
-25
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,10 +1687,10 @@ $(BUILT_INS): git$X
16871687
ln -s $< $@ 2>/dev/null || \
16881688
cp $< $@
16891689

1690-
common-cmds.h: ./generate-cmdlist.sh command-list.txt
1690+
common-cmds.h: generate-cmdlist.perl command-list.txt
16911691

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

16951695
SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
16961696
$(localedir_SQ):$(NO_CURL):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\

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.

0 commit comments

Comments
 (0)