[coding-style]: add git hook to format code

1. please run hooks/install_hooks.sh manually for the first time
2. hooks/pre-commit.hook is called before commit automatically
3. format code

Change-Id: I4565b206da10abb59506ef73f62392c9e9690cd4
Signed-off-by: Lin Kesheng <lks@rock-chips.com>
This commit is contained in:
Lin Kesheng
2017-02-15 15:05:09 +08:00
parent 6a3d3e497f
commit d5dceef2c4
7 changed files with 59 additions and 5 deletions

23
hooks/install_hooks.sh Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
# install git hooks
src_dir=../../hooks
dst_dir=../.git/hooks
if test ! \( -x $dst_dir/pre-commit -a -L $dst_dir/pre-commit \);
then
rm -f $dst_dir/pre-commit
if ! ln -s $src_dir/pre-commit.hook $dst_dir/pre-commit 2> /dev/null
then
echo "Failed to create commit hook symlink, copying instead ..."
cp pre-commit.hook ../.git/hooks/pre-commit
fi
fi

31
hooks/pre-commit.hook Executable file
View File

@@ -0,0 +1,31 @@
#!/bin/sh
out_file="./fmt_df.txt"
cur_dir=$(pwd)
script_dir=tools/
echo "[git-hook]: before commit, format code use mpp_astyle.sh ..."
cd $script_dir
./mpp_astyle.sh
cd $cur_dir
git diff > $out_file
if [ -s $out_file ]
then {
echo "[git-hook]: code changed after formating, please commit again."
rm $out_file
echo "[git-hook]: git status below:"
git status
exit 1
} else {
echo "[git-hook]: nothing change after formating, commit continues."
if [ -f $out_file ]
then {
rm $out_file
} fi
exit 0
} fi

View File

@@ -422,7 +422,7 @@ MPP_RET m2vd_parser_prepare(void *ctx, MppPacket pkt, HalDecTask *task)
p->pts = mpp_packet_get_pts(pkt);
len_in = (RK_U32)mpp_packet_get_length(pkt);
if(mpp_packet_get_flag(pkt) & MPP_PACKET_FLAG_EXTRA_DATA) {
if (mpp_packet_get_flag(pkt) & MPP_PACKET_FLAG_EXTRA_DATA) {
pos += len_in;
mpp_packet_set_pos(pkt, pos);
return ret;

View File

@@ -605,7 +605,7 @@ MPP_RET mpp_quadreg_update(MppLinReg *ctx, RK_S32 x, RK_S32 r, RK_S32 wlen)
else
i--;
cq = cx[i];
cq = cx[i];
/* limite wlen when complexity change sharply */
if (idx++ > wlen)
@@ -682,7 +682,7 @@ MPP_RET mpp_quadreg_update(MppLinReg *ctx, RK_S32 x, RK_S32 r, RK_S32 wlen)
mpp_rc_dbg_rc("%e %e %e\n", b0, b1, b2);
matrix_value = a00 * a11 * a22 + a01 * a12 * a20 + a02 * a10 * a21
- a02 * a11 * a20 - a00 * a12 * a21 - a01 * a10 * a22;
- a02 * a11 * a20 - a00 * a12 * a21 - a01 * a10 * a22;
mpp_rc_dbg_rc("matrix value: %e\n", matrix_value);

View File

@@ -114,7 +114,7 @@ int VPUClientInit(VPU_CLIENT_TYPE type)
if (fd == -1) {
mpp_err_f("failed to open %s, errno = %d, error msg: %s\n",
name, errno, strerror(errno));
name, errno, strerror(errno));
return -1;
}
ret = ioctl(fd, VPU_IOC_SET_CLIENT_TYPE, (RK_U32)type);

BIN
tools/astyle Executable file

Binary file not shown.

View File

@@ -1,4 +1,4 @@
#!/bin/bash
set -e
astyle --options=astylerc ../*.cpp ../*.c ../*.h
./astyle --quiet --options=astylerc ../*.cpp ../*.c ../*.h