164
my $rv = GetOptions(%opts, 'help|H|h' => \$_help, 'version|V' => \$_version,
165
'minimize-connections' => \$Git::SVN::Migration::_minimize,
166
'id|i=s' => \$Git::SVN::default_ref_id,
167
- 'svn-remote|remote|R=s' => \$Git::SVN::default_repo_id);
167
+ 'svn-remote|remote|R=s' => sub {
168
+ $Git::SVN::no_reuse_existing = 1;
169
+ $Git::SVN::default_repo_id = $_[1] });
170
exit 1 if (!$rv && $cmd ne 'log');
171
172
usage(0) if $_help;
751
use warnings;
752
use vars qw/$default_repo_id $default_ref_id $_no_metadata $_follow_parent
753
$_repack $_repack_flags $_use_svm_props $_head
752
- $_use_svnsync_props/;
754
+ $_use_svnsync_props $no_reuse_existing/;
755
use Carp qw/croak/;
756
use File::Path qw/mkpath/;
757
use File::Copy qw/copy/;
946
947
sub find_existing_remote {
948
my ($url, $remotes) = @_;
949
+ return undef if $no_reuse_existing;
950
my $existing;
951
foreach my $repo_id (keys %$remotes) {
952
my $u = $remotes->{$repo_id}->{url} or next;
1119
$svm = {
1120
source => tmp_config('--get', "$section.svm-source"),
1121
uuid => tmp_config('--get', "$section.svm-uuid"),
1122
+ replace => tmp_config('--get', "$section.svm-replace"),
1123
}
1124
};
1121
- $self->{svm} = $svm if ($svm && $svm->{source} && $svm->{uuid});
1125
+ if ($svm && $svm->{source} && $svm->{uuid} && $svm->{replace}) {
1126
+ $self->{svm} = $svm;
1127
+ }
1128
$self->{svm};
1129
}
1130
1133
return $ra if $self->svm;
1134
1135
my @err = ( "useSvmProps set, but failed to read SVM properties\n",
1130
- "(svm:source, svm:mirror, svm:mirror) ",
1136
+ "(svm:source, svm:uuid) ",
1137
"from the following URLs:\n" );
1138
sub read_svm_props {
1133
- my ($self, $props) = @_;
1139
+ my ($self, $ra, $path, $r) = @_;
1140
+ my $props = ($ra->get_dir($path, $r))[2];
1141
my $src = $props->{'svm:source'};
1135
- my $mirror = $props->{'svm:mirror'};
1142
my $uuid = $props->{'svm:uuid'};
1137
- return undef if (!$src || !$mirror || !$uuid);
1143
+ return undef if (!$src || !$uuid);
1144
1139
- chomp($src, $mirror, $uuid);
1145
+ chomp($src, $uuid);
1146
1147
$uuid =~ m{^[0-9a-f\-]{30,}$}
1148
or die "doesn't look right - svm:uuid is '$uuid'\n";
1143
- # don't know what a '!' is there for, also the
1144
- # username is of no interest
1145
- $src =~ s{/?!$}{$mirror};
1149
+
1150
+ # the '!' is used to mark the repos_root!/relative/path
1151
+ $src =~ s{/?!/?}{/};
1152
$src =~ s{/+$}{}; # no trailing slashes please
1153
+ # username is of no interest
1154
$src =~ s{(^[a-z\+]*://)[^/@]*@}{$1};
1155
1156
+ my $replace = $ra->{url};
1157
+ $replace .= "/$path" if length $path;
1158
+
1159
my $section = "svn-remote.$self->{repo_id}";
1150
- tmp_config('--add', "$section.svm-source", $src);
1151
- tmp_config('--add', "$section.svm-uuid", $uuid);
1152
- $self->{svm} = { source => $src , uuid => $uuid };
1153
- return 1;
1160
+ tmp_config("$section.svm-source", $src);
1161
+ tmp_config("$section.svm-replace", $replace);
1162
+ tmp_config("$section.svm-uuid", $uuid);
1163
+ $self->{svm} = {
1164
+ source => $src,
1165
+ uuid => $uuid,
1166
+ replace => $replace
1167
+ };
1168
}
1169
1170
my $r = $ra->get_latest_revnum;
1171
my $path = $self->{path};
1158
- my @tried_a = ($path);
1172
+ my %tried;
1173
while (length $path) {
1160
- if ($self->read_svm_props(($ra->get_dir($path, $r))[2])) {
1161
- return $ra;
1174
+ unless ($tried{"$self->{url}/$path"}) {
1175
+ return $ra if $self->read_svm_props($ra, $path, $r);
1176
+ $tried{"$self->{url}/$path"} = 1;
1177
}
1163
- $path =~ s#/?[^/]+$## && push @tried_a, $path;
1164
- }
1165
- if ($self->read_svm_props(($ra->get_dir('', $r))[2])) {
1166
- return $ra;
1178
+ $path =~ s#/?[^/]+$##;
1179
}
1180
+ die "Path: '$path' should be ''\n" if $path ne '';
1181
+ return $ra if $self->read_svm_props($ra, $path, $r);
1182
+ $tried{"$self->{url}/$path"} = 1;
1183
1184
if ($ra->{repos_root} eq $self->{url}) {
1170
- die @err, map { " $self->{url}/$_\n" } @tried_a, "\n";
1185
+ die @err, (map { " $_\n" } keys %tried), "\n";
1186
}
1187
1188
# nope, make sure we're connected to the repository root:
1189
my $ok;
1190
my @tried_b;
1191
$path = $ra->{svn_path};
1177
- $path =~ s#/?[^/]+$##; # we already tried this one above
1192
$ra = Git::SVN::Ra->new($ra->{repos_root});
1193
while (length $path) {
1180
- $ok = $self->read_svm_props(($ra->get_dir($path, $r))[2]);
1181
- last if $ok;
1182
- $path =~ s#/?[^/]+$## && push @tried_b, $path;
1194
+ unless ($tried{"$ra->{url}/$path"}) {
1195
+ $ok = $self->read_svm_props($ra, $path, $r);
1196
+ last if $ok;
1197
+ $tried{"$ra->{url}/$path"} = 1;
1198
+ }
1199
+ $path =~ s#/?[^/]+$##;
1200
}
1184
- $ok = $self->read_svm_props(($ra->get_dir('', $r))[2]) unless $ok;
1201
+ die "Path: '$path' should be ''\n" if $path ne '';
1202
+ $ok ||= $self->read_svm_props($ra, $path, $r);
1203
+ $tried{"$ra->{url}/$path"} = 1;
1204
if (!$ok) {
1186
- die @err, map { " $self->{url}/$_\n" } @tried_a, "\n",
1187
- map { " $ra->{url}/$_\n" } @tried_b, "\n"
1205
+ die @err, (map { " $_\n" } keys %tried), "\n";
1206
}
1207
Git::SVN::Ra->new($self->{url});
1208
}
1797
"options set!\n";
1798
}
1799
my ($uuid, $r) = $headrev =~ m{^([a-f\d\-]{30,}):(\d+)$};
1782
- if ($uuid ne $self->{svm}->{uuid}) {
1800
+ # we don't want "SVM: initializing mirror for junk" ...
1801
+ return undef if $r == 0;
1802
+ my $svm = $self->svm;
1803
+ if ($uuid ne $svm->{uuid}) {
1804
die "UUID mismatch on SVM path:\n",
1784
- "expected: $self->{svm}->{uuid}\n",
1805
+ "expected: $svm->{uuid}\n",
1806
" got: $uuid\n";
1807
}
1787
- my $full_url = $self->{svm}->{source};
1788
- $full_url .= "/$self->{path}" if length $self->{path};
1808
+ my $full_url = $self->full_url;
1809
+ $full_url =~ s#^\Q$svm->{replace}\E(/|$)#$svm->{source}$1# or
1810
+ die "Failed to replace '$svm->{replace}' with ",
1811
+ "'$svm->{source}' in $full_url\n";
1812
$log_entry{metadata} = "$full_url\@$r $uuid";
1813
$log_entry{svm_revision} = $r;
1814
$email ||= "$author\@$uuid"