| 1 | #!/bin/bash |
| 2 | |
| 3 | SOURCE_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" |
| 4 | |
| 5 | UNCRUSTIFY=$(command -v uncrustify) |
| 6 | if [ -z "$UNCRUSTIFY" ]; |
| 7 | then |
| 8 | echo "Uncrustify is not installed on your system." |
| 9 | exit 1 |
| 10 | fi |
| 11 | |
| 12 | LINEUP_PARAMETERS="$SOURCE_ROOT/data/lineup-parameters" |
| 13 | if [ ! -x "$LINEUP_PARAMETERS" ]; |
| 14 | then |
| 15 | echo "lineup-parameters script is missing" |
| 16 | exit 1 |
| 17 | fi |
| 18 | |
| 19 | # create a filename to store our generated patch |
| 20 | prefix="libproxy-ccs" |
| 21 | suffix="$(date +%C%y-%m-%d_%Hh%Mm%Ss)" |
| 22 | patch="/tmp/$prefix-$suffix.patch" |
| 23 | |
| 24 | # clean up old patches |
| 25 | rm -f /tmp/$prefix*.patch |
| 26 | |
| 27 | pushd $SOURCE_ROOT |
| 28 | for DIR in src |
| 29 | do |
| 30 | # Aligning prototypes is not working yet, so avoid headers |
| 31 | for FILE in $(find "$DIR" -name "*.c" ! -path "*/contrib/*") |
| 32 | do |
| 33 | "$UNCRUSTIFY" -q -c "data/uncrustify.cfg" -f "$FILE" -o "$FILE.uncrustify" |
| 34 | "$LINEUP_PARAMETERS" "$FILE.uncrustify" > "$FILE.temp" && mv "$FILE.temp" "$FILE.uncrustify" |
| 35 | diff -urN "$FILE" "$FILE.uncrustify" | \ |
| 36 | sed -e "1s|--- |--- a/|" -e "2s|+++ |+++ b/|" >> "$patch" |
| 37 | rm "$FILE.uncrustify" |
| 38 | done |
| 39 | done |
| 40 | popd |
| 41 | |
| 42 | if [ ! -s "$patch" ] ; then |
| 43 | printf "** Commit is valid. \\o/\n" |
| 44 | rm -f "$patch" |
| 45 | exit 0 |
| 46 | fi |
| 47 | |
| 48 | printf "** Commit does not comply to the correct style :(\n\n" |
| 49 | |
| 50 | if hash colordiff 2> /dev/null; then |
| 51 | colordiff < $patch |
| 52 | else |
| 53 | cat "$patch" |
| 54 | fi |
| 55 | |
| 56 | printf "\n" |
| 57 | printf "You can apply these changed with: git apply $patch\n" |
| 58 | printf "\n" |
| 59 | |
| 60 | exit 1 |