#! /bin/sh

# Written by Roland McGrath <roland@frob.com>

# For people that want to move an existing tree, Roland McGrath just
# posted a script to the libc-alpha list.  Without permission, I repost
# it here. It is used as
#
#   newcvsroot :pserver:anoncvs@anoncvs.cygnus.com:/cvs/src src binutils
#
# where the first parameter is the CVSROOT, the second is the module,
# and the third is the directory containing the tree.  It writes all
# CVS/Root and CVS/Repository files.
#
# Please note that the script requires an advanced shell, like bash (or
# probably ksh).


root=$1; shift
module=$1; shift
topdir=$1; shift

rep=`echo $root|sed -e's/.*://'`

case "$topdir" in
/*|./*|../*) echo >&2 "$0 wants relative path from top of checkout"; exit 1;;
esac

find $topdir \( -name Repository -o -name Root \) -print | while read f; do

case "$f" in
*/CVS/Root) echo $root > $f ;;
*/CVS/Repository)
  r=${module}${f#${topdir}}
  echo > $f $rep/${r%/CVS/Repository}
  ;;
esac

done
