1#!/bin/bash 2 3CHECKPATCH="${CHECKPATCH:-checkpatch.pl}" 4# checkpatch.pl will ignore the following paths 5CHECKPATCH_IGNORE=$(echo \ 6 core/include/gen-asm-defines.h \ 7 core/lib/lib{fdt,tomcrypt} core/lib/zlib \ 8 lib/libutils lib/libmbedtls \ 9 core/arch/arm/include/arm{32,64}.h \ 10 core/arch/arm/plat-ti/api_monitor_index_a{9,15}.h) 11_CP_EXCL=$(for p in $CHECKPATCH_IGNORE; do echo ":(exclude)$p" ; done) 12 13function _checkpatch() { 14 # Use --typedefsfile if supported by the checkpatch tool 15 typedefs_opt="--typedefsfile typedefs.checkpatch" 16 $CHECKPATCH --help 2>&1 | grep -q -- --typedefsfile || \ 17 typedefs_opt=""; 18 # Ignore NOT_UNIFIED_DIFF in case patch has no diff 19 # (e.g., all paths filtered out) 20 $CHECKPATCH --quiet --ignore FILE_PATH_CHANGES \ 21 --ignore GERRIT_CHANGE_ID \ 22 --ignore NOT_UNIFIED_DIFF \ 23 --no-tree \ 24 $typedefs_opt \ 25 - 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