tools/checkpatch.sh: do full file check for commits and patches defaultly

Make 'checkpatch.sh -c commits' and 'checkpatch.sh -p patches' do full
file check as default, while 'checkpatch.sh -r -c commits' and 'checkpatch.sh
-r -p patches' do ranges check only.
This commit is contained in:
liuhaitao 2020-02-14 19:21:05 +08:00 committed by Gregory Nutt
parent ea72d84c4d
commit 05391da6b8

View File

@ -19,12 +19,14 @@
TOOLDIR=$(dirname $0) TOOLDIR=$(dirname $0)
fail=0 fail=0
range=0
usage() { usage() {
echo "USAGE: ${0} [options] [list|-]" echo "USAGE: ${0} [options] [list|-]"
echo "" echo ""
echo "Options:" echo "Options:"
echo "-h" echo "-h"
echo "-r range check only (used with -p and -c)"
echo "-p <patch list> (default)" echo "-p <patch list> (default)"
echo "-c <commit list>" echo "-c <commit list>"
echo "-f <file list>" echo "-f <file list>"
@ -44,7 +46,11 @@ check_ranges() {
while read; do while read; do
if [[ $REPLY =~ \+\+\+\ (b/)?([^[:blank:]]+).* ]]; then if [[ $REPLY =~ \+\+\+\ (b/)?([^[:blank:]]+).* ]]; then
if [ "$ranges" != "" ]; then if [ "$ranges" != "" ]; then
check_file $ranges $path 2>&1 if [ $range != 0 ]; then
check_file $ranges $path 2>&1
else
check_file $path 2>&1
fi
fi fi
path=${BASH_REMATCH[2]} path=${BASH_REMATCH[2]}
ranges="" ranges=""
@ -53,19 +59,25 @@ check_ranges() {
fi fi
done done
if [ "$ranges" != "" ]; then if [ "$ranges" != "" ]; then
check_file $ranges $path 2>&1 if [ $range != 0 ]; then
check_file $ranges $path 2>&1
else
check_file $path 2>&1
fi
fi fi
} }
check_patch() { check_patch() {
git apply --check $1 git apply --check $1
if [ $? != 0 ]; then ret=$?
exit 1 if [ $ret != 0 ]; then
fail=$ret
else
git apply $1
diffs=`cat $1`
check_ranges <<< "$diffs"
git apply -R $1
fi fi
git apply $1
diffs=`cat $1`
check_ranges <<< "$diffs"
git apply -R $1
} }
check_commit() { check_commit() {
@ -86,6 +98,9 @@ while [ ! -z "$1" ]; do
usage usage
exit 0 exit 0
;; ;;
-r )
range=1
;;
-p ) -p )
shift shift
patches=$@ patches=$@
@ -103,13 +118,14 @@ while [ ! -z "$1" ]; do
;; ;;
- ) - )
check_ranges check_ranges
exit 0 break
;; ;;
* ) * )
patches=$@ patches=$@
break break
;; ;;
esac esac
shift
done done
for patch in $patches; do for patch in $patches; do