Blame scripts/travis-checkpatch

Packit Service 54dbc3
#!/bin/bash
Packit Service 54dbc3
# Copyright 2017 Mellanox Technologies Ltd.
Packit Service 54dbc3
# Licensed under BSD (MIT variant) or GPLv2. See COPYING.
Packit Service 54dbc3
Packit Service 54dbc3
Packit Service 54dbc3
if [ "x$TRAVIS_EVENT_TYPE" != "xpull_request" ]; then
Packit Service 54dbc3
	# Peform checkpatch checks on pull requests only
Packit Service 54dbc3
	exit 0
Packit Service 54dbc3
fi
Packit Service 54dbc3
Packit Service 54dbc3
# The below "set" is commented, because the checkpatch.pl returns 1 (error) for warnings too.
Packit Service 54dbc3
# And the rdma-core code is not mature enough to be warning safe
Packit Service 54dbc3
# set -e
Packit Service 54dbc3
Packit Service 54dbc3
if [ "x$TRAVIS_COMMIT_RANGE" != "x" ]; then
Packit Service 54dbc3
	wget -q https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/scripts/checkpatch.pl \
Packit Service 54dbc3
	        https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/scripts/spelling.txt
Packit Service 54dbc3
	DIR_FOR_PATCHES_TO_CHECK=$(mktemp -d)
Packit Service 54dbc3
	git format-patch --no-cover-letter $TRAVIS_COMMIT_RANGE ^$TRAVIS_BRANCH -o $DIR_FOR_PATCHES_TO_CHECK/
Packit Service 54dbc3
	CHECKPATCH_OPT="--no-tree --ignore PREFER_KERNEL_TYPES,FILE_PATH_CHANGES,EXECUTE_PERMISSIONS,USE_NEGATIVE_ERRNO,CONST_STRUCT $DIR_FOR_PATCHES_TO_CHECK/*"
Packit Service 54dbc3
	perl checkpatch.pl $CHECKPATCH_OPT
Packit Service 54dbc3
	if [ $? -ne 0 ]; then
Packit Service 54dbc3
		# We rerun checkpatch to simplify parsing and to understand if we failed for errors
Packit Service 54dbc3
		# For example, the output on some arbitrary patchset of the following line without awk is:
Packit Service 54dbc3
		# total: 1 errors, 3 warnings, 42 lines checked
Packit Service 54dbc3
		NUMB_ERRRORS=$(perl checkpatch.pl --terse $CHECKPATCH_OPT | awk 'BEGIN {FS = "total:"} ; {sum+=$2} END {print sum}')
Packit Service 54dbc3
		exit $NUMB_ERRRORS
Packit Service 54dbc3
	fi
Packit Service 54dbc3
fi