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