#!/bin/sh
# Copyright (c) 2007, Whirix Ltd.
# Author: Vyacheslav Iutin <iutinvg@yahoo.com>
#
# Licenced under the same terms as Subversion.
#
# What is this: make dump of files which were changed or added between given 
# revisions. It could be used if you want to upload or pass to somebody only 
# changed files, for incremental updates, etc.
#
# usage: svn-changes-dump.sh 345
# usage: svn-changes-dump.sh 345:367
# 
# the argument can be revision number or range
#
# it'll create folder CHANGES_345:367/ with all the changed and added files

SVN="svn"
DIR=CHANGES_$1

# get max number of revision from range
REV1=`echo "$1" | sed 's/^\([0-9]\+\):\([0-9]\+\)$/\1/g'`
REV2=`echo "$1" | sed 's/^\([0-9]\+\):\([0-9]\+\)$/\2/g'`
if [ $REV1 -gt $REV2 ] ; then
	MAXREV=$REV1
else
	MAXREV=$REV2
fi

# get file list
diffList=`svn log -v -r$1 | grep -E '[[:space:]]{3}(M|A)' | \
cut -d'/' -f 4-`

# create folders and copy files, we copy files of latest revision from range
for listItem in $diffList ; do
	if [ ! -d "$listItem" ] ; then
		mkdir -p "$DIR"/`dirname "$listItem"`
		$SVN cat -r$MAXREV "$listItem" > "$DIR/$listItem"
	fi
done


