File: pre-commit.hook

package info (click to toggle)
intel-vaapi-driver 2.4.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,628 kB
  • sloc: ansic: 181,516; asm: 20,806; cpp: 15,306; pascal: 5,836; makefile: 1,822; python: 153; xml: 146; sh: 51
file content (37 lines) | stat: -rwxr-xr-x 1,194 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh
#
# Use astyle to check the coding style
#

ASTYLE=astyle
ASTYLE_PARAMS="--style=linux -cnpUH -s4 -M120"

if [ -z "`which $ASTYLE 2> /dev/null`" ]; then
    echo "git pre-commit hook:"
    echo "Don't find $ASTYLE, please install $ASTYLE before committing the changes"
    exit 1
fi

echo "Checking coding style..."
echo ""
for file in `git diff-index --cached --name-only --diff-filter=ACMR HEAD src/ | grep "\.[ch]$" 2> /dev/null`; do
    tmp0file=`git checkout-index --temp ${file} | cut -f 1`
    tmp1file=`mktemp /tmp/${tmp0file}.XXX` || exit 1
    $ASTYLE $ASTYLE_PARAMS < ${tmp0file} > ${tmp1file} 2> /dev/null
    diff -up "${tmp0file}" "${tmp1file}"
    ret=$?
    rm -f "${tmp0file}" "${tmp1file}"
    if [ $ret != 0 ]; then
echo ""
echo "**************************************************************************"
echo " Coding style error in $file"
echo ""
echo " Please fix the coding style before committing. You may run the command"
echo " below to fix the coding style from the top-level directory"
echo ""
echo " $ASTYLE $ASTYLE_PARAMS $file"
echo "**************************************************************************"
        exit 1
    fi
done
echo "PASS!!!"