#!/bin/sh -e
# This script is put in the public domain by Henrik Nordström
# <hno@squid-cache.org>. It is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# If you find this script useful then you are encouraged to send feedback
# to the author, but you have absolutely no obligation to do so.
#
# Author:
#   Henrik Nordström <hno@squid-cache.org>
#   http://hem.passagen.se/hno/
#
# Distribution URL:
#   http://devel.squid-cache.org/CVS.html
#
# Version history:
#   2001-12-25	First public domain release
#
if [ $# -ne 2 ]; then
   echo "Usage: $0 old new"
   echo "    where old is the old ancestor branch, and new is the new ancestor"
   echo "    future tracking should follow. Next cvsmerge call will merge"
   echo "    all changes between the old and the new ancestors into this tree"
   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
    localtag=HEAD
fi
rootdir=`cat CVS/Root|sed -e 's/.*://'`
module=`cat CVS/Repository|sed -e "s#^$rootdir##"`
oldbase="$1"
newbase="$2"
mergetag="Z-${localtag}_merge_${oldbase}"
newmergetag="Z-${localtag}_merge_${newbase}"
oldmergetag="Z-${localtag}_merge-old_${oldbase}"
oldpositiontag="Z-${localtag}_old_${oldbase}"

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

o Set up tracking of the new base branch
ecvs -q rtag -F -r ${mergetag} ${newmergetag} ${module}

o Save a old marker on the old base
ecvs -q rtag -F -r ${mergetag} ${oldmergetag} ${module}
ecvs -q rtag -F -r ${localtag} ${oldpositiontag} ${module}

o Delete the tracking from the old base
ecvs -q rtag -d ${mergetag} ${module}

echo "Done."