From 05391da6b87a59327c4456eb94d320ec1f868c1b Mon Sep 17 00:00:00 2001 From: liuhaitao Date: Fri, 14 Feb 2020 19:21:05 +0800 Subject: [PATCH] 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. --- tools/checkpatch.sh | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/tools/checkpatch.sh b/tools/checkpatch.sh index 2aaf188e7a..3b54d42b6d 100755 --- a/tools/checkpatch.sh +++ b/tools/checkpatch.sh @@ -19,12 +19,14 @@ TOOLDIR=$(dirname $0) fail=0 +range=0 usage() { echo "USAGE: ${0} [options] [list|-]" echo "" echo "Options:" echo "-h" + echo "-r range check only (used with -p and -c)" echo "-p (default)" echo "-c " echo "-f " @@ -44,7 +46,11 @@ check_ranges() { while read; do if [[ $REPLY =~ \+\+\+\ (b/)?([^[:blank:]]+).* ]]; 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 path=${BASH_REMATCH[2]} ranges="" @@ -53,19 +59,25 @@ check_ranges() { fi done 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 } check_patch() { git apply --check $1 - if [ $? != 0 ]; then - exit 1 + ret=$? + if [ $ret != 0 ]; then + fail=$ret + else + git apply $1 + diffs=`cat $1` + check_ranges <<< "$diffs" + git apply -R $1 fi - git apply $1 - diffs=`cat $1` - check_ranges <<< "$diffs" - git apply -R $1 } check_commit() { @@ -86,6 +98,9 @@ while [ ! -z "$1" ]; do usage exit 0 ;; + -r ) + range=1 + ;; -p ) shift patches=$@ @@ -103,13 +118,14 @@ while [ ! -z "$1" ]; do ;; - ) check_ranges - exit 0 + break ;; * ) patches=$@ break ;; esac + shift done for patch in $patches; do