You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/04/20 13:07:41 UTC

[incubator-nuttx] 01/09: checkpatch.sh: Simplify the code logic, no functional change

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit cf674ed51c904e41474be2ffb46319cf795d0553
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Apr 18 20:53:21 2020 +0800

    checkpatch.sh: Simplify the code logic, no functional change
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 tools/checkpatch.sh | 61 ++++++++++++++++++++++-------------------------------
 1 file changed, 25 insertions(+), 36 deletions(-)

diff --git a/tools/checkpatch.sh b/tools/checkpatch.sh
index 18a9848..08adb21 100755
--- a/tools/checkpatch.sh
+++ b/tools/checkpatch.sh
@@ -18,6 +18,7 @@
 
 TOOLDIR=$(dirname $0)
 
+check=check_patch
 fail=0
 range=0
 spell=0
@@ -36,10 +37,12 @@ usage() {
   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 <patch file names> is a space separated list of patch file names or wildcard. or *.patch"
+
+  exit $@
 }
 
 check_file() {
-  $TOOLDIR/nxstyle $@
+  $TOOLDIR/nxstyle $@ 2>&1
   ret=$?
   if [ $ret != 0 ]; then
     fail=$ret
@@ -59,9 +62,9 @@ check_ranges() {
     if [[ $REPLY =~ ^(\+\+\+\ (b/)?([^[:blank:]]+).*)$ ]]; then
       if [ "$ranges" != "" ]; then
         if [ $range != 0 ]; then
-          check_file $ranges $path 2>&1
+          check_file $ranges $path
         else
-          check_file $path 2>&1
+          check_file $path
         fi
       fi
       path=${BASH_REMATCH[3]}
@@ -72,9 +75,9 @@ check_ranges() {
   done
   if [ "$ranges" != "" ]; then
     if [ $range != 0 ]; then
-      check_file $ranges $path 2>&1
+      check_file $ranges $path
     else
-      check_file $path 2>&1
+      check_file $path
     fi
   fi
 }
@@ -106,53 +109,39 @@ fi
 
 while [ ! -z "$1" ]; do
   case "$1" in
-  -h )
-    usage
-    exit 0
+  - )
+    check_ranges
     ;;
   -c )
     spell=1
     ;;
-  -r )
-    range=1
-    ;;
-  -p )
-    shift
-    patches=$@
-    break
+  -f )
+    check=check_file
     ;;
   -g )
-    shift
-    commits=$@
-    break
+    check=check_commit
     ;;
-  -f )
-    shift
-    files=$@
-    break
+  -h )
+    usage 0
     ;;
-  - )
-    check_ranges
-    break
+  -p )
+    check=check_patch
+    ;;
+  -r )
+    range=1
+    ;;
+  -* )
+    usage 1
     ;;
   * )
-    patches=$@
     break
     ;;
   esac
   shift
 done
 
-for patch in $patches; do
-  check_patch $patch
-done
-
-for commit in $commits; do
-  check_commit $commit
-done
-
-for file in $files; do
-  check_file $file 2>&1
+for arg in $@; do
+  $check $arg
 done
 
 exit $fail