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 \ 866666258SJens Wiklander lib/libutils lib/libmbedtls \ 9*cc4de916SJerome Forissier lib/libutee/include/elf.h \ 10660fcc53SJerome Forissier core/arch/arm/include/arm{32,64}.h \ 11ee90f22cSEtienne Carriere core/arch/arm/plat-ti/api_monitor_index_a{9,15}.h \ 12ee90f22cSEtienne Carriere core/arch/arm/dts) 131c93c2b5SIgor Opaniuk_CP_EXCL=$(for p in $CHECKPATCH_IGNORE; do echo ":(exclude)$p" ; done) 141c93c2b5SIgor Opaniuk 151c93c2b5SIgor Opaniukfunction _checkpatch() { 16c1d47bcfSEtienne Carriere # Use --typedefsfile if supported by the checkpatch tool 17c1d47bcfSEtienne Carriere typedefs_opt="--typedefsfile typedefs.checkpatch" 18c1d47bcfSEtienne Carriere $CHECKPATCH --help 2>&1 | grep -q -- --typedefsfile || \ 19c1d47bcfSEtienne Carriere typedefs_opt=""; 209d8c378dSJerome Forissier # Ignore NOT_UNIFIED_DIFF in case patch has no diff 219d8c378dSJerome Forissier # (e.g., all paths filtered out) 2211ec4014SMaxim Uvarov $CHECKPATCH $typedefs_opt - 231c93c2b5SIgor Opaniuk} 241c93c2b5SIgor Opaniuk 251c93c2b5SIgor Opaniukfunction checkpatch() { 261c93c2b5SIgor Opaniuk git show --oneline --no-patch $1 279d8c378dSJerome Forissier # The first git 'format-patch' shows the commit message 289d8c378dSJerome Forissier # The second one produces the diff (might be empty if _CP_EXCL 299d8c378dSJerome Forissier # filters out all diffs) 309d8c378dSJerome Forissier (git format-patch $1^..$1 --stdout | sed -n '/^diff --git/q;p'; \ 319d8c378dSJerome Forissier git format-patch $1^..$1 --stdout -- $_CP_EXCL . | \ 329d8c378dSJerome Forissier sed -n '/^diff --git/,$p') | _checkpatch 331c93c2b5SIgor Opaniuk} 341c93c2b5SIgor Opaniuk 351c93c2b5SIgor Opaniukfunction checkstaging() { 361c93c2b5SIgor Opaniuk git diff --cached -- . $_CP_EXCL | _checkpatch 371c93c2b5SIgor Opaniuk} 381c93c2b5SIgor Opaniuk 391c93c2b5SIgor Opaniukfunction checkworking() { 401c93c2b5SIgor Opaniuk git diff -- . $_CP_EXCL | _checkpatch 411c93c2b5SIgor Opaniuk} 421c93c2b5SIgor Opaniuk 431c93c2b5SIgor Opaniukfunction checkdiff() { 441c93c2b5SIgor Opaniuk git diff $1...$2 -- . $_CP_EXCL | _checkpatch 451c93c2b5SIgor Opaniuk} 461c93c2b5SIgor Opaniuk 47