--- trunk/svn2cvs.pl 2004/03/09 21:02:42 2 +++ trunk/svn2cvs.pl 2004/03/09 21:45:32 3 @@ -20,13 +20,19 @@ # cvsroot directory my $CVSROOT="$HOME/x/cvsroot"; # name of cvs repository to commit to -my $CVSREP="webpac"; +my $CVSREP="svn2cvs"; # svnroot directory -my $SVNROOT="file://$HOME/private/svn/webpac/"; +my $SVNROOT="file://$HOME/private/svn/svn2cvs"; # name of respository my $SVNREP="trunk"; +# webpac example +#$CVSROOT="$HOME/x/cvsroot"; +#$CVSREP="webpac"; +#$SVNROOT="file://$HOME/private/svn/webpac/"; +#$SVNREP="trunk"; + my $TMPDIR=tempdir( "/tmp/checkoutXXXXX", CLEANUP => 1 ); chdir($TMPDIR) || die "can't cd to $TMPDIR: $!"; @@ -34,6 +40,7 @@ # cvs command with root my $cvs="cvs -d $CVSROOT"; + # # sub to do logging and system calls # @@ -43,61 +50,78 @@ system $cmd || die "$errmsg: $!"; } +# +# sub to commit .svn rev file later +# +sub commit_svnrev { + my $rev = shift @_; + my $add_new = shift @_; -# ok, now do the checkout + die "commit_svnrev needs revision" if (! defined($rev)); -log_system("$cvs checkout $CVSREP","cvs checkout failed"); + open(SVNREV,"> $CVSREP/.svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; + print SVNREV $rev; + close(SVNREV); -# check if svnrev exists + my $path=".svnrev"; -if (! -e "$CVSREP/.svnrev") { - print <<_USAGE_; + if ($add_new) { + system "$cvs add $CVSREP/$path" || die "cvs add of $path failed: $!"; + } - Your CVS repository doesn't have $TMPDIR/$CVSREP/.svnrev file! + my $msg="subversion revision $rev commited to CVS"; + print "$msg\n"; + system "$cvs commit -m \"$msg\" $CVSREP/$path" || die "cvs commit of $path failed: $!"; +} - This file is used to commit changes to CVS repository with correct - logs from Subversion. - Please create .svnrec file with currect svn revision which - corresponds to version of checkouted tree and commit that file - to CVS repository, e.g. - - echo 233 > .svnrev - cvs add .svnrev - cvs commit -m "subversion repository revision sync file" .svnrev +# ok, now do the checkout -_USAGE_ - print "CVS Repository left in $TMPDIR/$CVSREP\n"; - exit 1; -} +log_system("$cvs -q checkout $CVSREP","cvs checkout failed"); +my $rev; -open(SVNREV,"$CVSREP/.svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; -my $rev = ; -chomp($rev); -close(SVNREV); +# check if svnrev exists +if (! -e "$CVSREP/.svnrev") { + print <<_USAGE_; -print "Starting after revision $rev\n"; -$rev++; +Your CVS repository doesn't have .svnrev file! +This file is used to keep CVS repository and SubVersion in sync, so +that only newer changes will be commited. -# -# sub to commit .svn rev file later -# +It's quote possible that this is first svn2cvs run for this repository. +If so, you will have to identify correct svn revision which +corresponds to current version of CVS repository that has just +been checkouted. + +If you migrated your cvs repository to svn using cvs2svn, this will be +last SubVersion revision. If this is initial run of conversion of +SubVersion repository to CVS, correct revision is 0. -sub commit_svnrev($) { - my $rev = shift @_ || die "commit_svnrev needs revision"; +_USAGE_ - open(SVNREV,"> $CVSREP/.svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; - print SVNREV $rev; + print "svn revision corresponding to CVS [abort]: "; + my $in = ; + chomp($in); + if ($in !~ /^\d+$/) { + print "Aborting: revision not a number\n"; + exit 1; + } else { + $rev = $in; + commit_svnrev($rev,1); # create new + } +} else { + open(SVNREV,"$CVSREP/.svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; + my $rev = ; + chomp($rev); close(SVNREV); - - my $msg="subversion revision $rev commited to CVS"; - my $path=".svnrev"; - print "$msg\n"; - system "$cvs commit -m \"$msg\" $CVSREP/$path" || die "cvs commit of $path failed: $!"; } +print "Starting after revision $rev\n"; +$rev++; + + # # FIXME!! HEAD should really be next verison and loop because this way we # loose multiple edits of same file and corresponding messages. On the