#!/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-09-25	First public domain release
#
if [ $# -lt 1 ]; then
   cat <<- EOF
	usage: $0 merge_from [base_branch]
	usage: $0 merge_from [-r based_on_tag]
	merge_from is the branch to track in this tree.  base_branch is
	the branch it's based on.  base_on_tag is the startingpoint of
	next call to cvsmerge.  If no base is specified, then it will be
	the current state of merge_from.

	Two different uses of based_on_tag exists:
	a) To specify the base of the branch to be merged
	b) To specify our current base branch, when moving our base to
	   another branch.
	EOF
    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!!"`
mergetag=$1
if [ "$2" = "-r" ]; then
   roottag="$3"
elif [ -n "$2" ]; then
   roottag="Z-${mergetag}_merge_${2}"
else
   roottag="$mergetag"
fi
basetag="Z-${localtag}_merge_${mergetag}"
if [ -z "$localtag" ] || [ -z "$roottag" ]; then
    echo "Incorrect use"
    exit 1
fi
if [ "$mergetag" = "$roottag" ]; then
    echo "Are you sure you want to reset merge tracking of $localtag to the current state of $mergetag?"
    echo "This assumes both trees is up to date and that all parent changes is in your tree already."
    echo -n "Continue (Yes/No)? "
read ans
case $ans in
[Yy]*)
    # OK
    ;;
*|"")
    echo "Aborted!"
    exit 1
    ;;
esac
fi
cvs rtag -F -r $roottag $basetag $module