compression: emit POC marker when only one single POC is requested (fixes #1191)
[openjpeg.git] / scripts / verify-indentation.sh
1 #!/bin/bash
2 cd $(git rev-parse --show-toplevel)
3
4 export PATH=$PATH:$PWD/scripts
5
6 if [ -z "$TRAVIS_COMMIT_RANGE" ]; then
7         echo "No commit range given"
8         exit 0
9 fi
10
11 if ! type -p astyle.sh >/dev/null; then
12         echo astyle.sh not found
13         exit 1
14 fi
15
16 set -e
17
18 ASTYLEDIFF=/tmp/astyle.diff
19 >$ASTYLEDIFF
20
21
22 if [[ ! -z  $TRAVIS_PULL_REQUEST_BRANCH  ]]; then
23   # if on a PR, just analyse the changed files
24   echo "TRAVIS PR BRANCH: $TRAVIS_PULL_REQUEST_BRANCH"
25   FILES=$(git diff --diff-filter=AM --name-only $(git merge-base HEAD master) | tr '\n' ' ' )
26 elif [[ ! -z  $TRAVIS_COMMIT_RANGE  ]]; then
27   echo "TRAVIS COMMIT RANGE: $TRAVIS_COMMIT_RANGE"
28   FILES=$(git diff --diff-filter=AM --name-only ${TRAVIS_COMMIT_RANGE/.../..} | tr '\n' ' ' )
29 fi
30
31 for f in $FILES; do
32         if ! [ -f "$f" ]; then
33                 echo "$f was removed." >>/tmp/ctest-important.log
34                 continue
35         fi
36
37         echo "Checking $f" >>/tmp/ctest-important.log
38         case "$f" in
39         thirdparty*)
40                 echo "$f skipped"
41                 continue
42                 ;;
43
44         *.cpp|*.c|*.h|*.cxx|*.hxx|*.c++|*.h++|*.cc|*.hh|*.C|*.H|*.sip|*.py)
45                 ;;
46
47         *)
48                 continue
49                 ;;
50         esac
51
52         m="$f.prepare"
53         cp "$f" "$m"
54         astyle.sh "$f"
55         if diff -u "$m" "$f" >>$ASTYLEDIFF; then
56                 rm "$m"
57         else
58                 echo "File $f needs indentation"
59         fi
60 done
61
62 if [ -s "$ASTYLEDIFF" ]; then
63         echo
64         echo "Required indentation updates:"
65         cat "$ASTYLEDIFF"
66
67         cat <<EOF
68
69 Tips to prevent and resolve:
70 * Enable WITH_ASTYLE in your cmake configuration to format C++ code
71 * Install autopep8 (>= 1.2.1) to format python code
72 * Use "scripts/astyle.sh file" to fix the now badly indented files
73 * Consider using scripts/prepare-commit.sh as pre-commit hook to avoid this
74   in the future (ln -s scripts/prepare-commit.sh .git/hooks/pre-commit) or
75   run it manually before each commit.
76 EOF
77
78         exit 1
79 fi