]> git.ipfire.org Git - thirdparty/pdns.git/blob - build-scripts/format-code
Add script to format code, leaving the file untouched if not changed
[thirdparty/pdns.git] / build-scripts / format-code
1 #!/bin/sh
2
3 #
4 # Reformat code, but do not touch if no changes.
5 # Report if a files was changed.
6 #
7
8 if [ "$0" != "./build-scripts/format-code" ]; then
9 echo "Please run me from the root checkout dir"
10 exit 1
11 fi
12
13 if [ ! -e .clang-format ]; then
14 echo "No .clang-format file found in .";
15 exit 1
16 fi
17
18 for file in "${@}"; do
19 if ! clang-format -style=file "$file" > "$file.xxx"; then
20 rm "$file.xxx"
21 else
22 if ! cmp -s "$file" "$file.xxx"; then
23 echo "$file reformatted"
24 mv "$file.xxx" "$file"
25 else
26 rm "$file.xxx"
27 fi
28 fi
29 done
30