From 4caaa78bafbe104cc249a0bb8a6cf3a88f498555 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Sun, 18 Sep 2022 20:10:57 +0200 Subject: [PATCH] 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. --- Meta/check-debug-flags.sh | 26 +++++++++++++++++++------- 1 file 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