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