diff options
author | Ben Wiederhake <BenWiederhake.GitHub@gmx.de> | 2022-09-18 20:10:57 +0200 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2022-09-18 18:45:25 -0700 |
commit | 4caaa78bafbe104cc249a0bb8a6cf3a88f498555 (patch) | |
tree | 7581d6b4dee85d96c407101dd0703bee1b67c613 /Meta/check-debug-flags.sh | |
parent | 88c8ad840db6b88022dc93a30f14be2b31d20856 (diff) | |
download | serenity-4caaa78bafbe104cc249a0bb8a6cf3a88f498555.zip |
Meta: Only check changed files in check-debug-flags during pre-commit
This speeds up the script from about 170ms down to about 80ms for
changes in Debug.h.in or similarly "DEBUG"-rich files, down to <10ms for
more common changesets.
160ms may not feel like much, but it adds up quickly, especially since
we run a dozen scripts during pre-commit.
Diffstat (limited to 'Meta/check-debug-flags.sh')
-rwxr-xr-x | Meta/check-debug-flags.sh | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/Meta/check-debug-flags.sh b/Meta/check-debug-flags.sh index f90e2c530b..d80081602b 100755 --- a/Meta/check-debug-flags.sh +++ b/Meta/check-debug-flags.sh @@ -21,15 +21,27 @@ while IFS= read -r FLAG; do MISSING_FLAGS=y fi done < <( - git ls-files -- \ - '*.cpp' \ - '*.h' \ - '*.in' \ - ':!:Kernel/FileSystem/ext2_fs.h' \ + if [ "$#" -eq "0" ]; then + git ls-files -- \ + '*.cpp' \ + '*.h' \ + '*.in' \ + ':!:Kernel/FileSystem/ext2_fs.h' + else + # 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}" =~ \.cpp || "${file}" =~ \.h || "${file}" =~ \.in) && ! "${file}" == "Kernel/FileSystem/ext2_fs.h" ]]; then + echo "$file" + fi + done + fi \ | xargs grep -E '(_DEBUG|DEBUG_)' \ | sed -re 's,^.*[^a-zA-Z0-9_]([a-zA-Z0-9_]*DEBUG[a-zA-Z0-9_]*).*$,\1,' \ - | sort \ - | uniq + | sort -u ) if [ "n" != "${MISSING_FLAGS}" ] ; then |