OpenToonz - An open-source full-featured 2D animation creation software
C
Check clang-format only on changed lines
Rodney9b02b4e87fae
diff --git a/.github/workflows/workflow_clang_format.yml b/.github/workflows/workflow_clang_format.ymlindex adad701b0..4c32c15c8 100644--- a/.github/workflows/workflow_clang_format.yml+++ b/.github/workflows/workflow_clang_format.yml@@ -33,7 +33,7 @@ jobs:sudo apt-get updatesudo apt-get install -y clang-format-14- - name: Check formatting of changed C/C++ files+ - name: Check formatting of changed C/C++ linesenv:BASE_SHA: ${{ github.event.pull_request.base.sha }}HEAD_SHA: ${{ github.event.pull_request.head.sha }}@@ -55,9 +55,28 @@ jobs:)if (( ${#files[@]} == 0 )); then- echo "No changed C/C++ files to check."+ echo "No changed C/C++ lines to check."exit 0fi- printf 'Checking %s\n' "${files[@]}"- clang-format-14 --dry-run --Werror -style=file "${files[@]}"+ for file in "${files[@]}"; do+ ranges=()+ while read -r start count; do+ count=${count:-1}+ if (( count > 0 )); then+ end=$((start + count - 1))+ ranges+=(--lines="$start:$end")+ fi+ done < <(+ git diff --unified=0 --no-color "$BASE_SHA" "$HEAD_SHA" -- "$file" |+ sed -nE 's/^@@ -[0-9]+(,[0-9]+)? \+([0-9]+)(,([0-9]+))? @@.*/\2 \4/p'+ )++ if (( ${#ranges[@]} == 0 )); then+ continue+ fi++ printf 'Checking %s (%s)\n' "$file" "${ranges[*]}"+ clang-format-14 --dry-run --Werror -style=file \+ "${ranges[@]}" "$file"+ done