18 |
my $HOME = $ENV{'HOME'} || die "can't get home directory!"; |
my $HOME = $ENV{'HOME'} || die "can't get home directory!"; |
19 |
|
|
20 |
# cvsroot directory |
# cvsroot directory |
21 |
my $CVSROOT="$HOME/x/cvsroot"; |
my $CVSROOT=':pserver:dpavlin@cvs.tigris.org:/cvs'; |
22 |
# name of cvs repository to commit to |
# name of cvs repository to commit to |
23 |
my $CVSREP="webpac"; |
my $CVSREP="svn2cvs/src"; |
24 |
|
|
25 |
|
$CVSROOT="$HOME/x/cvsroot"; |
26 |
|
$CVSREP="svn2cvs/src"; |
27 |
|
|
28 |
# svnroot directory |
# svnroot directory |
29 |
my $SVNROOT="file://$HOME/private/svn/webpac/"; |
my $SVNROOT="file://$HOME/private/svn/svn2cvs"; |
30 |
# name of respository |
# name of respository |
31 |
my $SVNREP="trunk"; |
my $SVNREP="trunk"; |
32 |
|
|
33 |
|
# webpac example |
34 |
|
#$CVSROOT="$HOME/x/cvsroot"; |
35 |
|
#$CVSREP="webpac"; |
36 |
|
#$SVNROOT="file://$HOME/private/svn/webpac/"; |
37 |
|
#$SVNREP="trunk"; |
38 |
|
|
39 |
my $TMPDIR=tempdir( "/tmp/checkoutXXXXX", CLEANUP => 1 ); |
my $TMPDIR=tempdir( "/tmp/checkoutXXXXX", CLEANUP => 1 ); |
40 |
|
|
41 |
chdir($TMPDIR) || die "can't cd to $TMPDIR: $!"; |
chdir($TMPDIR) || die "can't cd to $TMPDIR: $!"; |
52 |
system $cmd || die "$errmsg: $!"; |
system $cmd || die "$errmsg: $!"; |
53 |
} |
} |
54 |
|
|
55 |
|
# |
56 |
|
# sub to commit .svn rev file later |
57 |
|
# |
58 |
|
sub commit_svnrev { |
59 |
|
my $rev = shift @_; |
60 |
|
my $add_new = shift @_; |
61 |
|
|
62 |
# ok, now do the checkout |
die "commit_svnrev needs revision" if (! defined($rev)); |
63 |
|
|
64 |
log_system("$cvs checkout $CVSREP","cvs checkout failed"); |
open(SVNREV,"> .svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; |
65 |
|
print SVNREV $rev; |
66 |
|
close(SVNREV); |
67 |
|
|
68 |
# check if svnrev exists |
my $path=".svnrev"; |
69 |
|
|
70 |
if (! -e "$CVSREP/.svnrev") { |
if ($add_new) { |
71 |
print <<_USAGE_; |
system "$cvs add $path" || die "cvs add of $path failed: $!"; |
72 |
|
} else { |
73 |
|
my $msg="subversion revision $rev commited to CVS"; |
74 |
|
print "$msg\n"; |
75 |
|
system "$cvs commit -m \"$msg\" $path" || die "cvs commit of $path failed: $!"; |
76 |
|
} |
77 |
|
} |
78 |
|
|
79 |
Your CVS repository doesn't have $TMPDIR/$CVSREP/.svnrev file! |
# ok, now do the checkout |
80 |
|
|
81 |
This file is used to commit changes to CVS repository with correct |
log_system("$cvs -q checkout $CVSREP","cvs checkout failed"); |
|
logs from Subversion. |
|
82 |
|
|
83 |
Please create .svnrec file with currect svn revision which |
chdir($CVSREP) || die "can't cd to $TMPDIR/$CVSREP: $!"; |
|
corresponds to version of checkouted tree and commit that file |
|
|
to CVS repository, e.g. |
|
|
|
|
|
echo 233 > .svnrev |
|
|
cvs add .svnrev |
|
|
cvs commit -m "subversion repository revision sync file" .svnrev |
|
84 |
|
|
|
_USAGE_ |
|
|
print "CVS Repository left in $TMPDIR/$CVSREP\n"; |
|
|
exit 1; |
|
|
} |
|
85 |
|
|
86 |
|
my $rev; |
87 |
|
|
88 |
open(SVNREV,"$CVSREP/.svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; |
# check if svnrev exists |
89 |
my $rev = <SVNREV>; |
if (! -e ".svnrev") { |
90 |
chomp($rev); |
print <<_USAGE_; |
|
close(SVNREV); |
|
91 |
|
|
92 |
print "Starting after revision $rev\n"; |
Your CVS repository doesn't have .svnrev file! |
|
$rev++; |
|
93 |
|
|
94 |
|
This file is used to keep CVS repository and SubVersion in sync, so |
95 |
|
that only newer changes will be commited. |
96 |
|
|
97 |
# |
It's quote possible that this is first svn2cvs run for this repository. |
98 |
# sub to commit .svn rev file later |
If so, you will have to identify correct svn revision which |
99 |
# |
corresponds to current version of CVS repository that has just |
100 |
|
been checkouted. |
101 |
|
|
102 |
|
If you migrated your cvs repository to svn using cvs2svn, this will be |
103 |
|
last SubVersion revision. If this is initial run of conversion of |
104 |
|
SubVersion repository to CVS, correct revision is 0. |
105 |
|
|
106 |
sub commit_svnrev($) { |
_USAGE_ |
|
my $rev = shift @_ || die "commit_svnrev needs revision"; |
|
107 |
|
|
108 |
open(SVNREV,"> $CVSREP/.svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; |
print "svn revision corresponding to CVS [abort]: "; |
109 |
print SVNREV $rev; |
my $in = <STDIN>; |
110 |
|
chomp($in); |
111 |
|
if ($in !~ /^\d+$/) { |
112 |
|
print "Aborting: revision not a number\n"; |
113 |
|
exit 1; |
114 |
|
} else { |
115 |
|
$rev = $in; |
116 |
|
commit_svnrev($rev,1); # create new |
117 |
|
} |
118 |
|
} else { |
119 |
|
open(SVNREV,".svnrev") || die "can't open $TMPDIR/$CVSREP/.svnrev: $!"; |
120 |
|
$rev = <SVNREV>; |
121 |
|
chomp($rev); |
122 |
close(SVNREV); |
close(SVNREV); |
|
|
|
|
my $msg="subversion revision $rev commited to CVS"; |
|
|
my $path=".svnrev"; |
|
|
print "$msg\n"; |
|
|
system "$cvs commit -m \"$msg\" $CVSREP/$path" || die "cvs commit of $path failed: $!"; |
|
123 |
} |
} |
124 |
|
|
125 |
|
print "Starting after revision $rev\n"; |
126 |
|
$rev++; |
127 |
|
|
128 |
|
|
129 |
# |
# |
130 |
# FIXME!! HEAD should really be next verison and loop because this way we |
# FIXME!! HEAD should really be next verison and loop because this way we |
131 |
# loose multiple edits of same file and corresponding messages. On the |
# loose multiple edits of same file and corresponding messages. On the |
159 |
exit 0; |
exit 0; |
160 |
} |
} |
161 |
|
|
|
print Dumper($xml); |
|
|
|
|
162 |
foreach my $e (@{$xml->{'logentry'}}) { |
foreach my $e (@{$xml->{'logentry'}}) { |
163 |
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'}); |
164 |
$rev = $e->{'revision'}; |
$rev = $e->{'revision'}; |
165 |
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/$SVNREP $TMPDIR/$CVSREP", "svn export of revision $rev failed"); |
166 |
|
|
167 |
printf($fmt, $e->{'revision'}, $e->{'author'}, $e->{'date'}, $e->{'msg'}); |
printf($fmt, $e->{'revision'}, $e->{'author'}, $e->{'date'}, $e->{'msg'}); |
168 |
foreach my $p (@{$e->{'paths'}->{'path'}}) { |
foreach my $p (@{$e->{'paths'}->{'path'}}) { |
173 |
# prepare path and message |
# prepare path and message |
174 |
my $file = $path; |
my $file = $path; |
175 |
$path =~ s,^/$SVNREP/*,, || die "BUG: can't strip SVNREP from path"; |
$path =~ s,^/$SVNREP/*,, || die "BUG: can't strip SVNREP from path"; |
176 |
|
|
177 |
|
if (! $path) { |
178 |
|
print "NOTICE: skipped this operation. Probably trunk creation\n"; |
179 |
|
next; |
180 |
|
} |
181 |
|
|
182 |
my $msg = $e->{'msg'}; |
my $msg = $e->{'msg'}; |
183 |
$msg =~ s/"/\\"/g; # quote " |
$msg =~ s/"/\\"/g; # quote " |
184 |
|
|
185 |
if ($action =~ /M/) { |
if ($action =~ /M/) { |
186 |
print "svn2cvs: modify $path -- nop\n"; |
print "svn2cvs: modify $path -- nop\n"; |
187 |
} elsif ($action =~ /A/) { |
} elsif ($action =~ /A/) { |
188 |
log_system("$cvs add -m \"$msg\" $CVSREP/$path", "cvs add of $path failed"); |
log_system("$cvs add -m \"$msg\" $path", "cvs add of $path failed"); |
189 |
} elsif ($action =~ /D/) { |
} elsif ($action =~ /D/) { |
190 |
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"); |
191 |
} else { |
} else { |
192 |
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"; |
193 |
} |
} |
194 |
|
|
195 |
# now commit changes |
# now commit changes |
196 |
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"); |
197 |
|
|
198 |
} |
} |
199 |
|
|