Skip to content

Commit a7fa5b2

Browse files
pks-tgitster
authored andcommitted
Documentation: stop depending on Perl to generate command list
The "cmd-list.perl" script is used to extract the list of commands part of a specific category and extracts the description of each command from its respective manpage. The generated output is then included in git(1) to list all Git commands. The script is written in Perl. Refactor it to use shell scripting exclusively so that we can get rid of the mandatory dependency on Perl to build our documentation. The converted script is slower compared to its Perl implementation. But by being careful and not spawning external commands in `format_one ()` we can mitigate the performance hit to a reasonable level: Benchmark 1: Perl Time (mean ± σ): 10.3 ms ± 0.2 ms [User: 7.0 ms, System: 3.3 ms] Range (min … max): 10.0 ms … 11.1 ms 200 runs Benchmark 2: Shell Time (mean ± σ): 74.4 ms ± 0.4 ms [User: 48.6 ms, System: 24.7 ms] Range (min … max): 73.1 ms … 75.5 ms 200 runs Summary Perl ran 7.23 ± 0.13 times faster than Shell While a sevenfold slowdown is significant, the benefit of not requiring Perl for a fully-functioning Git installation outweighs waiting a couple of milliseconds longer during the build process. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 521c988 commit a7fa5b2

File tree

5 files changed

+109
-85
lines changed

5 files changed

+109
-85
lines changed

Documentation/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ cmds_txt = cmds-ancillaryinterrogators.adoc \
317317

318318
$(cmds_txt): cmd-list.made
319319

320-
cmd-list.made: cmd-list.perl ../command-list.txt $(MAN1_TXT)
321-
$(QUIET_GEN)$(PERL_PATH) ./cmd-list.perl .. . $(cmds_txt) && \
320+
cmd-list.made: cmd-list.sh ../command-list.txt $(MAN1_TXT)
321+
$(QUIET_GEN)$(SHELL_PATH) ./cmd-list.sh .. . $(cmds_txt) && \
322322
date >$@
323323

324324
mergetools-%.adoc: generate-mergetool-list.sh ../git-mergetool--lib.sh $(wildcard ../mergetools/*)

Documentation/cmd-list.perl

Lines changed: 0 additions & 80 deletions
This file was deleted.

Documentation/cmd-list.sh

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
format_one () {
6+
source_dir="$1"
7+
command="$2"
8+
attributes="$3"
9+
10+
path="$source_dir/Documentation/$command.adoc"
11+
if ! test -f "$path"
12+
then
13+
echo >&2 "No such file $path"
14+
exit 1
15+
fi
16+
17+
state=0
18+
while read line
19+
do
20+
case "$state" in
21+
0)
22+
case "$line" in
23+
git*\(*\)|scalar*\(*\))
24+
mansection="${line##*\(}"
25+
mansection="${mansection%\)}"
26+
;;
27+
NAME)
28+
state=1;;
29+
esac
30+
;;
31+
1)
32+
if test "$line" = "----"
33+
then
34+
state=2
35+
fi
36+
;;
37+
2)
38+
description="$line"
39+
break
40+
;;
41+
esac
42+
done <"$path"
43+
44+
if test -z "$mansection"
45+
then
46+
echo "No man section found in $path" >&2
47+
exit 1
48+
fi
49+
50+
if test -z "$description"
51+
then
52+
echo >&2 "No description found in $path"
53+
exit 1
54+
fi
55+
56+
case "$description" in
57+
"$command - "*)
58+
text="${description#$command - }"
59+
60+
printf "linkgit:%s[%s]::\n\t" "$command" "$mansection"
61+
case "$attributes" in
62+
*" deprecated "*)
63+
printf "(deprecated) "
64+
;;
65+
esac
66+
printf "$text.\n\n"
67+
;;
68+
*)
69+
echo >&2 "Description does not match $command: $description"
70+
exit 1
71+
;;
72+
esac
73+
}
74+
75+
source_dir="$1"
76+
build_dir="$2"
77+
shift 2
78+
79+
for out
80+
do
81+
category="${out#cmds-}"
82+
category="${category%.adoc}"
83+
path="$build_dir/$out"
84+
85+
while read command command_category attributes
86+
do
87+
case "$command" in
88+
"#"*)
89+
continue;;
90+
esac
91+
92+
case "$command_category" in
93+
"$category")
94+
format_one "$source_dir" "$command" " $attributes ";;
95+
esac
96+
done <"$source_dir/command-list.txt" >"$build_dir/$out+"
97+
98+
if cmp "$build_dir/$out+" "$build_dir/$out" >/dev/null 2>&1
99+
then
100+
rm "$build_dir/$out+"
101+
else
102+
mv "$build_dir/$out+" "$build_dir/$out"
103+
fi
104+
done

Documentation/meson.build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,12 @@ cmd_lists = [
315315

316316
documentation_deps += custom_target(
317317
command: [
318-
perl,
318+
shell,
319319
'@INPUT@',
320320
meson.project_source_root(),
321321
meson.current_build_dir(),
322322
] + cmd_lists,
323-
input: 'cmd-list.perl',
323+
input: 'cmd-list.sh',
324324
output: cmd_lists
325325
)
326326

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ endif
779779
# features. It is optional if you want to neither execute tests nor use any of
780780
# these optional features.
781781
perl_required = get_option('perl')
782-
if get_option('gitweb').enabled() or 'netrc' in get_option('credential_helpers') or get_option('docs') != []
782+
if get_option('gitweb').enabled() or 'netrc' in get_option('credential_helpers')
783783
perl_required = true
784784
endif
785785

0 commit comments

Comments
 (0)