11c93c2b5SIgor Opaniuk#!/bin/bash 21c93c2b5SIgor Opaniuk 35392ae31SAndrew F. DavisCHECKPATCH="${CHECKPATCH:-checkpatch.pl}" 41c93c2b5SIgor Opaniuk# checkpatch.pl will ignore the following paths 5070168e2SJerome ForissierCHECKPATCH_IGNORE=$(echo \ 6070168e2SJerome Forissier core/include/gen-asm-defines.h \ 7070168e2SJerome Forissier core/lib/lib{fdt,tomcrypt} core/lib/zlib \ 8*66666258SJens Wiklander lib/libutils lib/libmbedtls \ 9660fcc53SJerome Forissier core/arch/arm/include/arm{32,64}.h \ 1038f23772SAndrew F. Davis core/arch/arm/plat-ti/api_monitor_index_a{9,15}.h) 111c93c2b5SIgor Opaniuk_CP_EXCL=$(for p in $CHECKPATCH_IGNORE; do echo ":(exclude)$p" ; done) 121c93c2b5SIgor Opaniuk 131c93c2b5SIgor Opaniukfunction _checkpatch() { 14c1d47bcfSEtienne Carriere # Use --typedefsfile if supported by the checkpatch tool 15c1d47bcfSEtienne Carriere typedefs_opt="--typedefsfile typedefs.checkpatch" 16c1d47bcfSEtienne Carriere $CHECKPATCH --help 2>&1 | grep -q -- --typedefsfile || \ 17c1d47bcfSEtienne Carriere typedefs_opt=""; 189d8c378dSJerome Forissier # Ignore NOT_UNIFIED_DIFF in case patch has no diff 199d8c378dSJerome Forissier # (e.g., all paths filtered out) 201c93c2b5SIgor Opaniuk $CHECKPATCH --quiet --ignore FILE_PATH_CHANGES \ 219d8c378dSJerome Forissier --ignore GERRIT_CHANGE_ID \ 229d8c378dSJerome Forissier --ignore NOT_UNIFIED_DIFF \ 239d8c378dSJerome Forissier --no-tree \ 24c1d47bcfSEtienne Carriere $typedefs_opt \ 25c1d47bcfSEtienne Carriere - 261c93c2b5SIgor Opaniuk} 271c93c2b5SIgor Opaniuk 281c93c2b5SIgor Opaniukfunction checkpatch() { 291c93c2b5SIgor Opaniuk git show --oneline --no-patch $1 309d8c378dSJerome Forissier # The first git 'format-patch' shows the commit message 319d8c378dSJerome Forissier # The second one produces the diff (might be empty if _CP_EXCL 329d8c378dSJerome Forissier # filters out all diffs) 339d8c378dSJerome Forissier (git format-patch $1^..$1 --stdout | sed -n '/^diff --git/q;p'; \ 349d8c378dSJerome Forissier git format-patch $1^..$1 --stdout -- $_CP_EXCL . | \ 359d8c378dSJerome Forissier sed -n '/^diff --git/,$p') | _checkpatch 361c93c2b5SIgor Opaniuk} 371c93c2b5SIgor Opaniuk 381c93c2b5SIgor Opaniukfunction checkstaging() { 391c93c2b5SIgor Opaniuk git diff --cached -- . $_CP_EXCL | _checkpatch 401c93c2b5SIgor Opaniuk} 411c93c2b5SIgor Opaniuk 421c93c2b5SIgor Opaniukfunction checkworking() { 431c93c2b5SIgor Opaniuk git diff -- . $_CP_EXCL | _checkpatch 441c93c2b5SIgor Opaniuk} 451c93c2b5SIgor Opaniuk 461c93c2b5SIgor Opaniukfunction checkdiff() { 471c93c2b5SIgor Opaniuk git diff $1...$2 -- . $_CP_EXCL | _checkpatch 481c93c2b5SIgor Opaniuk} 491c93c2b5SIgor Opaniuk 50