#!/usr/bin/perl
#
# This perl script changes absolute CVS repository pathnames
# into relative ones by stripping off everything up to (and including)
# "cvs/".  So "/usr/users/e614mgr/cvs/triumf/mofia2" becomes
# "triumf/mofia2".  -RPM 01.05.08
#
# Script is based on one by Konstantin Olchanski.
#

$| = 1;

$dropupto = "cvs/";

open (FIND,"find . -type d -print |");
while (<FIND>)
  {
    chop;
    dodir($_);
  }
close FIND;

exit 0;

sub dodir
  {
    my $dir = shift @_;
    my $toss = "";
    my $keep = "";

    return if ! -d "$dir/CVS";

    my $cvsroot = `cat $dir/CVS/Root`; chop $cvsroot;
    my $cvsrepo = `cat $dir/CVS/Repository`; chop $cvsrepo;

    my $pad = " " x (30 - length($dir));

    print "dir: [$dir] $pad [$cvsrepo]\n";

    # Break the Repository into what we get rid of and what we keep.
    ($toss, $keep) = split($dropupto, $cvsrepo);

    # If there's anything in $keep, write that to the repository file.
    # Otherwise don't change it.
    if ($keep ne "")
    {
        print "Changing repository to [$keep]\n";
        `echo $keep > $dir/CVS/Repository`;
    }
  }

#end file
