aboutsummaryrefslogtreecommitdiff
path: root/scripts/reformat.sh
blob: c38263223e8374498a4bcecf40584f316bd07951 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/sh
set -eu

# Refuse to reformat nn.hpp: this is third-party code
if test $(basename $1) = "nn.hpp"; then
    exit 0
fi

clang-format -style="{BasedOnStyle: llvm, IndentWidth: 4}"  $1 > $1.reformatted
if diff -u $1.reformatted $1; then
    # No reformatting: remove temporary file
    rm $1.reformatted
else
    # Differences. Backup original file, and use reformatted file
    cp $1 $1.before_reformat
    mv $1.reformatted $1
fi