6 trap "rm $tmp_file" EXIT
26 if [ -n "$all" ]; then
27 exec sh "$0" $check $(git ls-files '*.[ch]' '*.[ch]pp' ':!:src/third_party')
30 clang_format="$(dirname "$0")/clang-format"
31 [ -t 1 ] && cf_color="--color=always" || cf_color=""
33 if [ -n "${VERBOSE:-}" ]; then
34 "$clang_format" --version
39 "$clang_format" "$file" >"$tmp_file"
40 if cmp -s "$file" "$tmp_file"; then
44 if [ -n "$check" ]; then
46 echo "Error: $file not formatted with Clang-Format"
47 echo 'Run "make format" or apply this diff:'
48 git diff $cf_color --no-index "$file" "$tmp_file" \
49 | sed -E -e "s!^---.*!--- a/$file!" \
50 -e "s!^\+\+\+.*!+++ b/$file!" \
51 -e "/diff --/d" -e "/index /d" \
52 -e "s/.[0-9]*.clang-format.tmp//"
54 echo "Reformatted $file"
55 cp "$tmp_file" "$file"