commit 4bd240e557f9f843cb8a17214553a72219faddca parent 6ee2d00783363da6a124fe1c01b3899257cbd1da Author: Ryan Sepassi <rsepassi@gmail.com> Date: Tue, 2 Jun 2026 16:45:16 -0700 make format: format git diff files by default Diffstat:
| M | Makefile | | | 16 | +++++++++++++++- |
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile @@ -618,8 +618,22 @@ dist: cd build/dist && tar czf kit.tar.gz kit @echo "dist: $(abspath $(DIST_TARBALL))" +# Format only the .c/.h files changed in the working tree (staged, unstaged, or +# new/untracked), restricted to the formatted roots and excluding test/pp. When +# nothing has changed, fall back to formatting every source file. format: - find src include driver lang test rt -path test/pp -prune -o \( -name '*.c' -o -name '*.h' \) -print | xargs clang-format -i --style=google + @files=$$( { git diff --name-only --diff-filter=ACMR HEAD -- '*.c' '*.h'; \ + git ls-files --others --exclude-standard -- '*.c' '*.h'; } 2>/dev/null \ + | grep -E '^(src|include|driver|lang|test|rt)/' \ + | grep -vE '^test/pp/' \ + | sort -u ); \ + if [ -n "$$files" ]; then \ + echo "$$files" | xargs clang-format -i --style=google; \ + echo "$$files" | sed 's/^/formatted /'; \ + else \ + echo "no changed sources; formatting all"; \ + find src include driver lang test rt -path test/pp -prune -o \( -name '*.c' -o -name '*.h' \) -print | xargs clang-format -i --style=google; \ + fi # Regenerate the clangd compilation database (build/compile_commands.json). # clangd auto-discovers it under build/; re-run after adding/removing sources