]> git.ipfire.org Git - thirdparty/pdns.git/blame - build-scripts/format-code
Add script to format code, leaving the file untouched if not changed
[thirdparty/pdns.git] / build-scripts / format-code
CommitLineData
ba5ba96c
OM
1#!/bin/sh
2
3#
4# Reformat code, but do not touch if no changes.
5# Report if a files was changed.
6#
7
8if [ "$0" != "./build-scripts/format-code" ]; then
9 echo "Please run me from the root checkout dir"
10 exit 1
11fi
12
13if [ ! -e .clang-format ]; then
14 echo "No .clang-format file found in .";
15 exit 1
16fi
17
18for 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
29done
30