68 |
} |
} |
69 |
} |
} |
70 |
|
|
71 |
|
# current revision in CVS |
72 |
|
my $rev; |
73 |
|
|
74 |
# ok, now do the checkout |
# ok, now do the checkout |
75 |
|
eval { |
76 |
|
log_system("$cvs -q checkout $CVSREP", "cvs checkout failed"); |
77 |
|
}; |
78 |
|
|
79 |
log_system("$cvs -q checkout $CVSREP", "cvs checkout failed"); |
if ($@) { |
80 |
|
print <<_NEW_REP_; |
81 |
|
|
82 |
chdir($CVSREP) || die "can't cd to $TMPDIR/$CVSREP: $!"; |
There is no CVS repository '$CVSREP' in your CVS. I will assume that |
83 |
|
this is import of new module in your CVS and start from revision 0. |
84 |
|
|
85 |
|
Press enter to continue importing new CVS repository or CTRL+C to abort. |
86 |
|
|
87 |
my $rev; |
_NEW_REP_ |
88 |
|
|
89 |
|
print "start import of new module [yes]: "; |
90 |
|
my $in = <STDIN>; |
91 |
|
mkdir($CVSREP) || die "can't create $CVSREP: $!"; |
92 |
|
|
93 |
|
chdir($CVSREP) || die "can't cd to $TMPDIR/$CVSREP: $!"; |
94 |
|
|
95 |
|
open(SVNREV,"> .svnrev") || die "can't open $CVSREP/.svnrev: $!"; |
96 |
|
print SVNREV "0"; |
97 |
|
close(SVNREV); |
98 |
|
|
99 |
|
$rev = 0; |
100 |
|
|
101 |
|
# create new module |
102 |
|
log_system("$cvs import -m 'new CVS module' $CVSREP svn2cvs r0", "can't import new module into $CVSREP"); |
103 |
|
|
104 |
|
unlink ".svnrev" || die "can't remove .svnrev: $!"; |
105 |
|
chdir($TMPDIR) || die "can't cd to $TMPDIR: $!"; |
106 |
|
rmdir $CVSREP || die "can't remove $CVSREP: $!"; |
107 |
|
|
108 |
# check if svnrev exists |
# and checkout it |
109 |
if (! -e ".svnrev") { |
log_system("$cvs -q checkout $CVSREP", "cvs checkout failed"); |
110 |
print <<_USAGE_; |
|
111 |
|
chdir($CVSREP) || die "can't cd to $TMPDIR/$CVSREP: $!"; |
112 |
|
|
113 |
|
} else { |
114 |
|
|
115 |
|
# import into existing module directory in CVS |
116 |
|
|
117 |
|
chdir($CVSREP) || die "can't cd to $TMPDIR/$CVSREP: $!"; |
118 |
|
|
119 |
|
|
120 |
|
# check if svnrev exists |
121 |
|
if (! -e ".svnrev") { |
122 |
|
print <<_USAGE_; |
123 |
|
|
124 |
Your CVS repository doesn't have .svnrev file! |
Your CVS repository doesn't have .svnrev file! |
125 |
|
|
137 |
|
|
138 |
_USAGE_ |
_USAGE_ |
139 |
|
|
140 |
print "svn revision corresponding to CVS [abort]: "; |
print "svn revision corresponding to CVS [abort]: "; |
141 |
my $in = <STDIN>; |
my $in = <STDIN>; |
142 |
chomp($in); |
chomp($in); |
143 |
if ($in !~ /^\d+$/) { |
if ($in !~ /^\d+$/) { |
144 |
print "Aborting: revision not a number\n"; |
print "Aborting: revision not a number\n"; |
145 |
exit 1; |
exit 1; |
146 |
|
} else { |
147 |
|
$rev = $in; |
148 |
|
commit_svnrev($rev,1); # create new |
149 |
|
} |
150 |
} else { |
} else { |
151 |
$rev = $in; |
open(SVNREV,".svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; |
152 |
commit_svnrev($rev,1); # create new |
$rev = <SVNREV>; |
153 |
|
chomp($rev); |
154 |
|
close(SVNREV); |
155 |
} |
} |
|
} else { |
|
|
open(SVNREV,".svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; |
|
|
$rev = <SVNREV>; |
|
|
chomp($rev); |
|
|
close(SVNREV); |
|
|
} |
|
156 |
|
|
157 |
print "Starting after revision $rev\n"; |
print "Starting after revision $rev\n"; |
158 |
$rev++; |
$rev++; |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
# |
# |
199 |
die "can't split '$path' to dir and file!"; |
die "can't split '$path' to dir and file!"; |
200 |
} else { |
} else { |
201 |
my ($d,$f) = ($1,$2); |
my ($d,$f) = ($1,$2); |
202 |
if ($d !~ m,/$,) { |
if ($d !~ m,/$, && $d ne "") { |
203 |
$d .= "/"; |
$d .= "/"; |
204 |
} |
} |
205 |
open(E, $d."CVS/Entries") || die "can't open ${d}CVS/Entries: $!"; |
open(E, $d."CVS/Entries") || die "can't open ${d}CVS/Entries: $!"; |
221 |
my $tmpsvn = $SVNROOT || die "BUG: SVNROOT empty!"; |
my $tmpsvn = $SVNROOT || die "BUG: SVNROOT empty!"; |
222 |
my $tmppath = $e->{'paths'}->{'path'}->[0]->{'content'} || die "BUG: tmppath empty!"; |
my $tmppath = $e->{'paths'}->{'path'}->[0]->{'content'} || die "BUG: tmppath empty!"; |
223 |
do { |
do { |
224 |
print "## tmppath: $tmppath tmpsvn: $tmpsvn SVNREP: $SVNREP\n"; |
if ($tmpsvn =~ s,(/\w+)/*$,,) { |
|
if ($tmpsvn =~ s,(/\w+/*)$,,) { |
|
225 |
$SVNREP .= $1; |
$SVNREP .= $1; |
226 |
} else { |
} else { |
227 |
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"; |
228 |
|
next; |
229 |
} |
} |
230 |
} until ($tmppath =~ m/^$SVNREP/); |
} until ($tmppath =~ m/^$SVNREP/); |
231 |
|
|
232 |
print "NOTICE: using $SVNREP as directory for svn\n"; |
print "NOTICE: using $SVNREP as directory for svn\n"; |
233 |
|
|
234 |
printf($fmt, $e->{'revision'}, $e->{'author'}, $e->{'date'}, $e->{'msg'}); |
printf($fmt, $e->{'revision'}, $e->{'author'}, $e->{'date'}, $e->{'msg'}); |
235 |
|
my @commit; |
236 |
|
|
237 |
foreach my $p (@{$e->{'paths'}->{'path'}}) { |
foreach my $p (@{$e->{'paths'}->{'path'}}) { |
238 |
my ($action,$path) = ($p->{'action'},$p->{'content'}); |
my ($action,$path) = ($p->{'action'},$p->{'content'}); |
239 |
|
|
241 |
|
|
242 |
# prepare path and message |
# prepare path and message |
243 |
my $file = $path; |
my $file = $path; |
244 |
$path =~ s,^$SVNREP/*,, || die "BUG: can't strip SVNREP from path"; |
$path =~ s,^$SVNREP/*,, || die "BUG: can't strip SVNREP '$SVNREP' from path"; |
245 |
|
|
246 |
if (! $path) { |
if (! $path) { |
247 |
print "NOTICE: skipped this operation. Probably trunk creation\n"; |
print "NOTICE: skipped this operation. Probably trunk creation\n"; |
257 |
if (-d $path) { |
if (-d $path) { |
258 |
chdir($path) || die "can't cd into dir $path for import: $!"; |
chdir($path) || die "can't cd into dir $path for import: $!"; |
259 |
log_system("$cvs import -d -m '$msg' $CVSREP/$path svn r$rev", "cvs import of $path failed"); |
log_system("$cvs import -d -m '$msg' $CVSREP/$path svn r$rev", "cvs import of $path failed"); |
260 |
|
if (-d "$CVSREP/$path") { |
261 |
|
rmdir "$CVSREP/$path" || die "can't remove $CVSREP/$path: $!"; |
262 |
|
} else { |
263 |
|
unlink "$CVSREP/$path" || die "can't remove $CVSREP/$path: $!"; |
264 |
|
} |
265 |
chdir("$TMPDIR") || die "can't cd to $TMPDIR/$CVSREP: $!"; |
chdir("$TMPDIR") || die "can't cd to $TMPDIR/$CVSREP: $!"; |
266 |
log_system("$cvs checkout $CVSREP/$path", "cvs checkout of imported dir $path failed"); |
log_system("$cvs checkout $CVSREP/$path", "cvs checkout of imported dir $path failed"); |
267 |
chdir("$TMPDIR/$CVSREP") || die "can't cd back to $TMPDIR/$CVSREP: $!"; |
chdir("$TMPDIR/$CVSREP") || die "can't cd back to $TMPDIR/$CVSREP: $!"; |
279 |
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"; |
280 |
} |
} |
281 |
|
|
282 |
# now commit changes |
# save commits for later |
283 |
log_system("$cvs commit -m '$msg' $path", "cvs commit of $path failed"); |
push @commit, $path; |
284 |
|
|
285 |
} |
} |
286 |
|
|
287 |
|
my $msg = $e->{'msg'}; |
288 |
|
$msg =~ s/'/'\\''/g; # quote " |
289 |
|
|
290 |
|
# now commit changes |
291 |
|
log_system("$cvs commit -m '$msg' ".join(" ",@commit), "cvs commit of ".join(",",@commit)." failed"); |
292 |
|
|
293 |
commit_svnrev($rev); |
commit_svnrev($rev); |
294 |
} |
} |
295 |
|
|
312 |
|
|
313 |
=head1 DESCRIPTION |
=head1 DESCRIPTION |
314 |
|
|
315 |
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 |
316 |
|
(read-only) CVS repository manually or from Subversion's C<post-commit> hook. |
317 |
|
|
318 |
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 |
319 |
B<CVSROOT/CVSREPOSITORY> to store last Subversion revision which was |
B<CVSROOT/CVSREPOSITORY> to store last Subversion revision which was |
365 |
"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 |
366 |
create multiple copies of files in CVS repository! |
create multiple copies of files in CVS repository! |
367 |
|
|
368 |
|
This script assume that you want to sync your C<trunk> (or any other |
369 |
|
directory for that matter) directory with CVS, not root of your subversion. |
370 |
|
This might be considered bug, but since common practise is to have |
371 |
|
directories C<trunk> and C<branches> in svn and source code in them, it's |
372 |
|
not serious limitation. |
373 |
|
|
374 |
=head1 RELATED PROJECTS |
=head1 RELATED PROJECTS |
375 |
|
|
376 |
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 |
380 |
Subversion repository. It is designed for one-time conversions, not for |
Subversion repository. It is designed for one-time conversions, not for |
381 |
repeated synchronizations between CVS and Subversion. |
repeated synchronizations between CVS and Subversion. |
382 |
|
|
383 |
|
=head1 CHANGES |
384 |
|
|
385 |
|
Versions of this utility are actually Subversion repository revisions, |
386 |
|
so they might not be in sequence. |
387 |
|
|
388 |
|
=over 3 |
389 |
|
|
390 |
|
=item r10 |
391 |
|
|
392 |
|
First release available to public |
393 |
|
|
394 |
|
=item r15 |
395 |
|
|
396 |
|
Addition of comprehensive documentation, fixes for quoting in commit |
397 |
|
messages, and support for skipping changes which are not under current |
398 |
|
Subversion checkout root (e.g. branches). |
399 |
|
|
400 |
|
=item r18 |
401 |
|
|
402 |
|
Support for importing your svn into empty CVS repository (it will first |
403 |
|
create module and than dump all revisions). |
404 |
|
Group commit operations to save round-trips to CVS server. |
405 |
|
Documentation improvements and other small fixes. |
406 |
|
|
407 |
|
|
408 |
|
=back |
409 |
|
|
410 |
=head1 AUTHOR |
=head1 AUTHOR |
411 |
|
|
412 |
Dobrica Pavlinusic <dpavlin@rot13.org> |
Dobrica Pavlinusic <dpavlin@rot13.org> |