Meta: Only check changed files in lint-gml-format.sh

This speeds up the script from about 140ms down to <10ms, even for
changesets that touch a handful of different GML files.

130ms may not feel like much, but it adds up quickly, especially since
we run a dozen scripts during pre-commit.
This commit is contained in:
Ben Wiederhake 2022-09-18 20:10:57 +02:00 committed by Brian Gianforcaro
parent de581ca5fd
commit 532786848b
Notes: sideshowbarker 2024-07-17 20:58:35 +09:00

View file

@ -18,4 +18,18 @@ if [ -z "${GML_FORMAT:-}" ] ; then
GML_FORMAT="Build/lagom/gml-format"
fi
find AK Base Documentation Kernel Meta Ports Tests Userland -type f -name '*.gml' -print0 | xargs -0 "${GML_FORMAT}" -i
if [ "$#" -gt "0" ] ; then
# We're in the middle of a pre-commit run, so we should only check the files that have
# actually changed. The reason is that "git ls-files | grep" on the entire repo takes
# about 100ms. That is perfectly fine during a CI run, but becomes noticable during a
# pre-commit hook. It is unnecessary to check the entire repository on every single
# commit, so we save some time here.
for file in "$@"; do
if [[ "${file}" =~ \.gml ]]; then
echo "$file"
fi
done
else
find AK Base Documentation Kernel Meta Ports Tests Userland -type f -name '*.gml' -print
fi \
| xargs -r "${GML_FORMAT}" -i