1#!/bin/bash 2# SPDX-License-Identifier: BSD-2-Clause 3 4CHECKPATCH="${CHECKPATCH:-checkpatch.pl}" 5# checkpatch.pl will ignore the following paths 6CHECKPATCH_IGNORE=$(echo ) 7_CP_EXCL=$(for p in $CHECKPATCH_IGNORE; do echo ":(exclude)$p" ; done) 8 9function _checkpatch() { 10 # Use --typedefsfile if supported by the checkpatch tool 11 typedefs_opt="--typedefsfile typedefs.checkpatch" 12 $CHECKPATCH --help 2>&1 | grep -q -- --typedefsfile || \ 13 typedefs_opt=""; 14 # Ignore NOT_UNIFIED_DIFF in case patch has no diff 15 # (e.g., all paths filtered out) 16 $CHECKPATCH --quiet --ignore FILE_PATH_CHANGES \ 17 --ignore GERRIT_CHANGE_ID \ 18 --ignore NOT_UNIFIED_DIFF \ 19 --ignore CAMELCASE \ 20 --ignore PREFER_KERNEL_TYPES \ 21 --ignore CONCATENATED_STRING \ 22 --no-tree \ 23 --strict \ 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