#!/bin/bash
#usage:
# svndumpchangesets [<int> [<int>]]

# defaults
rev=0
tip=`svn info`
max=`echo ${tip} | awk '{ print $12 }' | sed -e 's/:.*//g'`

# parse command line options, if specified
if [ "$1" != "" ] ; then
	if [ $1 -gt 0 ] ; then
		rev=$1
	fi
	if [ "$2" != "" ] ; then
		if [ $2 -gt $1 ] ; then
			max=$2
		fi
	fi
fi

if [ $rev -gt $max ] ; then
	echo 'A revision greater than the working repository was specified. Exiting ...'
	exit 1
fi

output='dumped_changesets'
if  [ -d ${output} ] ; then
	# be happy
	echo ''
else
	mkdir ${output}
fi
echo $rev
echo $max
while [ $rev -le $max ] ; do
	echo "Creating a logged patch for ${rev} ..."
	#echo "hg -v log -r ${rev} > ${output}/${rev}.patch"
	#echo "hg diff -r ${rev} >> ${output}/${rev}.patch"
	#svn log -r ${rev} | sed -e '1,3d' | sed -e '$d' | sed -e '/^$/d' > ${output}/${rev}.patch
	patchfile="${output}/svn-${rev}.patch"
	svn log -c ${rev}  > ${patchfile}
	svn diff -c ${rev} >> ${patchfile}
	rev=`expr ${rev} + 1`
done
