1#!/bin/bash 2 3CHECKPATCH="${CHECKPATCH:-checkpatch.pl}" 4CHECKPATCH_OPT="${CHECKPATCH_OPT:-}" 5# checkpatch.pl will ignore the following paths 6CHECKPATCH_IGNORE=$(echo \ 7 core/include/gen-asm-defines.h \ 8 core/lib/lib{fdt,tomcrypt} core/lib/zlib \ 9 lib/libutils lib/libmbedtls \ 10 lib/libutee/include/elf.h \ 11 core/arch/arm/include/arm{32,64}.h \ 12 core/arch/arm/plat-ti/api_monitor_index_a{9,15}.h \ 13 core/arch/arm/dts \ 14 ta/pkcs11/scripts/verify-helpers.sh ) 15_CP_EXCL=$(for p in $CHECKPATCH_IGNORE; do echo ":(exclude)$p" ; done) 16 17function _checkpatch() { 18 # Use --typedefsfile if supported by the checkpatch tool 19 typedefs_opt="--typedefsfile typedefs.checkpatch" 20 $CHECKPATCH --help 2>&1 | grep -q -- --typedefsfile || \ 21 typedefs_opt=""; 22 # Ignore NOT_UNIFIED_DIFF in case patch has no diff 23 # (e.g., all paths filtered out) 24 $CHECKPATCH $CHECKPATCH_OPT $typedefs_opt - 25} 26 27function checkpatch() { 28 git show --oneline --no-patch $1 29 # The first git 'format-patch' shows the commit message 30 # The second one produces the diff (might be empty if _CP_EXCL 31 # filters out all diffs) 32 (git format-patch $1^..$1 --stdout | sed -n '/^diff --git/q;p'; \ 33 git format-patch $1^..$1 --stdout -- $_CP_EXCL . | \ 34 sed -n '/^diff --git/,$p') | _checkpatch 35} 36 37function checkstaging() { 38 git diff --cached -- . $_CP_EXCL | _checkpatch 39} 40 41function checkworking() { 42 git diff -- . $_CP_EXCL | _checkpatch 43} 44 45function checkdiff() { 46 git diff $1...$2 -- . $_CP_EXCL | _checkpatch 47} 48 49