#!/bin/sh

#
# (c) 2007 Novell Inc. 
# Written by Hubert Figuiere <hfiguiere@novell.com>
# This script is licensed under the GNU GPL v2 or (at you option)
# any later version.
#
#
# Rebase you current checkout of upstream to a new milestone
# and just update anything that do not belong to the MWS.
#
# Usage is as follow:
# $ cd OpenOffice2
# $ cws-cvsrebase SRC680_mXXX
# XXX is the milestone. You may want to change the tag if you 
# work on a different branch. 
# Check update.log for any CVS conflict.
#
# TODO:
#  -output conflict un a readable form on stdout
#  -use EIS to allow updating the CWS checkout by just
#  passing the CWS name and let the script do the rest.
#  -allow specifying the log file on the command line
#

if test -z $1 ; then
    echo "Missing MWS anchor paramater"
    echo "Usage"
    echo "$1 CVS_tag"
    echo "with CVS_tag the anchor tag for the milestone"
    exit 255
fi

logfile=`pwd`/update.log
touch $logfile

mws=$1
shift;

for i in *
do
    if test -d $i ; then
	if test -d $i/CVS ; then 
	    (cd $i 
		match=`cat CVS/Tag | grep ^[TN]SRC680 | wc -l`
		if test x$match = x1 ; then
		    echo "$i is to be updated to $mws" >> $logfile
		    cvs -qz3 update -r $mws -Pd >> $logfile 2>&1 
		else
		    echo "$i is cws: simply updated" >> $logfile
		    cvs -qz3 update -Pd >> $logfile 2>&1 
		fi
		)
	else
	    echo "$i is not in CVS" >> $logfile
	fi
    fi
done

