5
6
use File::Temp qw(tempdir);
8
10
# This should be read-only.
9
use constant BZR_REPO => 'bzr://localhost/bugzilla/';
11
use constant BZR_REPO => 'http://bzr.mozilla.org/bugzilla/';
10
12
# This should be a full CVSROOT that you can commit to.
11
use constant CVS_REPO => '/home/mkanat/cvs-import/mozilla-cvs/';
13
use constant CVS_REPO => 'mkanat%bugzilla.org@cvs.mozilla.org:/cvsroot';
12
14
use constant CVS_MODULE => 'mozilla/webtools/bugzilla';
16
our (%switch, $verbose);
15
print join(' ', @_), "\n";
19
print join(' ', @_), "\n" if $verbose;
63
67
my $to_dir = tempdir(CLEANUP => 1);
64
68
my @branch_args = ($branch eq 'HEAD') ? () : ('-r', $branch);
69
# When using cvs in server mode, we can't specify an absolute path, so
70
# we chdir to /tmp and use a relative path.
72
my $temp_dir = File::Spec->tmpdir;
74
$to_dir =~ s{^\Q$temp_dir\E/}{};
65
75
do_command('cvs', '-Q', '-d', CVS_REPO, 'checkout', '-P', '-d', $to_dir,
66
76
@branch_args, 'Bugzilla') && exit $?;
78
return "$temp_dir/$to_dir";
70
81
sub remove_removed_files {
76
87
remove_cvs_file($_) foreach @files;
78
89
# We retain .cvsignore files in CVS even if we deleted them in bzr.
79
elsif ($item !~ /\.cvsignore/) {
90
# Also, we don't delete the .bzrrev file, of course.
91
elsif ($item !~ /\.cvsignore/ and $item !~ /\.bzrrev/) {
80
92
remove_cvs_file($item);
88
100
do_command('cvs', 'rm', $file);
92
my $list = `bzr status -S`;
103
sub get_added_and_removed_files {
104
my $list = `bzr status -S | grep -v '/CVS'`;
105
my (@added, @removed);
94
106
my @lines = split("\n", $list);
95
107
foreach my $line (@lines) {
96
108
if ($line =~ /^\s*D\s+(.+)/) {
111
elsif ($line =~ /^\?\s+(.+)/) {
115
return (\@added, \@removed);
103
118
sub get_log_message {
124
139
do_command('cvs', @switches, 'add', @files) if @files;
128
GetOptions(\%switch, 'from=s', 'to=s', 'dry-run|n') || die $@;
142
GetOptions(\%switch, 'from=s', 'to=s', 'dry-run|n', 'verbose|v') || die $@;
129
143
($switch{from} && $switch{to}) or die "--from and --to must be specified.\n";
130
144
my ($from, $to) = @switch{qw(from to)};
145
$verbose = $switch{'verbose'};
132
147
my $cvs_checkout = checkout_cvs($to);
133
148
my $last_bzr_rev = get_last_rev($cvs_checkout);
145
160
my $bzr_checkout = checkout_bzr($from, $last_bzr_rev);
147
# Figure out added files by moving the .bzr directory to the CVS
148
# directory and using bzr commands on the CVS directory.
162
# Figure out added and removed files by moving the .bzr directory
163
# to the CVS directory, and using bzr commands on the CVS directory.
149
164
do_command("mv", "$bzr_checkout/.bzr/", "$cvs_checkout/");
150
165
chdir($cvs_checkout);
151
my @added = get_added_files();
166
my ($added, $removed) = get_added_and_removed_files();
152
167
do_command('mv', "$cvs_checkout/.bzr/", "$bzr_checkout/");
154
# Figure out removed files by copying over the CVS stuff into bzr
155
# and seeing what it says is "added".
156
do_command("cp -arf $cvs_checkout/* $bzr_checkout/");
157
do_command("find $bzr_checkout -depth -type d -name CVS"
158
. " -exec rm -rf {} \\;");
159
169
chdir($bzr_checkout);
160
my $removed_list = `bzr unknowns`;
161
my @removed = split("\n", $removed_list);
163
170
my $log_message = get_log_message($last_bzr_rev);
165
172
# Copy over the bzr data into the CVS checkout in preparation for commit.
166
173
do_command('rm', '-rf', "$bzr_checkout/.bzr/");
167
do_command("cp -arf $bzr_checkout/* $cvs_checkout/");
174
my @v_switch = $verbose ? ('-v') : ();
175
do_command("rsync", "-a", @v_switch, "$bzr_checkout/", "$cvs_checkout/");
169
177
chdir($cvs_checkout);
170
remove_removed_files(@removed);
171
add_added_files($bzr_checkout, $switch{'dry-run'}, @added);
178
remove_removed_files(@$removed);
179
add_added_files($bzr_checkout, $switch{'dry-run'}, @$added);
172
180
my @dry_switch = $switch{'dry-run'} ? ('-n') : ();
173
181
my $updated_rev = update_last_rev($cvs_checkout, $last_bzr_rev);
174
182
do_command('cvs', @dry_switch, 'commit', '-m', $log_message);