Update shell scripts

This commit is contained in:
jpirnay
2026-05-05 09:29:28 +02:00
parent 2a443da291
commit 064ed97362
2 changed files with 20 additions and 11 deletions
Regular → Executable
View File
+20 -11
View File
@@ -34,19 +34,28 @@ fi
# Format all files (or only modified files if -g is passed)
# Use 'git ls-files' to get a list of all files tracked by git:
# --modified: files tracked by git that have been modified (staged or unstaged)
# --exclude-standard: ignores files in .gitignore
# Additionally exclude files in 'lib/EpdFont/builtinFonts/' as they are script-generated.
# Also exclude files in 'lib/Epub/Epub/hyphenation/generated/' as they are script-generated.
# Use git diff in -g mode to capture staged and unstaged changes relative to HEAD.
# Otherwise use git ls-files to format all tracked source files.
# --exclude-standard ignores files in .gitignore.
# Also exclude generated, vendored, and build directories.
# Keep the no-match case non-fatal: grep returns 1 when no files match,
# which is expected when there are no modified C/C++ files.
set +o pipefail
git ls-files --exclude-standard ${GIT_LS_FILES_FLAGS} \
| grep -E '\.(c|cpp|h|hpp)$' \
| grep -v -E '^lib/EpdFont/builtinFonts/' \
| grep -v -E '^lib/Epub/Epub/hyphenation/generated/' \
| grep -v -E '^lib/uzlib/' \
| xargs -r "${CLANG_FORMAT_BIN}" -style=file -i
if [[ "${1:-}" == "-g" ]]; then
git diff --name-only HEAD -- \
| grep -E '\.(c|cpp|h|hpp)$' \
| grep -v -E '^(open-x4-sdk/|\.pio/|\.venv/|lib/EpdFont/builtinFonts/|lib/Epub/Epub/hyphenation/generated/|lib/uzlib/)' \
| grep -v -E '\.generated\.h$' \
| while IFS= read -r file; do
[[ -f "$file" ]] && printf '%s\n' "$file"
done \
| xargs -r "${CLANG_FORMAT_BIN}" -style=file -i
else
git ls-files --exclude-standard \
| grep -E '\.(c|cpp|h|hpp)$' \
| grep -v -E '^(open-x4-sdk/|\.pio/|\.venv/|lib/EpdFont/builtinFonts/|lib/Epub/Epub/hyphenation/generated/|lib/uzlib/)' \
| grep -v -E '\.generated\.h$' \
| xargs -r "${CLANG_FORMAT_BIN}" -style=file -i
fi
# Restore strict pipeline failure handling for the rest of the script.
set -o pipefail