#!/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 for incremental updates or if you want to pass
# somebody only changed files, etc.
#
# usage: svn-changes-dump.sh 345
# usage: svn-changes-dump.sh 345:367
# usage: svn-changes-dump.sh 345:HEAD
# 
# The argument can be any legal argument for --revision option of svn. If you 
# use range the last part of argument will be used for export. The files will
# be exported to the folder with name like CHANGES_345:367/.

SVN='svn'
DIR="CHANGES_$1"

# get last revision from range
MAXREV=${1#*:}

# 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 export -r$MAXREV "$listItem"@$MAXREV "$DIR/$listItem"
	fi
done



