<commit_before>#!/bin/bash

CHECKPATCH="${CHECKPATCH:-checkpatch.pl}"
# checkpatch.pl will ignore the following paths
CHECKPATCH_IGNORE=$(echo \
		core/include/gen-asm-defines.h \
		core/lib/lib{fdt,tomcrypt} core/lib/zlib \
		lib/lib{png,utils,zlib} \
		core/arch/arm/include/arm{32,64}.h \
		core/arch/arm/plat-ti/api_monitor_index_a{9,15}.h)
_CP_EXCL=$(for p in $CHECKPATCH_IGNORE; do echo ":(exclude)$p" ; done)

function _checkpatch() {
		# Use --typedefsfile if supported by the checkpatch tool
		typedefs_opt="--typedefsfile typedefs.checkpatch"
		$CHECKPATCH --help 2>&1 | grep -q -- --typedefsfile || \
				typedefs_opt="";

		$CHECKPATCH --quiet --ignore FILE_PATH_CHANGES \
				--ignore GERRIT_CHANGE_ID --no-tree \
				$typedefs_opt \
				-
}

function checkpatch() {
		git show --oneline --no-patch $1
		git format-patch -1 $1 --stdout -- $_CP_EXCL . | _checkpatch
}

function checkstaging() {
		git diff --cached -- . $_CP_EXCL | _checkpatch
}
<commit_msg>checkpatch_inc.sh: fix case of empty commit due to path filtering<commit_after>#!/bin/bash

CHECKPATCH="${CHECKPATCH:-checkpatch.pl}"
# checkpatch.pl will ignore the following paths
CHECKPATCH_IGNORE=$(echo \
		core/include/gen-asm-defines.h \
		core/lib/lib{fdt,tomcrypt} core/lib/zlib \
		lib/lib{png,utils,zlib} \
		core/arch/arm/include/arm{32,64}.h \
		core/arch/arm/plat-ti/api_monitor_index_a{9,15}.h)
_CP_EXCL=$(for p in $CHECKPATCH_IGNORE; do echo ":(exclude)$p" ; done)

function _checkpatch() {
		# Use --typedefsfile if supported by the checkpatch tool
		typedefs_opt="--typedefsfile typedefs.checkpatch"
		$CHECKPATCH --help 2>&1 | grep -q -- --typedefsfile || \
				typedefs_opt="";
		# Ignore NOT_UNIFIED_DIFF in case patch has no diff
		# (e.g., all paths filtered out)
		$CHECKPATCH --quiet --ignore FILE_PATH_CHANGES \
				--ignore GERRIT_CHANGE_ID \
				--ignore NOT_UNIFIED_DIFF \
				--no-tree \
				$typedefs_opt \
				-
}

function checkpatch() {
	git show --oneline --no-patch $1
	# The first git 'format-patch' shows the commit message
	# The second one produces the diff (might be empty if _CP_EXCL
	# filters out all diffs)
	(git format-patch $1^..$1 --stdout | sed -n '/^diff --git/q;p'; \
	 git format-patch $1^..$1 --stdout -- $_CP_EXCL . | \
		sed -n '/^diff --git/,$p') | _checkpatch
}

function checkstaging() {
		git diff --cached -- . $_CP_EXCL | _checkpatch
}

{'fraction_non_alphanumeric': 0.1521555367709214, 'fraction_numerical': 0.01098901098901099, 'mean_word_length': 3.3193430656934306, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3188167', 'n_tokens_mistral': 987, 'n_tokens_neox': 881, 'n_words': 200}