--- trunk/svn2cvs.pl 2004/03/09 21:02:42 2 +++ trunk/svn2cvs.pl 2004/03/09 21:54:36 4 @@ -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,62 +50,79 @@ system $cmd || die "$errmsg: $!"; } +# +# sub to commit .svn rev file later +# +sub commit_svnrev { + my $rev = shift @_; + my $add_new = shift @_; + + die "commit_svnrev needs revision" if (! defined($rev)); + + open(SVNREV,"> $CVSREP/.svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; + print SVNREV $rev; + close(SVNREV); + + my $path=".svnrev"; + + if ($add_new) { + system "$cvs add $CVSREP/$path" || die "cvs add of $path failed: $!"; + } else { + my $msg="subversion revision $rev commited to CVS"; + print "$msg\n"; + system "$cvs commit -m \"$msg\" $CVSREP/$path" || die "cvs commit of $path failed: $!"; + } +} + # ok, now do the checkout -log_system("$cvs checkout $CVSREP","cvs checkout failed"); +log_system("$cvs -q checkout $CVSREP","cvs checkout failed"); -# check if svnrev exists +my $rev; +# check if svnrev exists if (! -e "$CVSREP/.svnrev") { print <<_USAGE_; - Your CVS repository doesn't have $TMPDIR/$CVSREP/.svnrev file! +Your CVS repository doesn't have .svnrev file! - This file is used to commit changes to CVS repository with correct - logs from Subversion. +This file is used to keep CVS repository and SubVersion in sync, so +that only newer changes will be commited. - 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 +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. _USAGE_ - print "CVS Repository left in $TMPDIR/$CVSREP\n"; - exit 1; -} - -open(SVNREV,"$CVSREP/.svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; -my $rev = ; -chomp($rev); -close(SVNREV); + 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); +} print "Starting after revision $rev\n"; $rev++; # -# sub to commit .svn rev file later -# - -sub commit_svnrev($) { - my $rev = shift @_ || die "commit_svnrev needs revision"; - - open(SVNREV,"> $CVSREP/.svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; - print SVNREV $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: $!"; -} - -# # FIXME!! HEAD should really be next verison and loop because this way we # loose multiple edits of same file and corresponding messages. On the # other hand, if you want to compress your traffic to CVS server and don't @@ -131,8 +155,6 @@ exit 0; } -print Dumper($xml); - foreach my $e (@{$xml->{'logentry'}}) { die "BUG: revision from .svnrev ($rev) greater than from subversion (".$e->{'revision'}.")" if ($rev > $e->{'revision'}); $rev = $e->{'revision'};