From 78a34f56f351b9bf5411c003b1906a36715f4bdd Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Fri, 29 Nov 2024 16:06:04 +0100 Subject: [PATCH] discard non-sipified directories in prepare_commit and verify_indent --- .pre-commit-config.yaml | 19 ++++++++++++------- scripts/prepare_commit.sh | 16 +++++++++------- scripts/verify_indentation.sh | 17 ++++++++++------- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 407dad692679..79f313670df9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,7 @@ exclude: | (?x)^( python/.*/auto_\w+/.*.py| + external/.*| tests/testdata/script_with_error.py )$ fail_fast: false @@ -8,16 +9,20 @@ fail_fast: false repos: - repo: https://github.com/pre-commit/mirrors-clang-format rev: v19.1.3 - exclude: | - (?x)^( - src/core/.*| - src/gui/.*| - src/analysis/.*| - src/3d/.* - )$ + # if adding directory handled by clang-format + # you need to adapt prepare_commit and verify_indentation scripts accordingly hooks: - id: clang-format types_or: [c++, c, c#] + exclude: | + (?x)^( + src/core/.*| + src/gui/.*| + src/analysis/.*| + src/3d/.*| + src/server/.*| + tests/code_layout/sipify/sipifyheader.h + )$ - repo: https://github.com/asottile/pyupgrade rev: v3.19.0 diff --git a/scripts/prepare_commit.sh b/scripts/prepare_commit.sh index 17e9becf4a8e..4df7bf1f19a3 100755 --- a/scripts/prepare_commit.sh +++ b/scripts/prepare_commit.sh @@ -119,13 +119,15 @@ for f in $MODIFIED; do ;; esac - m=$f.$REV.prepare - - cp "$f" "$m" - ASTYLEPROGRESS=" [$i/$N]" astyle.sh "$f" - if diff -u "$m" "$f" >>"$ASTYLEDIFF"; then - # no difference found - rm "$m" + # only run astyle on sipified directories, others are handled by clang-format (see .pre-commit-config.yaml) + if [[ $f =~ "^src/(core|gui|analysis|3d|server)" ]]; then + m=$f.$REV.prepare + cp "$f" "$m" + ASTYLEPROGRESS=" [$i/$N]" astyle.sh "$f" + if diff -u "$m" "$f" >>"$ASTYLEDIFF"; then + # no difference found + rm "$m" + fi fi done diff --git a/scripts/verify_indentation.sh b/scripts/verify_indentation.sh index 4d869d148cbe..892869e9054f 100755 --- a/scripts/verify_indentation.sh +++ b/scripts/verify_indentation.sh @@ -39,13 +39,16 @@ for f in $FILES; do ;; esac - m="$f.prepare" - cp "$f" "$m" - astyle.sh "$f" - if diff -u "$m" "$f" >>$ASTYLEDIFF; then - rm "$m" - else - echo "File $f is not styled properly." + # only run astyle on sipified directories, others are handled by clang-format (see .pre-commit-config.yaml) + if [[ $f =~ "^src/(core|gui|analysis|3d|server)" ]]; then + m="$f.prepare" + cp "$f" "$m" + astyle.sh "$f" + if diff -u "$m" "$f" >>$ASTYLEDIFF; then + rm "$m" + else + echo "File $f is not styled properly." + fi fi done