Merge branch 'ab/generate-command-list'

Build optimization.

* ab/generate-command-list:
  generate-cmdlist.sh: don't parse command-list.txt thrice
  generate-cmdlist.sh: replace "grep' invocation with a shell version
  generate-cmdlist.sh: do not shell out to "sed"
  generate-cmdlist.sh: stop sorting category lines
  generate-cmdlist.sh: replace for loop by printf's auto-repeat feature
  generate-cmdlist.sh: run "grep | sort", not "sort | grep"
  generate-cmdlist.sh: don't call get_categories() from category_list()
  generate-cmdlist.sh: spawn fewer processes
  generate-cmdlist.sh: trivial whitespace change
  command-list.txt: sort with "LC_ALL=C sort"
This commit is contained in:
Junio C Hamano 2021-12-10 14:35:08 -08:00
commit d1305bd3cf
2 changed files with 56 additions and 44 deletions

View File

@ -43,7 +43,7 @@
# specified here, which can only have "guide" attribute and nothing
# else.
#
### command list (do not change this line, also do not change alignment)
### command list (do not change this line)
# command name category [category] [category]
git-add mainporcelain worktree
git-am mainporcelain
@ -60,9 +60,9 @@ git-cat-file plumbinginterrogators
git-check-attr purehelpers
git-check-ignore purehelpers
git-check-mailmap purehelpers
git-check-ref-format purehelpers
git-checkout mainporcelain
git-checkout-index plumbingmanipulators
git-check-ref-format purehelpers
git-cherry plumbinginterrogators complete
git-cherry-pick mainporcelain
git-citool mainporcelain
@ -111,7 +111,6 @@ git-index-pack plumbingmanipulators
git-init mainporcelain init
git-instaweb ancillaryinterrogators complete
git-interpret-trailers purehelpers
gitk mainporcelain
git-log mainporcelain info
git-ls-files plumbinginterrogators
git-ls-remote plumbinginterrogators
@ -124,11 +123,11 @@ git-merge-base plumbinginterrogators
git-merge-file plumbingmanipulators
git-merge-index plumbingmanipulators
git-merge-one-file purehelpers
git-mergetool ancillarymanipulators complete
git-merge-tree ancillaryinterrogators
git-multi-pack-index plumbingmanipulators
git-mergetool ancillarymanipulators complete
git-mktag plumbingmanipulators
git-mktree plumbingmanipulators
git-multi-pack-index plumbingmanipulators
git-mv mainporcelain worktree
git-name-rev plumbinginterrogators
git-notes mainporcelain
@ -154,23 +153,23 @@ git-request-pull foreignscminterface complete
git-rerere ancillaryinterrogators
git-reset mainporcelain history
git-restore mainporcelain worktree
git-revert mainporcelain
git-rev-list plumbinginterrogators
git-rev-parse plumbinginterrogators
git-revert mainporcelain
git-rm mainporcelain worktree
git-send-email foreignscminterface complete
git-send-pack synchingrepositories
git-sh-i18n purehelpers
git-sh-setup purehelpers
git-shell synchelpers
git-shortlog mainporcelain
git-show mainporcelain info
git-show-branch ancillaryinterrogators complete
git-show-index plumbinginterrogators
git-show-ref plumbinginterrogators
git-sh-i18n purehelpers
git-sh-setup purehelpers
git-sparse-checkout mainporcelain
git-stash mainporcelain
git-stage complete
git-stash mainporcelain
git-status mainporcelain info
git-stripspace purehelpers
git-submodule mainporcelain
@ -189,7 +188,6 @@ git-var plumbinginterrogators
git-verify-commit ancillaryinterrogators
git-verify-pack plumbinginterrogators
git-verify-tag ancillaryinterrogators
gitweb ancillaryinterrogators
git-whatchanged ancillaryinterrogators complete
git-worktree mainporcelain
git-write-tree plumbingmanipulators
@ -204,6 +202,7 @@ gitfaq guide
gitglossary guide
githooks guide
gitignore guide
gitk mainporcelain
gitmailmap guide
gitmodules guide
gitnamespaces guide
@ -211,6 +210,7 @@ gitremote-helpers guide
gitrepository-layout guide
gitrevisions guide
gitsubmodules guide
gittutorial-2 guide
gittutorial guide
gittutorial-2 guide
gitweb ancillaryinterrogators
gitworkflows guide

View File

@ -6,37 +6,38 @@ die () {
}
command_list () {
eval "grep -ve '^#' $exclude_programs" <"$1"
}
get_categories () {
tr ' ' '\012'|
grep -v '^$' |
sort |
uniq
while read cmd rest
do
case "$cmd" in
"#"* | '')
# Ignore comments and allow empty lines
continue
;;
*)
case "$exclude_programs" in
*":$cmd:"*)
;;
*)
echo "$cmd $rest"
;;
esac
esac
done <"$1"
}
category_list () {
command_list "$1" |
cut -c 40- |
get_categories
}
get_synopsis () {
sed -n '
/^NAME/,/'"$1"'/H
${
x
s/.*'"$1"' - \(.*\)/N_("\1")/
p
}' "Documentation/$1.txt"
echo "$1" |
cut -d' ' -f2- |
tr ' ' '\012' |
grep -v '^$' |
LC_ALL=C sort -u
}
define_categories () {
echo
echo "/* Command categories */"
bit=0
category_list "$1" |
echo "$1" |
while read cat
do
echo "#define CAT_$cat (1UL << $bit)"
@ -50,7 +51,7 @@ define_category_names () {
echo "/* Category names */"
echo "static const char *category_names[] = {"
bit=0
category_list "$1" |
echo "$1" |
while read cat
do
echo " \"$cat\", /* (1UL << $bit) */"
@ -63,27 +64,38 @@ define_category_names () {
print_command_list () {
echo "static struct cmdname_help command_list[] = {"
command_list "$1" |
echo "$1" |
while read cmd rest
do
printf " { \"$cmd\", $(get_synopsis $cmd), 0"
for cat in $(echo "$rest" | get_categories)
synopsis=
while read line
do
printf " | CAT_$cat"
done
case "$line" in
"$cmd - "*)
synopsis=${line#$cmd - }
break
;;
esac
done <"Documentation/$cmd.txt"
printf '\t{ "%s", N_("%s"), 0' "$cmd" "$synopsis"
printf " | CAT_%s" $rest
echo " },"
done
echo "};"
}
exclude_programs=
exclude_programs=:
while test "--exclude-program" = "$1"
do
shift
exclude_programs="$exclude_programs -e \"^$1 \""
exclude_programs="$exclude_programs$1:"
shift
done
commands="$(command_list "$1")"
categories="$(category_list "$commands")"
echo "/* Automatically generated by generate-cmdlist.sh */
struct cmdname_help {
const char *name;
@ -91,8 +103,8 @@ struct cmdname_help {
uint32_t category;
};
"
define_categories "$1"
define_categories "$categories"
echo
define_category_names "$1"
define_category_names "$categories"
echo
print_command_list "$1"
print_command_list "$commands"