以下以全志平台添加代码检查举例:
1>在本地仓库的.git/hooks 目录下添加pre-commit脚本

pre-commit的内容如下:
#!/bin/sh
#
# pre-commit hook to run check-patch on the output and stop any commits
# that do not pass. Note, only for git-commit, and not for any of the
# other scenarios
#
# Copyright 2010 Ben Dooks, <ben-linux@fluff.org>
if git rev-parse --verify HEAD 2>/dev/null >/dev/null
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
git diff --cached $against -- '*.c' '*.h'| ${PWD}/linux-4.9/scripts/checkpatch.pl --no-signoff
2> 提交代码时自动进行代码检查,通不过时,自动停止提交,并打印错误日志
git add .
git status

git commit

对错误进行修改后,再次git commit,检查通过后,将会进入填写提交信息界面

通过该方式能够确保我们的代码风格符合Linux内核的编码规范。scripts目录下的工具Lindent可以用来自动修改缩进问题。提醒一下,使用Lindent要求系统安装indent这个工具。
使用示例如下:
scripts/Lindent print_msg.c
sed是一个流编辑器,其强大的功能可以帮助我们处理很多重复性的工作。比如,Linux内核的coding style要求,行尾不能有空格(包括Tab),去除这些空格就可以借助sed。 使用示例如下:
sed -i 's/\s*$//' your_code.c
去掉^M
sed -i "s/\r//g" your_code.c

被折叠的 条评论
为什么被折叠?



