From f5fd113cbf10269b8792cacb432ccf5e35ad900c Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Tue, 23 Jan 2018 14:35:46 -0500 Subject: [PATCH] tools: enable stylechecker to handle new files Since the tool is entirely diff based, it was having some issues diffing things that didn't exist. Also made it a bit smarter about ignoring kernel-specific style nits we don't really care about. Signed-off-by: Quentin Young --- tools/checkpatch.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/checkpatch.sh b/tools/checkpatch.sh index adbd3c7ebd..42ea8dbb38 100755 --- a/tools/checkpatch.sh +++ b/tools/checkpatch.sh @@ -13,15 +13,18 @@ if [[ -z "$1" || -z "$2" ]]; then exit 0 fi +# remove temp directories +rm -rf /tmp/f1 /tmp/f2 + # save working tree if git -C $tree status --porcelain | egrep --silent '^(\?\?|.[DM])'; then echo "Detected dirty tree, caching state..." dirty=1 git -C $tree config gc.auto 0; td=$(git -C $tree status -z | grep -z "^[ARM]D" | cut -z -d' ' -f2- | tr '\0' '\n') - INDEX=`git -C $tree write-tree` + INDEX=$(git -C $tree write-tree) git -C $tree add -f . - WORKTREE=`git -C $tree write-tree` + WORKTREE=$(git -C $tree write-tree) echo "Saved index to $INDEX" echo "Saved working tree to $WORKTREE" fi @@ -36,11 +39,14 @@ git -C $tree reset --hard git -C $tree apply < $patch mkdir -p /tmp/f1 /tmp/f2 mod=$(git -C $tree ls-files -m | grep ".*\.[ch]" | grep -v $ignore) +mod+=" $(git -C $tree ls-files --others --exclude-standard | grep '.*\.[ch]' | grep -v $ignore)" +echo $mod if [ -z "$mod" ]; then echo "There doesn't seem to be any changes." else cp $tree/$mod /tmp/f1/ git -C $tree reset --hard + git -C $tree clean -fd cp $tree/$mod /tmp/f2/ echo "Running style checks..." for file in /tmp/f1/*; do @@ -56,12 +62,11 @@ else echo "Report for $(basename $file _cp)" echo "===============================================" if [ -a /tmp/f2/$(basename $file) ]; then - diff $file /tmp/f2/$(basename $file) | grep -A3 "ERROR\|WARNING" + diff $file /tmp/f2/$(basename $file) | grep -v "normally be const" | grep -A3 "ERROR\|WARNING" else - cat $file + cat $file | grep -v "normally be const" | grep -A3 "ERROR\|WARNING" fi done - rm -rf /tmp/f1 /tmp/f2 fi # restore working tree