From 557967fa1e0d18205892c364f1a208647e35aad0 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Wed, 16 Jul 2025 04:47:17 +0200 Subject: [PATCH] Batch files for Docker clang-format to improve performance --- formatters/format-cpp.sh | 44 ++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/formatters/format-cpp.sh b/formatters/format-cpp.sh index e96d64207..f0e84c6de 100755 --- a/formatters/format-cpp.sh +++ b/formatters/format-cpp.sh @@ -88,25 +88,35 @@ done echo "Found ${#files[@]} C/C++ files to format" -# Format each file with 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")" +# Check if we're using Docker (if clang-format is a script containing 'docker') +if file $(which clang-format) | grep -q "shell script"; then + echo "Using Docker clang-format - batching files for performance..." + # Format all files in one call when using Docker + if ! clang-format -i -style=file:".clang-format" "${files[@]}" 2>&1; then + echo "Error: clang-format failed" + errors=1 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 - if ! clang-format -i -style=file:".clang-format" "$file" 2>&1; then - printf "\nError formatting: $file\n" - errors=$((errors + 1)) - fi -done - -# Clear the progress line and show completion -printf "\r%-100s\r" " " + # Format the file and capture any errors + if ! clang-format -i -style=file:".clang-format" "$file" 2>&1; then + printf "\nError formatting: $file\n" + errors=$((errors + 1)) + fi + done + + # Clear the progress line + printf "\r%-100s\r" " " +fi if [ $errors -gt 0 ]; then echo "Completed with $errors errors"