blob: 1a9dc42024fd5475ff2c860c0ad55e9dca4a6d37 [file] [log] [blame]
Igor Opaniuk1c93c2b2016-11-03 13:27:28 +02001#!/bin/bash
2
3DIR="${BASH_SOURCE%/*}"
4
Markus S. Wamser33977c02018-10-17 16:30:06 +02005# if no CHECKPATCH is explicitly given by the environment, try to
6# locate checkpatch.pl: first take the one from the path, then check
7# for a local copy of the linux headers, finally try sources downloaded
8# with OP-TEE (for QEMU)
9if [ -z "$CHECKPATCH" ]; then
10 CHECKPATCH=$(command -v checkpatch.pl)
11fi
12if [ -z "$CHECKPATCH" ]; then
13 CHECKPATCH=$(find /usr/src/linux-headers* -name checkpatch.pl -print -quit)
14fi
15if [ -z "$CHECKPATCH" ]; then
16 CHECKPATCH=$(find "$PWD/../linux" -name checkpatch.pl -print -quit)
17fi
18
Igor Opaniuk1c93c2b2016-11-03 13:27:28 +020019source "$DIR/checkpatch_inc.sh"
20
21hash $CHECKPATCH 2>/dev/null ||
22 { echo >&2 "Could not find checkpatch.pl, aborting"; exit 1; }
23
24usage() {
25 SCR=$(basename "$0")
26 echo "Usage: $SCR [--working] Check working area"
Andrew Mustea77571212022-12-21 16:49:48 -080027 echo " $SCR <commit>... Check specific commits,
28 symbolic names, and/or revision
29 selections"
Igor Opaniuk1c93c2b2016-11-03 13:27:28 +020030 echo " $SCR --diff <commit1> <commit2> Check diff commit1...commit2"
31 echo " $SCR --cached Check staging area"
32 echo " $SCR --help This help"
33 exit 1
34}
35
36op=${1:---working}
37case "$op" in
38 --cached)
39 echo "Checking staging area: "
40 checkstaging
41 ;;
42 --diff)
43 echo "Checking diff (diff $1...$2)"
44 checkdiff "$2" "$3"
45 ;;
46 --working)
47 echo "Checking working area: "
48 checkworking
49 ;;
50 --help|-h)
51 usage
52 ;;
53 *)
Jerome Forissier849b17b2017-02-22 18:11:36 +010054 echo "Checking commit(s):"
Andrew Mustea77571212022-12-21 16:49:48 -080055 read -r MAJOR MINOR < <(git --version | awk -F '[. ]' '{print $3, $4}')
56 if (( MAJOR < 2 )) || (( MAJOR == 2 && MINOR < 19 )); then
57 for c in "$@"; do checkpatch "$c"; done
58 else
59 for arg in "$@"; do
60 # parse the argument into a git object or list of git objects
61 object="$(git rev-parse "${arg}")" || continue
62 # run checkpatch if the parsed argument represents a single commit hash
63 if git cat-file -e "${object}" 2>/dev/null; then
64 checkpatch "${object}"
65 else
66 # expand the object list and run checkpatch on each commit id
67 commits="$(echo "${object}" | git rev-list --stdin)"
68 for c in ${commits}; do checkpatch "$c"; done
69 fi
70 done
71 fi
72 ;;
Igor Opaniuk1c93c2b2016-11-03 13:27:28 +020073
74esac