summaryrefslogtreecommitdiff
path: root/Meta/lint-clang-format.sh
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-12-27 15:34:06 +0100
committerAndreas Kling <kling@serenityos.org>2020-12-27 21:25:27 +0100
commit51bcfb5a44ebedc319bb8dc66dfe814f936e5e83 (patch)
treec47b89dfcbad76f4416eeb3e87768203e9be2720 /Meta/lint-clang-format.sh
parenta56b3cbf7cb7968e9eac93272b829002dd36ce15 (diff)
downloadserenity-51bcfb5a44ebedc319bb8dc66dfe814f936e5e83.zip
Meta: Update lint-{clang-format,shell-scripts}.sh to take a list of files
This should speed up pre-commit a bit as only files that are staged will be processed, and clang-format and shellcheck are only invoked once, not for every file. When no arguments are given (e.g. on CI), it still uses 'git ls-files'.
Diffstat (limited to 'Meta/lint-clang-format.sh')
-rwxr-xr-xMeta/lint-clang-format.sh45
1 files changed, 29 insertions, 16 deletions
diff --git a/Meta/lint-clang-format.sh b/Meta/lint-clang-format.sh
index 6a84940969..2359639071 100755
--- a/Meta/lint-clang-format.sh
+++ b/Meta/lint-clang-format.sh
@@ -20,7 +20,7 @@ else
exit 1
fi
-if [ "$#" -eq "1" ] && [ "x--overwrite-inplace" = "x$1" ] ; then
+if [ "$#" -gt "0" ] && [ "x--overwrite-inplace" = "x$1" ] ; then
true # The only way to run this script.
else
# Note that this branch also covers --help, -h, -help, -?, etc.
@@ -31,19 +31,32 @@ fi
echo "Using ${CLANG_FORMAT}"
-{
- git ls-files -- \
- '*.cpp' \
- '*.h' \
- ':!:Base' \
- ':!:Kernel/Arch/i386/CPU.cpp' \
- ':!:Kernel/FileSystem/ext2_fs.h' \
- ':!:Libraries/LibC/getopt.cpp' \
- ':!:Libraries/LibC/syslog.h' \
- ':!:Libraries/LibCore/puff.h' \
- ':!:Libraries/LibCore/puff.cpp' \
- ':!:Libraries/LibELF/exec_elf.h' \
- || echo "'git ls-files failed!'"
-} | xargs -d'\n' "${CLANG_FORMAT}" -style=file -i
+if [ "$#" -eq "1" ]; then
+ mapfile -t files < <(
+ git ls-files -- \
+ '*.cpp' \
+ '*.h' \
+ ':!:Base' \
+ ':!:Kernel/Arch/i386/CPU.cpp' \
+ ':!:Kernel/FileSystem/ext2_fs.h' \
+ ':!:Libraries/LibC/getopt.cpp' \
+ ':!:Libraries/LibC/syslog.h' \
+ ':!:Libraries/LibCore/puff.h' \
+ ':!:Libraries/LibCore/puff.cpp' \
+ ':!:Libraries/LibELF/exec_elf.h'
+ )
+else
+ files=()
+ for file in "${@:2}"; do
+ if [[ "${file}" == *".cpp" || "${file}" == *".h" ]]; then
+ files+=("${file}")
+ fi
+ done
+fi
-echo "Maybe some files have changed. Sorry, but clang-format doesn't indicate what happened."
+if (( ${#files[@]} )); then
+ "${CLANG_FORMAT}" -style=file -i "${files[@]}"
+ echo "Maybe some files have changed. Sorry, but clang-format doesn't indicate what happened."
+else
+ echo "No .cpp or .h files to check."
+fi