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