#!/bin/bash
# Put this in your .procmailrc:
#	:0f
#	| patchwatch

#	:0c
#	* ^X-Watched-Patch:.*YES
#	Lists/WatchedPatches
#
# Here's an example of watching files:
#
#	$ cat ~/bin/patchwatch.list
#	mmzone.h
#	arch/(i386|ppc64|x86_64)/mm/
#	discontig.c
#	drivers/base/memory
#
# isdiff: 
##!/bin/bash
#DIFF_LINES="$(egrep '^(diff|--- |\+\+\+ )' "$1" | wc -l)";
#if [ "$DIFF_LINES" -ge 3 ]; then
#	true;
#else
#	false;
#fi;



TEMP=`mktemp /tmp/patchwatch-XXXXXXX < /dev/null`;
cat > $TEMP;

FILES=""
if isdiff $TEMP; then
	FILES="$(cat $TEMP \
		| formail -I "" \
		| grep '^[+][+][+] ' | awk '{print $2}' \
		| perl -pe 's|^.*?/||' \
		| grep -E -f ~/bin/patchwatch.list \
		| perl -pe 's/\n/ /g')"
fi

if [ -n "$FILES" ]; then
	cat $TEMP | formail -a "X-Watched-Patch: YES -- '$FILES'"
else
	cat $TEMP
fi
rm $TEMP;
