Skip to content

Commit f318d73

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 75ba897 commit f318d73

File tree

4 files changed

+75
-10
lines changed

4 files changed

+75
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
/gitweb/static/gitweb.js
181181
/gitweb/static/gitweb.min.*
182182
/common-cmds.h
183+
/command-list.h
183184
*.tar.gz
184185
*.dsc
185186
*.deb

Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ LIB_FILE = libgit.a
757757
XDIFF_LIB = xdiff/lib.a
758758
VCSSVN_LIB = vcs-svn/lib.a
759759

760-
GENERATED_H += common-cmds.h
760+
GENERATED_H += common-cmds.h command-list.h
761761

762762
LIB_H = $(shell $(FIND) . \
763763
-name .git -prune -o \
@@ -1938,6 +1938,11 @@ $(BUILT_INS): git$X
19381938
common-cmds.h: generate-cmdlist.sh command-list.txt
19391939

19401940
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)
19411946
$(QUIET_GEN)$(SHELL_PATH) ./generate-cmdlist.sh command-list.txt >$@+ && mv $@+ $@
19421947

19431948
SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):$(GIT_VERSION):\
@@ -2148,7 +2153,7 @@ else
21482153
# Dependencies on header files, for platforms that do not support
21492154
# the gcc -MMD option.
21502155
#
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
21522157
# should _not_ be included here, since they are necessary even when
21532158
# building an object for the first time.
21542159

@@ -2527,7 +2532,7 @@ sparse: $(SP_OBJ)
25272532
style:
25282533
git clang-format --style file --diff --extensions c,h
25292534

2530-
check: common-cmds.h
2535+
check: common-cmds.h command-list.h
25312536
@if sparse; \
25322537
then \
25332538
echo >&2 "Use 'make sparse' instead"; \
@@ -2775,7 +2780,7 @@ clean: profile-clean coverage-clean
27752780
$(RM) $(TEST_PROGRAMS) $(NO_INSTALL)
27762781
$(RM) -r bin-wrappers $(dep_dirs)
27772782
$(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*
27792784
$(RM) -r $(GIT_TARNAME) .doc-tmp-dir
27802785
$(RM) $(GIT_TARNAME).tar.gz git-core_$(GIT_VERSION)-*.tar.gz
27812786
$(RM) $(htmldocs).tar.gz $(manpages).tar.gz

command-list.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ info examine the history and state (see also: git help revisions)
88
history grow, mark and tweak your common history
99
remote collaborate (see also: git help workflows)
1010

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]
1313
git-add mainporcelain worktree
1414
git-am mainporcelain
1515
git-annotate ancillaryinterrogators

generate-cmdlist.sh

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
#!/bin/sh
22

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+
325
get_synopsis () {
426
sed -n '
527
/^NAME/,/'"$1"'/H
@@ -10,14 +32,51 @@ get_synopsis () {
1032
}' "Documentation/$1.txt"
1133
}
1234

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+
1364
echo "/* Automatically generated by generate-cmdlist.sh */
1465
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;
1869
};
70+
"
71+
if test -z "$2"
72+
then
73+
define_categories "$1"
74+
echo
75+
print_command_list "$1"
76+
exit 0
77+
fi
1978

20-
static const char *common_cmd_groups[] = {"
79+
echo "static const char *common_cmd_groups[] = {"
2180

2281
grps=grps$$.tmp
2382
match=match$$.tmp

0 commit comments

Comments
 (0)