checkpatch.sh: Simplify the code logic, no functional change
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
d53566118e
commit
cf674ed51c
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
TOOLDIR=$(dirname $0)
|
TOOLDIR=$(dirname $0)
|
||||||
|
|
||||||
|
check=check_patch
|
||||||
fail=0
|
fail=0
|
||||||
range=0
|
range=0
|
||||||
spell=0
|
spell=0
|
||||||
@ -36,10 +37,12 @@ usage() {
|
|||||||
echo " git diff --cached | ./tools/checkpatch.sh -"
|
echo " git diff --cached | ./tools/checkpatch.sh -"
|
||||||
echo "Where a <commit list> is any syntax supported by git for specifying git revision, see GITREVISIONS(7)"
|
echo "Where a <commit list> is any syntax supported by git for specifying git revision, see GITREVISIONS(7)"
|
||||||
echo "Where a <patch file names> is a space separated list of patch file names or wildcard. or *.patch"
|
echo "Where a <patch file names> is a space separated list of patch file names or wildcard. or *.patch"
|
||||||
|
|
||||||
|
exit $@
|
||||||
}
|
}
|
||||||
|
|
||||||
check_file() {
|
check_file() {
|
||||||
$TOOLDIR/nxstyle $@
|
$TOOLDIR/nxstyle $@ 2>&1
|
||||||
ret=$?
|
ret=$?
|
||||||
if [ $ret != 0 ]; then
|
if [ $ret != 0 ]; then
|
||||||
fail=$ret
|
fail=$ret
|
||||||
@ -59,9 +62,9 @@ check_ranges() {
|
|||||||
if [[ $REPLY =~ ^(\+\+\+\ (b/)?([^[:blank:]]+).*)$ ]]; then
|
if [[ $REPLY =~ ^(\+\+\+\ (b/)?([^[:blank:]]+).*)$ ]]; then
|
||||||
if [ "$ranges" != "" ]; then
|
if [ "$ranges" != "" ]; then
|
||||||
if [ $range != 0 ]; then
|
if [ $range != 0 ]; then
|
||||||
check_file $ranges $path 2>&1
|
check_file $ranges $path
|
||||||
else
|
else
|
||||||
check_file $path 2>&1
|
check_file $path
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
path=${BASH_REMATCH[3]}
|
path=${BASH_REMATCH[3]}
|
||||||
@ -72,9 +75,9 @@ check_ranges() {
|
|||||||
done
|
done
|
||||||
if [ "$ranges" != "" ]; then
|
if [ "$ranges" != "" ]; then
|
||||||
if [ $range != 0 ]; then
|
if [ $range != 0 ]; then
|
||||||
check_file $ranges $path 2>&1
|
check_file $ranges $path
|
||||||
else
|
else
|
||||||
check_file $path 2>&1
|
check_file $path
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -106,53 +109,39 @@ fi
|
|||||||
|
|
||||||
while [ ! -z "$1" ]; do
|
while [ ! -z "$1" ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h )
|
- )
|
||||||
usage
|
check_ranges
|
||||||
exit 0
|
|
||||||
;;
|
;;
|
||||||
-c )
|
-c )
|
||||||
spell=1
|
spell=1
|
||||||
;;
|
;;
|
||||||
|
-f )
|
||||||
|
check=check_file
|
||||||
|
;;
|
||||||
|
-g )
|
||||||
|
check=check_commit
|
||||||
|
;;
|
||||||
|
-h )
|
||||||
|
usage 0
|
||||||
|
;;
|
||||||
|
-p )
|
||||||
|
check=check_patch
|
||||||
|
;;
|
||||||
-r )
|
-r )
|
||||||
range=1
|
range=1
|
||||||
;;
|
;;
|
||||||
-p )
|
-* )
|
||||||
shift
|
usage 1
|
||||||
patches=$@
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
-g )
|
|
||||||
shift
|
|
||||||
commits=$@
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
-f )
|
|
||||||
shift
|
|
||||||
files=$@
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
- )
|
|
||||||
check_ranges
|
|
||||||
break
|
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
patches=$@
|
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
for patch in $patches; do
|
for arg in $@; do
|
||||||
check_patch $patch
|
$check $arg
|
||||||
done
|
|
||||||
|
|
||||||
for commit in $commits; do
|
|
||||||
check_commit $commit
|
|
||||||
done
|
|
||||||
|
|
||||||
for file in $files; do
|
|
||||||
check_file $file 2>&1
|
|
||||||
done
|
done
|
||||||
|
|
||||||
exit $fail
|
exit $fail
|
||||||
|
Loading…
x
Reference in New Issue
Block a user