generate-cmds.sh: export all commands to command-list.h

The current generate-cmds.sh generates just enough to print "git help" output. That is, it only extracts help text for common commands. The script is now updated to extract help text for all commands and keep command classification a new file, command-list.h. This will be useful later: - "git help -a" could print a short summary of all commands instead of just the common ones. - "git" could produce a list of commands of one or more category. One of its use is to reduce another command classification embedded in git-completion.bash. The new file can be generated but is not used anywhere yet. The plan is we migrate away from common-cmds.h. Then we can kill off common-cmds.h build rules and generation code (and also delete duplicate content in command-list.h which we keep for now to not mess generate-cmds.sh up too much). PS. The new fixed column requirement on command-list.txt is technically not needed. But it helps simplify the code a bit at this stage. We could lift this restriction later if we want to. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed May 10, 2018 at 10:46 UTC f318d7391592f153d1682d01ebaa2d35e3b6ede7
4 files changed +75 -10
.gitignore
+1
@@ -180,6 +180,7 @@
180 /gitweb/static/gitweb.js
181 /gitweb/static/gitweb.min.*
182 /common-cmds.h
183 +/command-list.h
184 *.tar.gz
185 *.dsc
186 *.deb
Makefile
+9 -4
@@ -757,7 +757,7 @@ LIB_FILE = libgit.a
757 XDIFF_LIB = xdiff/lib.a
758 VCSSVN_LIB = vcs-svn/lib.a
759
760 -GENERATED_H += common-cmds.h
760 +GENERATED_H += common-cmds.h command-list.h
761
762 LIB_H = $(shell $(FIND) . \
763 -name .git -prune -o \
@@ -1938,6 +1938,11 @@ $(BUILT_INS): git$X
1938 common-cmds.h: generate-cmdlist.sh command-list.txt
1939
1940 common-cmds.h: $(wildcard Documentation/git-*.txt)
1941 + $(QUIET_GEN)$(SHELL_PATH) ./generate-cmdlist.sh command-list.txt COMMON >$@+ && mv $@+ $@
1942 +
1943 +command-list.h: generate-cmdlist.sh command-list.txt
1944 +
1945 +command-list.h: $(wildcard Documentation/git-*.txt)
1946 $(QUIET_GEN)$(SHELL_PATH) ./generate-cmdlist.sh command-list.txt >$@+ && mv $@+ $@
1947
1948 SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
@@ -2148,7 +2153,7 @@ else
2153 # Dependencies on header files, for platforms that do not support
2154 # the gcc -MMD option.
2155 #
2151 -# Dependencies on automatically generated headers such as common-cmds.h
2156 +# Dependencies on automatically generated headers such as common-cmds.h or command-list.h
2157 # should _not_ be included here, since they are necessary even when
2158 # building an object for the first time.
2159
@@ -2527,7 +2532,7 @@ sparse: $(SP_OBJ)
2532 style:
2533 git clang-format --style file --diff --extensions c,h
2534
2530 -check: common-cmds.h
2535 +check: common-cmds.h command-list.h
2536 @if sparse; \
2537 then \
2538 echo >&2 "Use 'make sparse' instead"; \
@@ -2775,7 +2780,7 @@ clean: profile-clean coverage-clean
2780 $(RM) $(TEST_PROGRAMS) $(NO_INSTALL)
2781 $(RM) -r bin-wrappers $(dep_dirs)
2782 $(RM) -r po/build/
2778 - $(RM) *.pyc *.pyo */*.pyc */*.pyo common-cmds.h $(ETAGS_TARGET) tags cscope*
2783 + $(RM) *.pyc *.pyo */*.pyc */*.pyo common-cmds.h command-list.h $(ETAGS_TARGET) tags cscope*
2784 $(RM) -r $(GIT_TARNAME) .doc-tmp-dir
2785 $(RM) $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz
2786 $(RM) $(htmldocs).tar.gz $(manpages).tar.gz
command-list.txt
+2 -2
@@ -8,8 +8,8 @@ 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)
12 -# command name category [deprecated] [common]
11 +### command list (do not change this line, also do not change alignment)
12 +# command name category [category] [category]
13 git-add mainporcelain worktree
14 git-am mainporcelain
15 git-annotate ancillaryinterrogators
generate-cmdlist.sh
+63 -4
@@ -1,5 +1,27 @@
1 #!/bin/sh
2
3 +die () {
4 + echo "$@" >&2
5 + exit 1
6 +}
7 +
8 +command_list () {
9 + sed '1,/^### command list/d;/^#/d' "$1"
10 +}
11 +
12 +get_categories () {
13 + tr ' ' '\n'|
14 + grep -v '^$' |
15 + sort |
16 + uniq
17 +}
18 +
19 +category_list () {
20 + command_list "$1" |
21 + cut -c 40- |
22 + get_categories
23 +}
24 +
25 get_synopsis () {
26 sed -n '
27 /^NAME/,/'"$1"'/H
@@ -10,14 +32,51 @@ get_synopsis () {
32 }' "Documentation/$1.txt"
33 }
34
35 +define_categories () {
36 + echo
37 + echo "/* Command categories */"
38 + bit=0
39 + category_list "$1" |
40 + while read cat
41 + do
42 + echo "#define CAT_$cat (1UL << $bit)"
43 + bit=$(($bit+1))
44 + done
45 + test "$bit" -gt 32 && die "Urgh.. too many categories?"
46 +}
47 +
48 +print_command_list () {
49 + echo "static struct cmdname_help command_list[] = {"
50 +
51 + command_list "$1" |
52 + while read cmd rest
53 + do
54 + printf " { \"$cmd\", $(get_synopsis $cmd), 0"
55 + for cat in $(echo "$rest" | get_categories)
56 + do
57 + printf " | CAT_$cat"
58 + done
59 + echo " },"
60 + done
61 + echo "};"
62 +}
63 +
64 echo "/* Automatically generated by generate-cmdlist.sh */
65 struct cmdname_help {
15 - char name[16];
16 - char help[80];
17 - unsigned char group;
66 + const char *name;
67 + const char *help;
68 + uint32_t group;
69 };
70 +"
71 +if test -z "$2"
72 +then
73 + define_categories "$1"
74 + echo
75 + print_command_list "$1"
76 + exit 0
77 +fi
78
20 -static const char *common_cmd_groups[] = {"
79 +echo "static const char *common_cmd_groups[] = {"
80
81 grps=grps$$.tmp
82 match=match$$.tmp