14 |
use Data::Dumper; |
use Data::Dumper; |
15 |
use XML::Simple; |
use XML::Simple; |
16 |
|
|
17 |
# get current user home directory |
if (@ARGV < 2) { |
18 |
my $HOME = $ENV{'HOME'} || die "can't get home directory!"; |
print "usage: $0 SVN_URL CVSROOT CVSREPOSITORY\n"; |
19 |
|
exit 1; |
20 |
|
} |
21 |
|
|
22 |
|
my ($SVNROOT,$CVSROOT, $CVSREP) = @ARGV; |
23 |
|
|
24 |
# cvsroot directory |
if ($SVNROOT !~ m,^[\w+]+:///*\w+,) { |
25 |
#my $CVSROOT="$HOME/x/cvsroot"; |
print "ERROR: invalid svn root $SVNROOT\n"; |
26 |
my $CVSROOT=':pserver:dpavlin@cvs.tigris.org:/cvs'; |
exit 1; |
27 |
# name of cvs repository to commit to |
} |
|
my $CVSREP="svn2cvs/src"; |
|
|
|
|
|
# svnroot directory |
|
|
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"; |
|
28 |
|
|
29 |
my $TMPDIR=tempdir( "/tmp/checkoutXXXXX", CLEANUP => 1 ); |
my $TMPDIR=tempdir( "/tmp/checkoutXXXXX", CLEANUP => 1 ); |
30 |
|
|
33 |
# cvs command with root |
# cvs command with root |
34 |
my $cvs="cvs -d $CVSROOT"; |
my $cvs="cvs -d $CVSROOT"; |
35 |
|
|
|
|
|
36 |
# |
# |
37 |
# sub to do logging and system calls |
# sub to do logging and system calls |
38 |
# |
# |
39 |
sub log_system($$) { |
sub log_system($$) { |
40 |
my ($cmd,$errmsg) = @_; |
my ($cmd,$errmsg) = @_; |
41 |
print STDERR "## $cmd\n"; |
print STDERR "## $cmd\n"; |
42 |
system $cmd || die "$errmsg: $!"; |
system($cmd) == 0 || die "$errmsg: $!"; |
43 |
} |
} |
44 |
|
|
45 |
# |
# |
51 |
|
|
52 |
die "commit_svnrev needs revision" if (! defined($rev)); |
die "commit_svnrev needs revision" if (! defined($rev)); |
53 |
|
|
54 |
open(SVNREV,"> $CVSREP/.svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; |
open(SVNREV,"> .svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; |
55 |
print SVNREV $rev; |
print SVNREV $rev; |
56 |
close(SVNREV); |
close(SVNREV); |
57 |
|
|
58 |
my $path=".svnrev"; |
my $path=".svnrev"; |
59 |
|
|
60 |
if ($add_new) { |
if ($add_new) { |
61 |
system "$cvs add $CVSREP/$path" || die "cvs add of $path failed: $!"; |
system "$cvs add $path" || die "cvs add of $path failed: $!"; |
62 |
} else { |
} else { |
63 |
my $msg="subversion revision $rev commited to CVS"; |
my $msg="subversion revision $rev commited to CVS"; |
64 |
print "$msg\n"; |
print "$msg\n"; |
65 |
system "$cvs commit -m \"$msg\" $CVSREP/$path" || die "cvs commit of $path failed: $!"; |
system "$cvs commit -m \"$msg\" $path" || die "cvs commit of $path failed: $!"; |
66 |
} |
} |
67 |
} |
} |
68 |
|
|
|
|
|
69 |
# ok, now do the checkout |
# ok, now do the checkout |
70 |
|
|
71 |
log_system("$cvs -q checkout $CVSREP","cvs checkout failed"); |
log_system("$cvs -q checkout $CVSREP", "cvs checkout failed"); |
72 |
|
|
73 |
|
chdir($CVSREP) || die "can't cd to $TMPDIR/$CVSREP: $!"; |
74 |
|
|
75 |
|
|
76 |
my $rev; |
my $rev; |
77 |
|
|
78 |
# check if svnrev exists |
# check if svnrev exists |
79 |
if (! -e "$CVSREP/.svnrev") { |
if (! -e ".svnrev") { |
80 |
print <<_USAGE_; |
print <<_USAGE_; |
81 |
|
|
82 |
Your CVS repository doesn't have .svnrev file! |
Your CVS repository doesn't have .svnrev file! |
106 |
commit_svnrev($rev,1); # create new |
commit_svnrev($rev,1); # create new |
107 |
} |
} |
108 |
} else { |
} else { |
109 |
open(SVNREV,"$CVSREP/.svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; |
open(SVNREV,".svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; |
110 |
my $rev = <SVNREV>; |
$rev = <SVNREV>; |
111 |
chomp($rev); |
chomp($rev); |
112 |
close(SVNREV); |
close(SVNREV); |
113 |
} |
} |
123 |
# case much about accuracy and completnes of logs there, this might |
# case much about accuracy and completnes of logs there, this might |
124 |
# be good. YMMV |
# be good. YMMV |
125 |
# |
# |
126 |
open(LOG, "svn log -r $rev:HEAD -v --xml $SVNROOT/$SVNREP |") || die "svn log for repository $SVNROOT/$SVNREP failed: $!"; |
open(LOG, "svn log -r $rev:HEAD -v --xml $SVNROOT |") || die "svn log for repository $SVNROOT failed: $!"; |
127 |
my $log; |
my $log; |
128 |
while(<LOG>) { |
while(<LOG>) { |
129 |
$log .= $_; |
$log .= $_; |
152 |
foreach my $e (@{$xml->{'logentry'}}) { |
foreach my $e (@{$xml->{'logentry'}}) { |
153 |
die "BUG: revision from .svnrev ($rev) greater than from subversion (".$e->{'revision'}.")" if ($rev > $e->{'revision'}); |
die "BUG: revision from .svnrev ($rev) greater than from subversion (".$e->{'revision'}.")" if ($rev > $e->{'revision'}); |
154 |
$rev = $e->{'revision'}; |
$rev = $e->{'revision'}; |
155 |
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 $TMPDIR/$CVSREP", "svn export of revision $rev failed"); |
156 |
|
|
157 |
|
# deduce name of svn directory |
158 |
|
my $SVNREP = ""; |
159 |
|
my $tmpsvn = $SVNROOT || die "BUG: SVNROOT empty!"; |
160 |
|
my $tmppath = $e->{'paths'}->{'path'}->[0]->{'content'} || die "BUG: tmppath empty!"; |
161 |
|
do { |
162 |
|
print "## tmppath: $tmppath tmpsvn: $tmpsvn SVNREP: $SVNREP\n"; |
163 |
|
if ($tmpsvn =~ s,(/\w+/*)$,,) { |
164 |
|
$SVNREP .= $1; |
165 |
|
} else { |
166 |
|
die "ERROR: can't deduce svn dir from $SVNROOT.\nUsing root of snv repository for current version instead of /trunk/ is not supported.\n"; |
167 |
|
} |
168 |
|
} until ($tmppath =~ m/^$SVNREP/); |
169 |
|
|
170 |
|
print "NOTICE: using $SVNREP as directory for svn\n"; |
171 |
|
|
172 |
printf($fmt, $e->{'revision'}, $e->{'author'}, $e->{'date'}, $e->{'msg'}); |
printf($fmt, $e->{'revision'}, $e->{'author'}, $e->{'date'}, $e->{'msg'}); |
173 |
foreach my $p (@{$e->{'paths'}->{'path'}}) { |
foreach my $p (@{$e->{'paths'}->{'path'}}) { |
177 |
|
|
178 |
# prepare path and message |
# prepare path and message |
179 |
my $file = $path; |
my $file = $path; |
180 |
$path =~ s,^/$SVNREP/*,, || die "BUG: can't strip SVNREP from path"; |
$path =~ s,^$SVNREP/*,, || die "BUG: can't strip SVNREP from path"; |
181 |
|
|
182 |
|
if (! $path) { |
183 |
|
print "NOTICE: skipped this operation. Probably trunk creation\n"; |
184 |
|
next; |
185 |
|
} |
186 |
|
|
187 |
my $msg = $e->{'msg'}; |
my $msg = $e->{'msg'}; |
188 |
$msg =~ s/"/\\"/g; # quote " |
$msg =~ s/"/\\"/g; # quote " |
189 |
|
|
190 |
if ($action =~ /M/) { |
if ($action =~ /M/) { |
191 |
print "svn2cvs: modify $path -- nop\n"; |
print "svn2cvs: modify $path -- nop\n"; |
192 |
} elsif ($action =~ /A/) { |
} elsif ($action =~ /A/) { |
193 |
log_system("$cvs add -m \"$msg\" $CVSREP/$path", "cvs add of $path failed"); |
if (-d $path) { |
194 |
|
chdir($path) || die "can't cd into dir $path for import: $!"; |
195 |
|
log_system("$cvs import -d -m \"$msg\" $CVSREP/$path svn r$rev", "cvs import of $path failed"); |
196 |
|
chdir("$TMPDIR") || die "can't cd to $TMPDIR/$CVSREP: $!"; |
197 |
|
log_system("$cvs checkout $CVSREP/$path", "cvs checkout of imported dir $path failed"); |
198 |
|
chdir("$TMPDIR/$CVSREP") || die "can't cd back to $TMPDIR/$CVSREP: $!"; |
199 |
|
} else { |
200 |
|
log_system("$cvs add -m \"$msg\" $path", "cvs add of $path failed"); |
201 |
|
} |
202 |
} elsif ($action =~ /D/) { |
} elsif ($action =~ /D/) { |
203 |
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"); |
204 |
} else { |
} else { |
205 |
print "WARNING: action $action not implemented on $path. Bug or missing feature of $0\n"; |
print "WARNING: action $action not implemented on $path. Bug or missing feature of $0\n"; |
206 |
} |
} |
207 |
|
|
208 |
# now commit changes |
# now commit changes |
209 |
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"); |
210 |
|
|
211 |
} |
} |
212 |
|
|
213 |
commit_svnrev($rev); |
commit_svnrev($rev); |
214 |
} |
} |
|
|
|
|
__END__ |
|
|
|
|
|
svn export --force "$SVNROOT/$SVNREP" "$CVSREP" |
|
|
|
|
|
cd dotfiles |
|
|
|
|
|
for file in $(find -type f -not -path \*CVS\*); do |
|
|
FILE=$(basename $file) |
|
|
DIR=$(dirname $file) |
|
|
if ! grep -q "^/$FILE/" $DIR/CVS/Entries ; then |
|
|
cvs add $file |
|
|
fi |
|
|
done |
|
|
|
|
|
#cvs commit -m "Automatic commit from SVN" |
|
|
|
|
|
#rm -rf $TMPDIR |
|
|
|
|
|
echo "cvs left in $TMPDIR" |
|