summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2021-12-10 14:35:08 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-12-10 14:35:08 -0800
commitd1305bd3cf64743a0eda8ee16fc15b531f43dd25 (patch)
tree5825b8dfd6ae597b9adb2146ee589fa70bf54318
parentMerge branch 'tw/var-default-branch' (diff)
parentgenerate-cmdlist.sh: don't parse command-list.txt thrice (diff)
downloadtgif-d1305bd3cf64743a0eda8ee16fc15b531f43dd25.tar.xz
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"
-rw-r--r--command-list.txt22
-rwxr-xr-xgenerate-cmdlist.sh78
2 files changed, 56 insertions, 44 deletions
diff --git a/command-list.txt b/command-list.txt
index eb9cee8dee..675c28f0bd 100644
--- a/command-list.txt
+++ b/command-list.txt
@@ -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
diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh
index 9dbbb08e70..205541e0f7 100755
--- a/generate-cmdlist.sh
+++ b/generate-cmdlist.sh
@@ -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"