hardware/intel/common/vaapi
Revision | 2f0a8449f37b978eb202082b9113039b00c6931a (tree) |
---|---|
Time | 2017-04-07 17:32:33 |
Author | Xiang, Haihao <haihao.xiang@inte...> |
Commiter | Xiang, Haihao |
Add pre-commit hook
Check that the code follows a consistant coding style before committing.
The current command will be interrupted if the commit doesn't follow the
code style
This fixes https://github.com/01org/intel-vaapi-driver/issues/99
Signed-off-by: Xiang, Haihao <haihao.xiang@intel.com>
@@ -4,7 +4,39 @@ Intel-vaapi-driver is an open source project licensed under the [MIT License] (h | ||
4 | 4 | |
5 | 5 | ## Coding Style |
6 | 6 | |
7 | -Intel-vaapi-driver does not have a defined coding style at this time, but that will be updated. | |
7 | +In our project we follow the Linux coding style with a few changes. You may run 'astyle --style=linux -cnpUH -s4 -M120 <file>' | |
8 | +to format/indent a single file or run './style_unify' in the top-level directory to handle all .c/.h files in the src directory. | |
9 | + | |
10 | +You will fail to commit your patch if your patch doesn't follow the coding style and the pre-commit hook will prompt you to fix | |
11 | +the coding style. | |
12 | + | |
13 | +For example: | |
14 | + | |
15 | +``` | |
16 | +Checking coding style... | |
17 | + | |
18 | +--- .merge_file_tZMQ4C 2017-03-31 11:02:36.244617415 +0800 | |
19 | ++++ /tmp/.merge_file_tZMQ4C.D0V 2017-03-31 11:02:36.274617276 +0800 | |
20 | +@@ -438,8 +438,7 @@ intel_batchbuffer_align(struct intel_bat | |
21 | + assert((pad_size & 3) == 0); | |
22 | + assert(intel_batchbuffer_space(batch) >= pad_size); | |
23 | + | |
24 | +- while (pad_size >= 4) | |
25 | +- { | |
26 | ++ while (pad_size >= 4) { | |
27 | + intel_batchbuffer_emit_dword(batch, 0); | |
28 | + pad_size -= 4; | |
29 | + } | |
30 | + | |
31 | +************************************************************************** | |
32 | + Coding style error in src/intel_batchbuffer.c | |
33 | + | |
34 | + Please fix the coding style before committing. You may run the command | |
35 | + below to fix the coding style from the top-level directory | |
36 | + | |
37 | + astyle --style=linux -cnpUH -s4 -M120 src/intel_batchbuffer.c | |
38 | +************************************************************************** | |
39 | +``` | |
8 | 40 | |
9 | 41 | ## Certificate of Origin |
10 | 42 |
@@ -6,6 +6,15 @@ test -z "$srcdir" && srcdir=. | ||
6 | 6 | ORIGDIR=`pwd` |
7 | 7 | cd "$srcdir" |
8 | 8 | |
9 | +# install pre-commit hook | |
10 | +SRC_PRE_COMMIT=hooks/pre-commit.hook | |
11 | +GIT_PRE_COMMIT=.git/hooks/pre-commit | |
12 | + | |
13 | +if [ ! \( -x $GIT_PRE_COMMIT -a -L $GIT_PRE_COMMIT \) ]; then | |
14 | + rm -f $GIT_PRE_COMMIT | |
15 | + ln -s ../../$SRC_PRE_COMMIT $GIT_PRE_COMMIT | |
16 | +fi | |
17 | + | |
9 | 18 | autoreconf -v --install || exit 1 |
10 | 19 | cd $ORIGDIR || exit $? |
11 | 20 |
@@ -0,0 +1,37 @@ | ||
1 | +#!/bin/sh | |
2 | +# | |
3 | +# Use astyle to check the coding style | |
4 | +# | |
5 | + | |
6 | +ASTYLE=astyle | |
7 | +ASTYLE_PARAMS="--style=linux -cnpUH -s4 -M120" | |
8 | + | |
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" | |
12 | + exit 1 | |
13 | +fi | |
14 | + | |
15 | +echo "Checking coding style..." | |
16 | +echo "" | |
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}" | |
22 | + ret=$? | |
23 | + rm -f "${tmp0file}" "${tmp1file}" | |
24 | + if [ $ret != 0 ]; then | |
25 | +echo "" | |
26 | +echo "**************************************************************************" | |
27 | +echo " Coding style error in $file" | |
28 | +echo "" | |
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" | |
31 | +echo "" | |
32 | +echo " $ASTYLE $ASTYLE_PARAMS $file" | |
33 | +echo "**************************************************************************" | |
34 | + exit 1 | |
35 | + fi | |
36 | +done | |
37 | +echo "PASS!!!" |