1*228cf40eSRouven Czerwinski#!/usr/bin/env bash 21c93c2b5SIgor Opaniuk 35392ae31SAndrew F. DavisCHECKPATCH="${CHECKPATCH:-checkpatch.pl}" 4235834c4SVesa JääskeläinenCHECKPATCH_OPT="${CHECKPATCH_OPT:-}" 51c93c2b5SIgor Opaniuk# checkpatch.pl will ignore the following paths 6070168e2SJerome ForissierCHECKPATCH_IGNORE=$(echo \ 7070168e2SJerome Forissier core/include/gen-asm-defines.h \ 8070168e2SJerome Forissier core/lib/lib{fdt,tomcrypt} core/lib/zlib \ 966666258SJens Wiklander lib/libutils lib/libmbedtls \ 10cc4de916SJerome Forissier lib/libutee/include/elf.h \ 11493b83d9SRuchika Gupta lib/libutee/include/elf_common.h \ 12660fcc53SJerome Forissier core/arch/arm/include/arm{32,64}.h \ 13ee90f22cSEtienne Carriere core/arch/arm/plat-ti/api_monitor_index_a{9,15}.h \ 145dfe80d6SVesa Jääskeläinen core/arch/arm/dts \ 15f30ea7caSMarouene Boubakri ta/pkcs11/scripts/verify-helpers.sh \ 16900bf7c6SYuichi Sugiyama core/lib/qcbor \ 17f30ea7caSMarouene Boubakri core/arch/riscv/include/encoding.h ) 181c93c2b5SIgor Opaniuk_CP_EXCL=$(for p in $CHECKPATCH_IGNORE; do echo ":(exclude)$p" ; done) 191c93c2b5SIgor Opaniuk 201c93c2b5SIgor Opaniukfunction _checkpatch() { 21c1d47bcfSEtienne Carriere # Use --typedefsfile if supported by the checkpatch tool 22c1d47bcfSEtienne Carriere typedefs_opt="--typedefsfile typedefs.checkpatch" 23c1d47bcfSEtienne Carriere $CHECKPATCH --help 2>&1 | grep -q -- --typedefsfile || \ 24c1d47bcfSEtienne Carriere typedefs_opt=""; 259d8c378dSJerome Forissier # Ignore NOT_UNIFIED_DIFF in case patch has no diff 269d8c378dSJerome Forissier # (e.g., all paths filtered out) 2779f8990dSClement Faure eval "$CHECKPATCH $CHECKPATCH_OPT $typedefs_opt -" 281c93c2b5SIgor Opaniuk} 291c93c2b5SIgor Opaniuk 301c93c2b5SIgor Opaniukfunction checkpatch() { 311c93c2b5SIgor Opaniuk git show --oneline --no-patch $1 329d8c378dSJerome Forissier # The first git 'format-patch' shows the commit message 339d8c378dSJerome Forissier # The second one produces the diff (might be empty if _CP_EXCL 349d8c378dSJerome Forissier # filters out all diffs) 359d8c378dSJerome Forissier (git format-patch $1^..$1 --stdout | sed -n '/^diff --git/q;p'; \ 369d8c378dSJerome Forissier git format-patch $1^..$1 --stdout -- $_CP_EXCL . | \ 379d8c378dSJerome Forissier sed -n '/^diff --git/,$p') | _checkpatch 381c93c2b5SIgor Opaniuk} 391c93c2b5SIgor Opaniuk 401c93c2b5SIgor Opaniukfunction checkstaging() { 411c93c2b5SIgor Opaniuk git diff --cached -- . $_CP_EXCL | _checkpatch 421c93c2b5SIgor Opaniuk} 431c93c2b5SIgor Opaniuk 441c93c2b5SIgor Opaniukfunction checkworking() { 451c93c2b5SIgor Opaniuk git diff -- . $_CP_EXCL | _checkpatch 461c93c2b5SIgor Opaniuk} 471c93c2b5SIgor Opaniuk 481c93c2b5SIgor Opaniukfunction checkdiff() { 491c93c2b5SIgor Opaniuk git diff $1...$2 -- . $_CP_EXCL | _checkpatch 501c93c2b5SIgor Opaniuk} 511c93c2b5SIgor Opaniuk 52