--- trunk/svn2cvs.pl 2004/03/09 21:02:42 2 +++ trunk/svn2cvs.pl 2004/03/09 22:35:55 7 @@ -18,15 +18,24 @@ my $HOME = $ENV{'HOME'} || die "can't get home directory!"; # cvsroot directory -my $CVSROOT="$HOME/x/cvsroot"; +my $CVSROOT=':pserver:dpavlin@cvs.tigris.org:/cvs'; # name of cvs repository to commit to -my $CVSREP="webpac"; +my $CVSREP="svn2cvs/src"; + +$CVSROOT="$HOME/x/cvsroot"; +$CVSREP="svn2cvs/src"; # 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: $!"; @@ -43,61 +52,80 @@ 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,"> .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 $path" || die "cvs add of $path failed: $!"; + } else { + my $msg="subversion revision $rev commited to CVS"; + print "$msg\n"; + system "$cvs commit -m \"$msg\" $path" || die "cvs commit of $path failed: $!"; + } +} - Your CVS repository doesn't have $TMPDIR/$CVSREP/.svnrev file! +# ok, now do the checkout - This file is used to commit changes to CVS repository with correct - logs from Subversion. +log_system("$cvs -q checkout $CVSREP","cvs checkout failed"); - 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 +chdir($CVSREP) || die "can't cd to $TMPDIR/$CVSREP: $!"; -_USAGE_ - print "CVS Repository left in $TMPDIR/$CVSREP\n"; - exit 1; -} +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 ".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,".svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; + $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 @@ -131,12 +159,10 @@ 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'}; - log_system("svn export --force -q -r $rev $SVNROOT/$SVNREP $CVSREP", "svn export of revision $rev failed"); + log_system("svn export --force -q -r $rev $SVNROOT/$SVNREP $TMPDIR/$CVSREP", "svn export of revision $rev failed"); printf($fmt, $e->{'revision'}, $e->{'author'}, $e->{'date'}, $e->{'msg'}); foreach my $p (@{$e->{'paths'}->{'path'}}) { @@ -147,21 +173,27 @@ # prepare path and message my $file = $path; $path =~ s,^/$SVNREP/*,, || die "BUG: can't strip SVNREP from path"; + + if (! $path) { + print "NOTICE: skipped this operation. Probably trunk creation\n"; + next; + } + my $msg = $e->{'msg'}; $msg =~ s/"/\\"/g; # quote " if ($action =~ /M/) { print "svn2cvs: modify $path -- nop\n"; } elsif ($action =~ /A/) { - log_system("$cvs add -m \"$msg\" $CVSREP/$path", "cvs add of $path failed"); + log_system("$cvs add -m \"$msg\" $path", "cvs add of $path failed"); } elsif ($action =~ /D/) { - log_system("$cvs delete -m \"$msg\" $CVSREP/$path", "cvs delete of $path failed"); + log_system("$cvs delete -m \"$msg\" $path", "cvs delete of $path failed"); } else { print "WARNING: action $action not implemented on $path. Bug or missing feature of $0\n"; } # now commit changes - log_system("$cvs commit -m \"$msg\" $CVSREP/$path", "cvs commit of $path failed"); + log_system("$cvs commit -m \"$msg\" $path", "cvs commit of $path failed"); }