#!/bin/bash -e
if [ $# -ne 1 ]; then
   echo "Usage: $0 base-tag"
   echo "    where base-tag is the base branch the diff should start from"
   echo "    (usually HEAD, but you should know...)"
   exit 1
fi
if [ ! -f CVS/Root ] || [ ! -f CVS/Repository ]; then
    echo "ERROR: The script must be run from a CVS working directory"
    exit 1
fi
if [ -f CVS/Tag ]; then
    localtag=`cat CVS/Tag|cut -c2-`
else
    echo "ERROR: The script can only be run from branches. Running"
    echo "it from the HEAD version does not make sense."
    exit 1
fi
rootdir=`cat CVS/Root|sed -e 's/.*://'`
module=`cat CVS/Repository|sed -e "s#^$rootdir##"`
mergefrom="$1"
mergetag="Z-${localtag}_merge_${mergefrom}"

ecvs() {
    echo cvs $* >&2
    cvs "$@"
}
o () {
    echo "# $*..."
}

echo "Patch file generated `date` from"
echo "CVS branch ${localtag}"
echo "CVS repository: `cat CVS/Root`"
echo "CVS module: $module"
echo
ecvs -z9 -q rdiff -u -kk -r ${mergetag} -r ${localtag} ${module} | cleanpatch
