]> git.ipfire.org Git - thirdparty/git.git/commitdiff
generate-cmdlist.sh: do not shell out to "sed"
authorJeff King <peff@peff.net>
Fri, 5 Nov 2021 14:08:06 +0000 (15:08 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 5 Nov 2021 19:01:13 +0000 (12:01 -0700)
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>
generate-cmdlist.sh

index f50112c50f886979ae36e908ab6dace5fcbc060f..9b7d6aea629d2984cb2f2dc9817d2106fc5db172 100755 (executable)
@@ -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