3 # Use astyle to check the coding style
7 ASTYLE_PARAMS="--style=linux -cnpUH -s4 -M120"
9 if [ -z "`which $ASTYLE 2> /dev/null`" ]; then
10 echo "git pre-commit hook:"
11 echo "Don't find $ASTYLE, please install $ASTYLE before committing the changes"
15 echo "Checking coding style..."
17 for file in `git diff-index --cached --name-only --diff-filter=ACMR HEAD src/ | grep "\.[ch]$" 2> /dev/null`; do
18 tmp0file=`git checkout-index --temp ${file} | cut -f 1`
19 tmp1file=`mktemp /tmp/${tmp0file}.XXX` || exit 1
20 $ASTYLE $ASTYLE_PARAMS < ${tmp0file} > ${tmp1file} 2> /dev/null
21 diff -up "${tmp0file}" "${tmp1file}"
23 rm -f "${tmp0file}" "${tmp1file}"
24 if [ $ret != 0 ]; then
26 echo "**************************************************************************"
27 echo " Coding style error in $file"
29 echo " Please fix the coding style before committing. You may run the command"
30 echo " below to fix the coding style from the top-level directory"
32 echo " $ASTYLE $ASTYLE_PARAMS $file"
33 echo "**************************************************************************"