13 |
|
|
14 |
use strict; |
use strict; |
15 |
use File::Temp qw/ tempdir /; |
use File::Temp qw/ tempdir /; |
16 |
|
use File::Path; |
17 |
use Data::Dumper; |
use Data::Dumper; |
18 |
use XML::Simple; |
use XML::Simple; |
19 |
|
|
29 |
exit 1; |
exit 1; |
30 |
} |
} |
31 |
|
|
32 |
|
# Ensure File::Temp::END can clean up: |
33 |
|
$SIG{__DIE__} = sub { chdir("/tmp"); die @_ }; |
34 |
|
|
35 |
my $TMPDIR=tempdir( "/tmp/checkoutXXXXX", CLEANUP => 1 ); |
my $TMPDIR=tempdir( "/tmp/checkoutXXXXX", CLEANUP => 1 ); |
36 |
|
|
37 |
chdir($TMPDIR) || die "can't cd to $TMPDIR: $!"; |
sub cd_tmp { |
38 |
|
chdir($TMPDIR) || die "can't cd to $TMPDIR: $!"; |
39 |
|
} |
40 |
|
|
41 |
|
sub cd_rep { |
42 |
|
chdir("$TMPDIR/$CVSREP") || die "can't cd to $TMPDIR/$CVSREP: $!"; |
43 |
|
} |
44 |
|
|
45 |
|
print "## using TMPDIR $TMPDIR\n"; |
46 |
|
|
47 |
# cvs command with root |
# cvs command with root |
48 |
my $cvs="cvs -d $CVSROOT"; |
my $cvs="cvs -d $CVSROOT"; |
49 |
|
|
50 |
|
# current revision in CVS |
51 |
|
my $rev; |
52 |
|
|
53 |
# |
# |
54 |
# sub to do logging and system calls |
# sub to do logging and system calls |
55 |
# |
# |
83 |
} |
} |
84 |
} |
} |
85 |
|
|
86 |
|
sub add_dir($$) { |
87 |
|
my ($path,$msg) = @_; |
88 |
|
print "# add_dir($path)\n"; |
89 |
|
die "add_dir($path) is not directory" unless (-d $path); |
90 |
|
|
91 |
|
my $curr_dir; |
92 |
|
|
93 |
|
foreach my $d (split(m#/#, $path)) { |
94 |
|
$curr_dir .= ( $curr_dir ? '/' : '') . $d; |
95 |
|
|
96 |
|
next if in_entries($curr_dir); |
97 |
|
next if (-e "$curr_dir/CVS"); |
98 |
|
|
99 |
|
log_system("$cvs add $curr_dir", "cvs add of $curr_dir failed"); |
100 |
|
} |
101 |
|
} |
102 |
|
|
103 |
# ok, now do the checkout |
# ok, now do the checkout |
104 |
|
eval { |
105 |
|
cd_tmp; |
106 |
|
log_system("$cvs -q checkout $CVSREP", "cvs checkout failed"); |
107 |
|
}; |
108 |
|
|
109 |
log_system("$cvs -q checkout $CVSREP", "cvs checkout failed"); |
if ($@) { |
110 |
|
print <<_NEW_REP_; |
111 |
|
|
112 |
chdir($CVSREP) || die "can't cd to $TMPDIR/$CVSREP: $!"; |
There is no CVS repository '$CVSREP' in your CVS. I will assume that |
113 |
|
this is import of new module in your CVS and start from revision 0. |
114 |
|
|
115 |
|
Press enter to continue importing new CVS repository or CTRL+C to abort. |
116 |
|
|
117 |
my $rev; |
_NEW_REP_ |
118 |
|
|
119 |
|
print "start import of new module [yes]: "; |
120 |
|
my $in = <STDIN>; |
121 |
|
cd_tmp; |
122 |
|
mkdir($CVSREP) || die "can't create $CVSREP: $!"; |
123 |
|
cd_rep; |
124 |
|
|
125 |
|
open(SVNREV,"> .svnrev") || die "can't open $CVSREP/.svnrev: $!"; |
126 |
|
print SVNREV "0"; |
127 |
|
close(SVNREV); |
128 |
|
|
129 |
|
$rev = 0; |
130 |
|
|
131 |
|
# create new module |
132 |
|
cd_rep; |
133 |
|
log_system("$cvs import -d -m 'new CVS module' $CVSREP svn r$rev", "import of new repository"); |
134 |
|
cd_tmp; |
135 |
|
rmtree($CVSREP) || die "can't remove $CVSREP"; |
136 |
|
log_system("$cvs -q checkout $CVSREP", "cvs checkout failed"); |
137 |
|
cd_rep; |
138 |
|
|
139 |
# check if svnrev exists |
} else { |
140 |
if (! -e ".svnrev") { |
# import into existing module directory in CVS |
141 |
print <<_USAGE_; |
|
142 |
|
cd_rep; |
143 |
|
# check if svnrev exists |
144 |
|
if (! -e ".svnrev") { |
145 |
|
print <<_USAGE_; |
146 |
|
|
147 |
Your CVS repository doesn't have .svnrev file! |
Your CVS repository doesn't have .svnrev file! |
148 |
|
|
160 |
|
|
161 |
_USAGE_ |
_USAGE_ |
162 |
|
|
163 |
print "svn revision corresponding to CVS [abort]: "; |
print "svn revision corresponding to CVS [abort]: "; |
164 |
my $in = <STDIN>; |
my $in = <STDIN>; |
165 |
chomp($in); |
chomp($in); |
166 |
if ($in !~ /^\d+$/) { |
if ($in !~ /^\d+$/) { |
167 |
print "Aborting: revision not a number\n"; |
print "Aborting: revision not a number\n"; |
168 |
exit 1; |
exit 1; |
169 |
|
} else { |
170 |
|
$rev = $in; |
171 |
|
commit_svnrev($rev,1); # create new |
172 |
|
} |
173 |
} else { |
} else { |
174 |
$rev = $in; |
open(SVNREV,".svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; |
175 |
commit_svnrev($rev,1); # create new |
$rev = <SVNREV>; |
176 |
|
chomp($rev); |
177 |
|
close(SVNREV); |
178 |
} |
} |
|
} else { |
|
|
open(SVNREV,".svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; |
|
|
$rev = <SVNREV>; |
|
|
chomp($rev); |
|
|
close(SVNREV); |
|
|
} |
|
179 |
|
|
180 |
print "Starting after revision $rev\n"; |
print "Starting after revision $rev\n"; |
181 |
$rev++; |
$rev++; |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
# |
# |
196 |
} |
} |
197 |
close(LOG); |
close(LOG); |
198 |
|
|
199 |
my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]); |
|
200 |
|
my $xml; |
201 |
|
eval { |
202 |
|
$xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]); |
203 |
|
}; |
204 |
|
|
205 |
|
|
206 |
#=begin log_example |
#=begin log_example |
229 |
if ($d !~ m,/$, && $d ne "") { |
if ($d !~ m,/$, && $d ne "") { |
230 |
$d .= "/"; |
$d .= "/"; |
231 |
} |
} |
232 |
open(E, $d."CVS/Entries") || die "can't open ${d}CVS/Entries: $!"; |
open(E, $d."CVS/Entries") || return 0; |
233 |
while(<E>) { |
while(<E>) { |
234 |
return(1) if (m,^/$f/,); |
return(1) if (m,^/$f/,); |
235 |
} |
} |
238 |
} |
} |
239 |
} |
} |
240 |
|
|
241 |
|
cd_tmp; |
242 |
|
cd_rep; |
243 |
|
|
244 |
foreach my $e (@{$xml->{'logentry'}}) { |
foreach my $e (@{$xml->{'logentry'}}) { |
245 |
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'}); |
246 |
$rev = $e->{'revision'}; |
$rev = $e->{'revision'}; |
251 |
my $tmpsvn = $SVNROOT || die "BUG: SVNROOT empty!"; |
my $tmpsvn = $SVNROOT || die "BUG: SVNROOT empty!"; |
252 |
my $tmppath = $e->{'paths'}->{'path'}->[0]->{'content'} || die "BUG: tmppath empty!"; |
my $tmppath = $e->{'paths'}->{'path'}->[0]->{'content'} || die "BUG: tmppath empty!"; |
253 |
do { |
do { |
254 |
if ($tmpsvn =~ s,(/\w+/*)$,,) { |
if ($tmpsvn =~ s#(/[^/]+)/*$##) { |
255 |
$SVNREP .= $1; |
$SVNREP = $1 . $SVNREP; |
256 |
} else { |
} else { |
257 |
print "NOTICE: can't deduce svn dir from $SVNROOT - skipping\n"; |
print "NOTICE: can't deduce svn dir from $SVNROOT - skipping\n"; |
258 |
next; |
next; |
262 |
print "NOTICE: using $SVNREP as directory for svn\n"; |
print "NOTICE: using $SVNREP as directory for svn\n"; |
263 |
|
|
264 |
printf($fmt, $e->{'revision'}, $e->{'author'}, $e->{'date'}, $e->{'msg'}); |
printf($fmt, $e->{'revision'}, $e->{'author'}, $e->{'date'}, $e->{'msg'}); |
265 |
|
my @commit; |
266 |
|
|
267 |
foreach my $p (@{$e->{'paths'}->{'path'}}) { |
foreach my $p (@{$e->{'paths'}->{'path'}}) { |
268 |
my ($action,$path) = ($p->{'action'},$p->{'content'}); |
my ($action,$path) = ($p->{'action'},$p->{'content'}); |
269 |
|
|
271 |
|
|
272 |
# prepare path and message |
# prepare path and message |
273 |
my $file = $path; |
my $file = $path; |
274 |
$path =~ s,^$SVNREP/*,, || die "BUG: can't strip SVNREP from path"; |
$path =~ s#^\Q$SVNREP\E/*## || die "BUG: can't strip SVNREP '$SVNREP' from path"; |
275 |
|
|
276 |
if (! $path) { |
if (! $path) { |
277 |
print "NOTICE: skipped this operation. Probably trunk creation\n"; |
print "NOTICE: skipped this operation. Probably trunk creation\n"; |
285 |
print "svn2cvs: modify $path -- nop\n"; |
print "svn2cvs: modify $path -- nop\n"; |
286 |
} elsif ($action =~ /A/) { |
} elsif ($action =~ /A/) { |
287 |
if (-d $path) { |
if (-d $path) { |
288 |
chdir($path) || die "can't cd into dir $path for import: $!"; |
add_dir($path, $msg); |
|
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: $!"; |
|
|
log_system("$cvs checkout $CVSREP/$path", "cvs checkout of imported dir $path failed"); |
|
|
chdir("$TMPDIR/$CVSREP") || die "can't cd back to $TMPDIR/$CVSREP: $!"; |
|
289 |
} elsif ($path =~ m,^(.+)/[^/]+$, && ! -e "$1/CVS/Root") { |
} elsif ($path =~ m,^(.+)/[^/]+$, && ! -e "$1/CVS/Root") { |
290 |
my $dir = $1; |
my $dir = $1; |
291 |
in_entries($dir) || log_system("$cvs add $dir", "cvs add of dir $dir failed"); |
in_entries($dir) || add_dir($dir, $msg); |
292 |
in_entries($path) || log_system("$cvs add $path", "cvs add of $path failed"); |
in_entries($path) || log_system("$cvs add $path", "cvs add of $path failed"); |
293 |
} else { |
} else { |
294 |
in_entries($path) || log_system("$cvs add $path", "cvs add of $path failed"); |
in_entries($path) || log_system("$cvs add $path", "cvs add of $path failed"); |
295 |
} |
} |
296 |
} elsif ($action =~ /D/) { |
} elsif ($action =~ /D/) { |
297 |
unlink $path || die "can't delete $path: $!"; |
if (-e $path) { |
298 |
log_system("$cvs delete $path", "cvs delete of $path failed"); |
unlink $path || die "can't delete $path: $!"; |
299 |
|
log_system("$cvs delete $path", "cvs delete of $path failed"); |
300 |
|
} else { |
301 |
|
print "WARNING: $path is not present, skipping...\n"; |
302 |
|
undef $path; |
303 |
|
} |
304 |
} else { |
} else { |
305 |
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"; |
306 |
} |
} |
307 |
|
|
308 |
# now commit changes |
# save commits for later |
309 |
log_system("$cvs commit -m '$msg' $path", "cvs commit of $path failed"); |
push @commit, $path if ($path); |
310 |
|
|
311 |
} |
} |
312 |
|
|
313 |
|
my $msg = $e->{'msg'}; |
314 |
|
$msg =~ s/'/'\\''/g; # quote " |
315 |
|
|
316 |
|
# now commit changes |
317 |
|
log_system("$cvs commit -m '$msg' ".join(" ",@commit), "cvs commit of ".join(",",@commit)." failed"); |
318 |
|
|
319 |
commit_svnrev($rev); |
commit_svnrev($rev); |
320 |
} |
} |
321 |
|
|
322 |
|
# cd out of $CVSREP before File::Temp::END is called |
323 |
|
chdir("/tmp") || die "can't cd to /tmp: $!"; |
324 |
|
|
325 |
__END__ |
__END__ |
326 |
|
|
327 |
=pod |
=pod |
341 |
|
|
342 |
=head1 DESCRIPTION |
=head1 DESCRIPTION |
343 |
|
|
344 |
This script will allow you to commit changes made to Subversion repository also to (read-only) CVS repository manually or from Subversion's C<post-commit> hook. |
This script will allows you to commit changes made to Subversion repository to |
345 |
|
(read-only) CVS repository manually or from Subversion's C<post-commit> hook. |
346 |
|
|
347 |
It's using F<.svnrev> file (which will be created on first run) in |
It's using F<.svnrev> file (which will be created on first run) in |
348 |
B<CVSROOT/CVSREPOSITORY> to store last Subversion revision which was |
B<CVSROOT/CVSREPOSITORY> to store last Subversion revision which was |
394 |
"Cheap" copy operations in Subversion are not at all cheap in CVS. They will |
"Cheap" copy operations in Subversion are not at all cheap in CVS. They will |
395 |
create multiple copies of files in CVS repository! |
create multiple copies of files in CVS repository! |
396 |
|
|
397 |
|
This script assume that you want to sync your C<trunk> (or any other |
398 |
|
directory for that matter) directory with CVS, not root of your subversion. |
399 |
|
This might be considered bug, but since common practise is to have |
400 |
|
directories C<trunk> and C<branches> in svn and source code in them, it's |
401 |
|
not serious limitation. |
402 |
|
|
403 |
=head1 RELATED PROJECTS |
=head1 RELATED PROJECTS |
404 |
|
|
405 |
B<Subversion> L<http://subversion.tigris.org/> version control system that is a |
B<Subversion> L<http://subversion.tigris.org/> version control system that is a |
426 |
messages, and support for skipping changes which are not under current |
messages, and support for skipping changes which are not under current |
427 |
Subversion checkout root (e.g. branches). |
Subversion checkout root (e.g. branches). |
428 |
|
|
429 |
|
=item r18 |
430 |
|
|
431 |
|
Support for importing your svn into empty CVS repository (it will first |
432 |
|
create module and than dump all revisions). |
433 |
|
Group commit operations to save round-trips to CVS server. |
434 |
|
Documentation improvements and other small fixes. |
435 |
|
|
436 |
|
=item r20 |
437 |
|
|
438 |
|
Fixed path deduction (overlap between Subversion reporistory and CVS checkout). |
439 |
|
|
440 |
|
=item r21 |
441 |
|
|
442 |
|
Use C<update -d> instead of checkout after import. |
443 |
|
Added fixes by Paul Egan <paulegan@mail.com> for XMLin and fixing working |
444 |
|
directory. |
445 |
|
|
446 |
|
=item r22 |
447 |
|
|
448 |
|
Rewritten import from revision 0 to empty repository, better importing |
449 |
|
of deep directory structures, initial support for recovery from partial |
450 |
|
commit. |
451 |
|
|
452 |
=back |
=back |
453 |
|
|
454 |
=head1 AUTHOR |
=head1 AUTHOR |