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 <sebastien.guimmara@gmail.com>] Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Sébastien Guimmara <sebastien.guimmara@gmail.com> Reviewed-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed May 21, 2015 at 19:39 UTC 527ec3980bcf9868e2b726664f13532ac73d3c3f
3 files changed +52 -25
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.sh command-list.txt
1690 +common-cmds.h: generate-cmdlist.perl command-list.txt
1691
1692 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 $@+ $@
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 new
+50
@@ -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 deleted
-23
@@ -1,23 +0,0 @@
1 -#!/bin/sh
2 -
3 -echo "/* Automatically generated by $0 */
4 -struct cmdname_help {
5 - char name[16];
6 - char help[80];
7 -};
8 -
9 -static struct cmdname_help common_cmds[] = {"
10 -
11 -sed -n -e 's/^git-\([^ ]*\)[ ].* common.*/\1/p' command-list.txt |
12 -sort |
13 -while read cmd
14 -do
15 - sed -n '
16 - /^NAME/,/git-'"$cmd"'/H
17 - ${
18 - x
19 - s/.*git-'"$cmd"' - \(.*\)/ {"'"$cmd"'", N_("\1")},/
20 - p
21 - }' "Documentation/git-$cmd.txt"
22 -done
23 -echo "};"