--- trunk/svn2cvs.pl 2004/03/14 21:49:36 14 +++ trunk/svn2cvs.pl 2005/03/06 12:09:42 18 @@ -68,18 +68,58 @@ } } +# current revision in CVS +my $rev; + # ok, now do the checkout +eval { + log_system("$cvs -q checkout $CVSREP", "cvs checkout failed"); +}; -log_system("$cvs -q checkout $CVSREP", "cvs checkout failed"); +if ($@) { + print <<_NEW_REP_; -chdir($CVSREP) || die "can't cd to $TMPDIR/$CVSREP: $!"; +There is no CVS repository '$CVSREP' in your CVS. I will assume that +this is import of new module in your CVS and start from revision 0. +Press enter to continue importing new CVS repository or CTRL+C to abort. -my $rev; +_NEW_REP_ + + print "start import of new module [yes]: "; + my $in = ; + mkdir($CVSREP) || die "can't create $CVSREP: $!"; + + chdir($CVSREP) || die "can't cd to $TMPDIR/$CVSREP: $!"; + + open(SVNREV,"> .svnrev") || die "can't open $CVSREP/.svnrev: $!"; + print SVNREV "0"; + close(SVNREV); + + $rev = 0; + + # create new module + log_system("$cvs import -m 'new CVS module' $CVSREP svn2cvs r0", "can't import new module into $CVSREP"); + + unlink ".svnrev" || die "can't remove .svnrev: $!"; + chdir($TMPDIR) || die "can't cd to $TMPDIR: $!"; + rmdir $CVSREP || die "can't remove $CVSREP: $!"; -# check if svnrev exists -if (! -e ".svnrev") { - print <<_USAGE_; + # and checkout it + log_system("$cvs -q checkout $CVSREP", "cvs checkout failed"); + + chdir($CVSREP) || die "can't cd to $TMPDIR/$CVSREP: $!"; + +} else { + + # import into existing module directory in CVS + + chdir($CVSREP) || die "can't cd to $TMPDIR/$CVSREP: $!"; + + + # check if svnrev exists + if (! -e ".svnrev") { + print <<_USAGE_; Your CVS repository doesn't have .svnrev file! @@ -97,25 +137,26 @@ _USAGE_ - print "svn revision corresponding to CVS [abort]: "; - my $in = ; - chomp($in); - if ($in !~ /^\d+$/) { - print "Aborting: revision not a number\n"; - exit 1; + 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 { - $rev = $in; - commit_svnrev($rev,1); # create new + open(SVNREV,".svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; + $rev = ; + chomp($rev); + close(SVNREV); } -} else { - open(SVNREV,".svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; - $rev = ; - chomp($rev); - close(SVNREV); -} -print "Starting after revision $rev\n"; -$rev++; + print "Starting after revision $rev\n"; + $rev++; +} # @@ -158,7 +199,7 @@ die "can't split '$path' to dir and file!"; } else { my ($d,$f) = ($1,$2); - if ($d !~ m,/$,) { + if ($d !~ m,/$, && $d ne "") { $d .= "/"; } open(E, $d."CVS/Entries") || die "can't open ${d}CVS/Entries: $!"; @@ -180,17 +221,19 @@ my $tmpsvn = $SVNROOT || die "BUG: SVNROOT empty!"; my $tmppath = $e->{'paths'}->{'path'}->[0]->{'content'} || die "BUG: tmppath empty!"; do { -print "## tmppath: $tmppath tmpsvn: $tmpsvn SVNREP: $SVNREP\n"; - if ($tmpsvn =~ s,(/\w+/*)$,,) { + if ($tmpsvn =~ s,(/\w+)/*$,,) { $SVNREP .= $1; } else { - die "ERROR: can't deduce svn dir from $SVNROOT.\nUsing root of snv repository for current version instead of /trunk/ is not supported.\n"; + print "NOTICE: can't deduce svn dir from $SVNROOT - skipping\n"; + next; } } until ($tmppath =~ m/^$SVNREP/); print "NOTICE: using $SVNREP as directory for svn\n"; printf($fmt, $e->{'revision'}, $e->{'author'}, $e->{'date'}, $e->{'msg'}); + my @commit; + foreach my $p (@{$e->{'paths'}->{'path'}}) { my ($action,$path) = ($p->{'action'},$p->{'content'}); @@ -198,7 +241,7 @@ # prepare path and message my $file = $path; - $path =~ s,^$SVNREP/*,, || die "BUG: can't strip SVNREP from path"; + $path =~ s,^$SVNREP/*,, || die "BUG: can't strip SVNREP '$SVNREP' from path"; if (! $path) { print "NOTICE: skipped this operation. Probably trunk creation\n"; @@ -214,6 +257,11 @@ if (-d $path) { chdir($path) || die "can't cd into dir $path for import: $!"; log_system("$cvs import -d -m '$msg' $CVSREP/$path svn r$rev", "cvs import of $path failed"); + if (-d "$CVSREP/$path") { + rmdir "$CVSREP/$path" || die "can't remove $CVSREP/$path: $!"; + } else { + unlink "$CVSREP/$path" || die "can't remove $CVSREP/$path: $!"; + } chdir("$TMPDIR") || die "can't cd to $TMPDIR/$CVSREP: $!"; log_system("$cvs checkout $CVSREP/$path", "cvs checkout of imported dir $path failed"); chdir("$TMPDIR/$CVSREP") || die "can't cd back to $TMPDIR/$CVSREP: $!"; @@ -231,11 +279,17 @@ print "WARNING: action $action not implemented on $path. Bug or missing feature of $0\n"; } - # now commit changes - log_system("$cvs commit -m '$msg' $path", "cvs commit of $path failed"); + # save commits for later + push @commit, $path; } + my $msg = $e->{'msg'}; + $msg =~ s/'/'\\''/g; # quote " + + # now commit changes + log_system("$cvs commit -m '$msg' ".join(" ",@commit), "cvs commit of ".join(",",@commit)." failed"); + commit_svnrev($rev); } @@ -258,7 +312,8 @@ =head1 DESCRIPTION -This script will allow you to commit changes made to Subversion repository also to (read-only) CVS repository manually or from Subversion's C hook. +This script will allows you to commit changes made to Subversion repository to +(read-only) CVS repository manually or from Subversion's C hook. It's using F<.svnrev> file (which will be created on first run) in B to store last Subversion revision which was @@ -310,6 +365,12 @@ "Cheap" copy operations in Subversion are not at all cheap in CVS. They will create multiple copies of files in CVS repository! +This script assume that you want to sync your C (or any other +directory for that matter) directory with CVS, not root of your subversion. +This might be considered bug, but since common practise is to have +directories C and C in svn and source code in them, it's +not serious limitation. + =head1 RELATED PROJECTS B L version control system that is a @@ -319,6 +380,33 @@ Subversion repository. It is designed for one-time conversions, not for repeated synchronizations between CVS and Subversion. +=head1 CHANGES + +Versions of this utility are actually Subversion repository revisions, +so they might not be in sequence. + +=over 3 + +=item r10 + +First release available to public + +=item r15 + +Addition of comprehensive documentation, fixes for quoting in commit +messages, and support for skipping changes which are not under current +Subversion checkout root (e.g. branches). + +=item r16 + +Support for importing your svn into empty CVS repository (it will first +create module and than dump all revisions). +Group commit operations to save round-trips to CVS server. +Documentation improvements and other small fixes. + + +=back + =head1 AUTHOR Dobrica Pavlinusic