--- trunk/svn2cvs.pl 2004/03/09 20:58:34 1 +++ trunk/svn2cvs.pl 2004/03/09 22:16:19 6 @@ -18,15 +18,22 @@ my $HOME = $ENV{'HOME'} || die "can't get home directory!"; # cvsroot directory -my $CVSROOT="$HOME/x/cvsroot"; +#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"; # 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 +41,7 @@ # cvs command with root my $cvs="cvs -d $CVSROOT"; + # # sub to do logging and system calls # @@ -43,60 +51,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 - -log_system("$cvs checkout $CVSREP","cvs checkout failed"); + die "commit_svnrev needs revision" if (! defined($rev)); -# check if svnrev exists + open(SVNREV,"> $CVSREP/.svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; + print SVNREV $rev; + close(SVNREV); -if (! -e "$CVSREP/.svnrev") { - print <<_USAGE_; + my $path=".svnrev"; - Your CVS repository doesn't have $TMPDIR/$CVSREP/.svnrev file! + 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: $!"; + } +} - 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"; +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: $!"; + $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 @@ -111,7 +137,7 @@ } close(LOG); -my $xml = XMLin($log, ForceArray => [ 'path' ]); +my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]); =begin log_example @@ -125,6 +151,11 @@ my $fmt = "\n" . "-" x 79 . "\nr%5s| %8s | %s\n\n%s\n"; +if (! $xml->{'logentry'}) { + print "no newer log entries in SubVersion repostory. CVS is current\n"; + exit 0; +} + foreach my $e (@{$xml->{'logentry'}}) { die "BUG: revision from .svnrev ($rev) greater than from subversion (".$e->{'revision'}.")" if ($rev > $e->{'revision'}); $rev = $e->{'revision'};