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