xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkaiq/tools/pre-commit-code-style.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/bin/sh
2*4882a593Smuzhiyun# checking code style before commit
3*4882a593Smuzhiyun
4*4882a593SmuzhiyunASTYLE=astyle
5*4882a593SmuzhiyunASTYLE_PARAMS="--indent=spaces=4 --convert-tabs --pad-oper --suffix=none"
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunDOS2UNIX=dos2unix
8*4882a593SmuzhiyunDOS2UNIX_PARAMS="-ascii --safe --keepdate --quiet"
9*4882a593Smuzhiyun
10*4882a593Smuzhiyuncommand -v $ASTYLE > /dev/null 2>&1 || echo "warning: $ASTYLE is not installed"
11*4882a593Smuzhiyuncommand -v $DOS2UNIX > /dev/null 2>&1 || echo "warning: $DOS2UNIX is not installed"
12*4882a593Smuzhiyun
13*4882a593Smuzhiyunecho "---- checking code style (dos2unix / astyle)----"
14*4882a593Smuzhiyunfor file in `git diff-index --cached --name-only -M HEAD | grep -E "\.c$|\.cpp$|\.h$|\.hpp$" ` ; do
15*4882a593Smuzhiyun    $DOS2UNIX ${DOS2UNIX_PARAMS} ${file}
16*4882a593Smuzhiyun    $ASTYLE ${ASTYLE_PARAMS} ${file}
17*4882a593Smuzhiyun    ret=$?
18*4882a593Smuzhiyun    if [ $ret != 0 ] ; then
19*4882a593Smuzhiyun        echo "code style failed on $file"
20*4882a593Smuzhiyun        exit 1
21*4882a593Smuzhiyun    fi
22*4882a593Smuzhiyun    git add $file
23*4882a593Smuzhiyundone
24*4882a593Smuzhiyunecho "---- checking code style done----"
25