generate-cmdlist: re-implement as shell script

527ec39 (generate-cmdlist: parse common group commands, 2015-05-21) replaced generate-cmdlist.sh with a more functional Perl version, generate-cmdlist.perl. The Perl version gleans named tags from a new "common groups" section in command-list.txt and recognizes those tags in "command list" section entries in place of the old 'common' tag. This allows git-help to, not only recognize, but also group common commands. Although the tests require Perl, 527ec39 creates an unconditional dependence upon Perl in the build system itself, which can not be overridden with NO_PERL. Such a dependency may be undesirable; for instance, the 'git-lite' package in the FreeBSD ports tree is intended as a minimal Git installation (which may, for example, be useful on servers needing only local clone and update capability), which, historically, has not depended upon Perl[1]. Therefore, revive generate-cmdlist.sh and extend it to recognize "common groups" and its named tags. Retire generate-cmdlist.perl. [1]: http://thread.gmane.org/gmane.comp.version-control.git/275905/focus=276132 Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Aug 23, 2015 at 17:31 UTC 82aec45b7d9dd235b6a490d2c93600e13c36c40d
3 files changed +52 -52
Makefile
+2 -2
@@ -1687,10 +1687,10 @@ $(BUILT_INS): git$X
1687 ln -s $< $@ 2>/dev/null || \
1688 cp $< $@
1689
1690 -common-cmds.h: generate-cmdlist.perl command-list.txt
1690 +common-cmds.h: generate-cmdlist.sh command-list.txt
1691
1692 common-cmds.h: $(wildcard Documentation/git-*.txt)
1693 - $(QUIET_GEN)$(PERL_PATH) generate-cmdlist.perl command-list.txt > $@+ && mv $@+ $@
1693 + $(QUIET_GEN)./generate-cmdlist.sh command-list.txt >$@+ && mv $@+ $@
1694
1695 SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
1696 $(localedir_SQ):$(NO_CURL):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\
generate-cmdlist.perl deleted
-50
@@ -1,50 +0,0 @@
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 new
+50
@@ -0,0 +1,50 @@
1 +#!/bin/sh
2 +
3 +echo "/* Automatically generated by $0 */
4 +struct cmdname_help {
5 + char name[16];
6 + char help[80];
7 + unsigned char group;
8 +};
9 +
10 +static const char *common_cmd_groups[] = {"
11 +
12 +grps=grps$$.tmp
13 +match=match$$.tmp
14 +trap "rm -f '$grps' '$match'" 0 1 2 3 15
15 +
16 +sed -n '
17 + 1,/^### common groups/b
18 + /^### command list/q
19 + /^#/b
20 + /^[ ]*$/b
21 + h;s/^[^ ][^ ]*[ ][ ]*\(.*\)/ N_("\1"),/p
22 + g;s/^\([^ ][^ ]*\)[ ].*/\1/w '$grps'
23 + ' "$1"
24 +printf '};\n\n'
25 +
26 +n=0
27 +substnum=
28 +while read grp
29 +do
30 + echo "^git-..*[ ]$grp"
31 + substnum="$substnum${substnum:+;}s/[ ]$grp/$n/"
32 + n=$(($n+1))
33 +done <"$grps" >"$match"
34 +
35 +printf 'static struct cmdname_help common_cmds[] = {\n'
36 +grep -f "$match" "$1" |
37 +sed 's/^git-//' |
38 +sort |
39 +while read cmd tags
40 +do
41 + tag=$(echo "$tags" | sed "$substnum; s/[^0-9]//g")
42 + sed -n '
43 + /^NAME/,/git-'"$cmd"'/H
44 + ${
45 + x
46 + s/.*git-'"$cmd"' - \(.*\)/ {"'"$cmd"'", N_("\1"), '$tag'},/
47 + p
48 + }' "Documentation/git-$cmd.txt"
49 +done
50 +echo "};"