3 # Check that the code follows a consistant code style
6 # Check for existence of indent, and error out if not present.
7 # On some *bsd systems the binary seems to be called gnunindent,
8 # so check for that first.
10 version=`gnuindent --version 2>/dev/null`
11 if test "x$version" = "x"; then
12 version=`indent --version 2>/dev/null`
13 if test "x$version" = "x"; then
14 echo "GStreamer git pre-commit hook:"
15 echo "Did not find GNU indent, please install it before continuing."
23 case `$INDENT --version` in
27 echo "GStreamer git pre-commit hook:"
28 echo "Did not find GNU indent, please install it before continuing."
29 echo "(Found $INDENT, but it doesn't seem to be GNU indent)"
34 INDENT_PARAMETERS="--braces-on-if-line \
35 --case-brace-indentation0 \
37 --braces-after-struct-decl-line \
41 --dont-line-up-parentheses \
42 --continuation-indentation4 \
47 echo "--Checking style--"
48 for file in `git-diff-index --cached --name-only HEAD --diff-filter=ACMR| grep "\.c$"` ; do
49 # nf is the temporary checkout. This makes sure we check against the
50 # revision in the index (and not the checked out version).
51 nf=`git checkout-index --temp ${file} | cut -f 1`
52 newfile=`mktemp /tmp/${nf}.XXXXXX` || exit 1
53 $INDENT ${INDENT_PARAMETERS} \
54 $nf -o $newfile 2>> /dev/null
55 # FIXME: Call indent twice as it tends to do line-breaks
56 # different for every second call.
57 $INDENT ${INDENT_PARAMETERS} \
58 $newfile 2>> /dev/null
59 diff -u -p "${nf}" "${newfile}"
64 echo "Code style error in $file, please fix before commiting."
68 echo "--Checking style pass--"