--- trunk/svn2cvs.pl 2005/04/18 16:43:08 20 +++ trunk/svn2cvs.pl 2005/07/01 19:07:10 21 @@ -13,6 +13,7 @@ use strict; use File::Temp qw/ tempdir /; +use File::Path; use Data::Dumper; use XML::Simple; @@ -28,6 +29,9 @@ exit 1; } +# Ensure File::Temp::END can clean up: +$SIG{__DIE__} = sub { chdir("/tmp"); die @_ }; + my $TMPDIR=tempdir( "/tmp/checkoutXXXXX", CLEANUP => 1 ); chdir($TMPDIR) || die "can't cd to $TMPDIR: $!"; @@ -105,8 +109,8 @@ chdir($TMPDIR) || die "can't cd to $TMPDIR: $!"; rmdir $CVSREP || die "can't remove $CVSREP: $!"; - # and checkout it - log_system("$cvs -q checkout $CVSREP", "cvs checkout failed"); + # and get new changes it + log_system("$cvs -q update -d $CVSREP", "cvs update -d failed"); chdir($CVSREP) || die "can't cd to $TMPDIR/$CVSREP: $!"; @@ -173,7 +177,11 @@ } close(LOG); -my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]); + +my $xml; +eval { + $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]); +}; #=begin log_example @@ -202,7 +210,7 @@ if ($d !~ m,/$, && $d ne "") { $d .= "/"; } - open(E, $d."CVS/Entries") || die "can't open ${d}CVS/Entries: $!"; + open(E, $d."CVS/Entries") || return 0; while() { return(1) if (m,^/$f/,); } @@ -211,6 +219,8 @@ } } +chdir("$TMPDIR/$CVSREP") || die "can't cd to $TMPDIR/$CVSREP: $!"; + foreach my $e (@{$xml->{'logentry'}}) { die "BUG: revision from .svnrev ($rev) greater than from subversion (".$e->{'revision'}.")" if ($rev > $e->{'revision'}); $rev = $e->{'revision'}; @@ -257,13 +267,13 @@ 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"); + chdir("$TMPDIR") || die "can't cd to $TMPDIR/$CVSREP: $!"; if (-d "$CVSREP/$path") { - rmdir "$CVSREP/$path" || die "can't remove $CVSREP/$path: $!"; + rmtree "$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"); + log_system("$cvs update -d $CVSREP", "cvs update -d of imported dir $path failed"); chdir("$TMPDIR/$CVSREP") || die "can't cd back to $TMPDIR/$CVSREP: $!"; } elsif ($path =~ m,^(.+)/[^/]+$, && ! -e "$1/CVS/Root") { my $dir = $1; @@ -293,6 +303,9 @@ commit_svnrev($rev); } +# cd out of $CVSREP before File::Temp::END is called +chdir("/tmp") || die "can't cd to /tmp: $!"; + __END__ =pod @@ -408,6 +421,13 @@ Fixed path deduction (overlap between Subversion reporistory and CVS checkout). +=item r21 + +Use C instead of checkout after import. +Added fixes by Paul Egan for XMLin and fixing working +directory. + + =back =head1 AUTHOR