#!/bin/sh
# Copyright (c) 2007, Whirix Ltd.
# All rights reserved.
# 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-diff-dump.sh 345
# usage: ./svn-diff-dump.sh 345:367 
# 
# the argument can be any legal argument for --revision option of svn: 
# HEAD, PREV, BASE, etc
#
# it'll create folder DIFF_345/ with all the changed and added files

dir=DIFF_$1

svn update

# rename folder if already exists
if [ -d $dir ] ; then
	tempdir=`mktemp -d $dir.XXXXXX`
	mv -v $dir/* $tempdir
	rm -r -v $dir
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
for listItem in $diffList ; do
	if [ ! -d $listItem ] ; then
		mkdir -v -p $dir/`dirname $listItem`
		cp -a -v $listItem $dir/$listItem
	fi
done



