#!/bin/sh

usage() {
    echo 1>&2 << EOF
cws-extract [-s] cws_name
Create a patch from an up-stream CWS suitable for ooo-build.

  -s            Don't ignore changes in whitespace.
EOF
    exit 1;
}

echo "Warning!  This is the SVN version of cws-extract, use
cws-extract-cvs for the older OOo CWSes."

CWS=""
DIFFPARAMS="-ubwp"
while [ -n "$1" ] ; do
    case "$1" in
        -s) DIFFPARAMS="-up"
            ;;
        *)  CWS="$1"
            ;;
    esac
    shift
done

[ -n "$CWS" ] || usage

# log of the branch only
MERGE_BASE=`svn log --stop-on-copy "svn+ssh://svn@svn.services.openoffice.org/ooo/cws/$CWS" | \
            grep 'CWS-TOOLING: \(rebase\|create\) CWS' | head -n 1 | \
            sed 's/^.*trunk@\([0-9]\+\).*$/\1/'`

if [ -n "$MERGE_BASE" ] ; then
    svn diff -x "$DIFFPARAMS" "svn+ssh://svn@svn.services.openoffice.org/ooo/trunk@$MERGE_BASE" "svn+ssh://svn@svn.services.openoffice.org/ooo/cws/$CWS" > "cws-$CWS.diff"
fi
