Batch files for Docker clang-format to improve performance

This commit is contained in:
Mario Zechner 2025-07-16 04:47:17 +02:00
parent d6b0ab0125
commit 557967fa1e

View File

@ -88,25 +88,35 @@ done
echo "Found ${#files[@]} C/C++ files to format" echo "Found ${#files[@]} C/C++ files to format"
# Format each file with progress # Check if we're using Docker (if clang-format is a script containing 'docker')
count=0 if file $(which clang-format) | grep -q "shell script"; then
errors=0 echo "Using Docker clang-format - batching files for performance..."
for file in "${files[@]}"; do # Format all files in one call when using Docker
count=$((count + 1)) if ! clang-format -i -style=file:".clang-format" "${files[@]}" 2>&1; then
# Show progress every 10 files or for the last file echo "Error: clang-format failed"
if [ $((count % 10)) -eq 0 ] || [ $count -eq ${#files[@]} ]; then errors=1
printf "\r[$count/${#files[@]}] Formatting: %-80s" "$(basename "$file")"
fi fi
else
# Format each file individually for native clang-format (shows progress)
count=0
errors=0
for file in "${files[@]}"; do
count=$((count + 1))
# Show progress every 10 files or for the last file
if [ $((count % 10)) -eq 0 ] || [ $count -eq ${#files[@]} ]; then
printf "\r[$count/${#files[@]}] Formatting: %-80s" "$(basename "$file")"
fi
# Format the file and capture any errors # Format the file and capture any errors
if ! clang-format -i -style=file:".clang-format" "$file" 2>&1; then if ! clang-format -i -style=file:".clang-format" "$file" 2>&1; then
printf "\nError formatting: $file\n" printf "\nError formatting: $file\n"
errors=$((errors + 1)) errors=$((errors + 1))
fi fi
done done
# Clear the progress line and show completion # Clear the progress line
printf "\r%-100s\r" " " printf "\r%-100s\r" " "
fi
if [ $errors -gt 0 ]; then if [ $errors -gt 0 ]; then
echo "Completed with $errors errors" echo "Completed with $errors errors"