#!/bin/sh

usage()
{
	cat << EOF
	Usage: `basename $0` patchdir
EOF

	exit 1
}

if [ $# -ne 1 ]; then
	usage
fi

mkdir -p $1/alreadyapplied/

for file in $1/*.patch; do
	subject=$(grep Subject $file | awk -F '] ' '{print $2}')
	git log --oneline | grep "${subject}" >/dev/null
	if [ $? -eq 0 ]; then
		echo "$file already applied"
		mv $file $1/alreadyapplied
	fi
done
