diff options
author | Jeff King <peff@peff.net> | 2021-11-05 17:08:06 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-11-05 22:01:13 +0300 |
commit | 3ebeb1d6b10b538b1c1ca05a260e6ad41ea80fd7 (patch) | |
tree | 2271598a8e8c6a453c8c6f10510412e430f11409 /generate-cmdlist.sh | |
parent | 8d5be8b421cf525a2fa61cb77921c74be7090c0a (diff) |
generate-cmdlist.sh: do not shell out to "sed"
Replace the "sed" invocation in get_synopsis() with a pure-shell
version. This speeds up generate-cmdlist.sh significantly. Compared to
HEAD~ (old) and "master" we are, according to hyperfine(1):
'sh generate-cmdlist.sh command-list.txt' ran
12.69 ± 5.01 times faster than 'sh generate-cmdlist.sh.old command-list.txt'
18.34 ± 3.03 times faster than 'sh generate-cmdlist.sh.master command-list.txt'
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'generate-cmdlist.sh')
-rwxr-xr-x | generate-cmdlist.sh | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/generate-cmdlist.sh b/generate-cmdlist.sh index f50112c50f..9b7d6aea62 100755 --- a/generate-cmdlist.sh +++ b/generate-cmdlist.sh @@ -17,16 +17,6 @@ category_list () { LC_ALL=C sort -u } -get_synopsis () { - sed -n ' - /^NAME/,/'"$1"'/H - ${ - x - s/.*'"$1"' - \(.*\)/N_("\1")/ - p - }' "Documentation/$1.txt" -} - define_categories () { echo echo "/* Command categories */" @@ -61,7 +51,18 @@ print_command_list () { command_list "$1" | while read cmd rest do - printf " { \"$cmd\", $(get_synopsis $cmd), 0" + synopsis= + while read line + do + 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 |