]>
Commit | Line | Data |
---|---|---|
9f7ad147 JN |
1 | package Git::SVN::Ra; |
2 | use vars qw/@ISA $config_dir $_ignore_refs_regex $_log_window_size/; | |
3 | use strict; | |
4 | use warnings; | |
835e3dde | 5 | use Memoize; |
9f7ad147 | 6 | use SVN::Client; |
565e56c2 MS |
7 | use Git::SVN::Utils qw( |
8 | canonicalize_url | |
705b49cb | 9 | canonicalize_path |
d2fd119c | 10 | add_path_to_url |
565e56c2 MS |
11 | ); |
12 | ||
9f7ad147 JN |
13 | use SVN::Ra; |
14 | BEGIN { | |
15 | @ISA = qw(SVN::Ra); | |
16 | } | |
17 | ||
18 | my ($ra_invalid, $can_do_switch, %ignored_err, $RA); | |
19 | ||
20 | BEGIN { | |
21 | # enforce temporary pool usage for some simple functions | |
22 | no strict 'refs'; | |
23 | for my $f (qw/rev_proplist get_latest_revnum get_uuid get_repos_root | |
24 | get_file/) { | |
25 | my $SUPER = "SUPER::$f"; | |
26 | *$f = sub { | |
27 | my $self = shift; | |
28 | my $pool = SVN::Pool->new; | |
29 | my @ret = $self->$SUPER(@_,$pool); | |
30 | $pool->clear; | |
31 | wantarray ? @ret : $ret[0]; | |
32 | }; | |
33 | } | |
34 | } | |
35 | ||
73ffac3b UH |
36 | # serf has a bug that leads to a coredump upon termination if the |
37 | # remote access object is left around (not fixed yet in serf 1.3.1). | |
38 | # Explicitly free it to work around the issue. | |
39 | END { | |
40 | $RA = undef; | |
41 | $ra_invalid = 1; | |
42 | } | |
43 | ||
9f7ad147 JN |
44 | sub _auth_providers () { |
45 | my @rv = ( | |
46 | SVN::Client::get_simple_provider(), | |
47 | SVN::Client::get_ssl_server_trust_file_provider(), | |
48 | SVN::Client::get_simple_prompt_provider( | |
49 | \&Git::SVN::Prompt::simple, 2), | |
50 | SVN::Client::get_ssl_client_cert_file_provider(), | |
51 | SVN::Client::get_ssl_client_cert_prompt_provider( | |
52 | \&Git::SVN::Prompt::ssl_client_cert, 2), | |
53 | SVN::Client::get_ssl_client_cert_pw_file_provider(), | |
54 | SVN::Client::get_ssl_client_cert_pw_prompt_provider( | |
55 | \&Git::SVN::Prompt::ssl_client_cert_pw, 2), | |
56 | SVN::Client::get_username_provider(), | |
57 | SVN::Client::get_ssl_server_trust_prompt_provider( | |
58 | \&Git::SVN::Prompt::ssl_server_trust), | |
59 | SVN::Client::get_username_prompt_provider( | |
60 | \&Git::SVN::Prompt::username, 2) | |
61 | ); | |
62 | ||
63 | # earlier 1.6.x versions would segfault, and <= 1.5.x didn't have | |
64 | # this function | |
65 | if (::compare_svn_version('1.6.15') >= 0) { | |
66 | my $config = SVN::Core::config_get_config($config_dir); | |
67 | my ($p, @a); | |
68 | # config_get_config returns all config files from | |
69 | # ~/.subversion, auth_get_platform_specific_client_providers | |
70 | # just wants the config "file". | |
71 | @a = ($config->{'config'}, undef); | |
72 | $p = SVN::Core::auth_get_platform_specific_client_providers(@a); | |
73 | # Insert the return value from | |
74 | # auth_get_platform_specific_providers | |
75 | unshift @rv, @$p; | |
76 | } | |
77 | \@rv; | |
78 | } | |
79 | ||
835e3dde EW |
80 | sub prepare_config_once { |
81 | SVN::_Core::svn_config_ensure($config_dir, undef); | |
82 | my ($baton, $callbacks) = SVN::Core::auth_open_helper(_auth_providers); | |
83 | my $config = SVN::Core::config_get_config($config_dir); | |
84 | my $dont_store_passwords = 1; | |
85 | my $conf_t = $config->{'config'}; | |
86 | ||
87 | no warnings 'once'; | |
88 | # The usage of $SVN::_Core::SVN_CONFIG_* variables | |
89 | # produces warnings that variables are used only once. | |
90 | # I had not found the better way to shut them up, so | |
91 | # the warnings of type 'once' are disabled in this block. | |
92 | if (SVN::_Core::svn_config_get_bool($conf_t, | |
93 | $SVN::_Core::SVN_CONFIG_SECTION_AUTH, | |
94 | $SVN::_Core::SVN_CONFIG_OPTION_STORE_PASSWORDS, | |
95 | 1) == 0) { | |
96 | SVN::_Core::svn_auth_set_parameter($baton, | |
97 | $SVN::_Core::SVN_AUTH_PARAM_DONT_STORE_PASSWORDS, | |
98 | bless (\$dont_store_passwords, "_p_void")); | |
99 | } | |
100 | if (SVN::_Core::svn_config_get_bool($conf_t, | |
101 | $SVN::_Core::SVN_CONFIG_SECTION_AUTH, | |
102 | $SVN::_Core::SVN_CONFIG_OPTION_STORE_AUTH_CREDS, | |
103 | 1) == 0) { | |
104 | $Git::SVN::Prompt::_no_auth_cache = 1; | |
105 | } | |
106 | ||
107 | return ($config, $baton, $callbacks); | |
108 | } # no warnings 'once' | |
109 | ||
110 | INIT { | |
111 | Memoize::memoize '_auth_providers'; | |
112 | Memoize::memoize 'prepare_config_once'; | |
113 | } | |
9f7ad147 JN |
114 | |
115 | sub new { | |
116 | my ($class, $url) = @_; | |
8266fc8b | 117 | $url = canonicalize_url($url); |
b4943dc9 | 118 | return $RA if ($RA && $RA->url eq $url); |
9f7ad147 JN |
119 | |
120 | ::_req_svn(); | |
121 | ||
9f7ad147 | 122 | $RA = undef; |
835e3dde | 123 | my ($config, $baton, $callbacks) = prepare_config_once(); |
8266fc8b | 124 | my $self = SVN::Ra->new(url => $url, auth => $baton, |
9f7ad147 JN |
125 | config => $config, |
126 | pool => SVN::Pool->new, | |
127 | auth_provider_callbacks => $callbacks); | |
b4943dc9 MS |
128 | $RA = bless $self, $class; |
129 | ||
130 | # Make sure its canonicalized | |
131 | $self->url($url); | |
9f7ad147 JN |
132 | $self->{svn_path} = $url; |
133 | $self->{repos_root} = $self->get_repos_root; | |
134 | $self->{svn_path} =~ s#^\Q$self->{repos_root}\E(/|$)##; | |
135 | $self->{cache} = { check_path => { r => 0, data => {} }, | |
136 | get_dir => { r => 0, data => {} } }; | |
b4943dc9 MS |
137 | |
138 | return $RA; | |
139 | } | |
140 | ||
141 | sub url { | |
142 | my $self = shift; | |
143 | ||
144 | if (@_) { | |
145 | my $url = shift; | |
565e56c2 | 146 | $self->{url} = canonicalize_url($url); |
b4943dc9 MS |
147 | return; |
148 | } | |
149 | ||
150 | return $self->{url}; | |
9f7ad147 JN |
151 | } |
152 | ||
153 | sub check_path { | |
154 | my ($self, $path, $r) = @_; | |
155 | my $cache = $self->{cache}->{check_path}; | |
156 | if ($r == $cache->{r} && exists $cache->{data}->{$path}) { | |
157 | return $cache->{data}->{$path}; | |
158 | } | |
159 | my $pool = SVN::Pool->new; | |
160 | my $t = $self->SUPER::check_path($path, $r, $pool); | |
161 | $pool->clear; | |
162 | if ($r != $cache->{r}) { | |
163 | %{$cache->{data}} = (); | |
164 | $cache->{r} = $r; | |
165 | } | |
166 | $cache->{data}->{$path} = $t; | |
167 | } | |
168 | ||
169 | sub get_dir { | |
170 | my ($self, $dir, $r) = @_; | |
171 | my $cache = $self->{cache}->{get_dir}; | |
172 | if ($r == $cache->{r}) { | |
173 | if (my $x = $cache->{data}->{$dir}) { | |
174 | return wantarray ? @$x : $x->[0]; | |
175 | } | |
176 | } | |
177 | my $pool = SVN::Pool->new; | |
178 | my ($d, undef, $props) = $self->SUPER::get_dir($dir, $r, $pool); | |
179 | my %dirents = map { $_ => { kind => $d->{$_}->kind } } keys %$d; | |
180 | $pool->clear; | |
181 | if ($r != $cache->{r}) { | |
182 | %{$cache->{data}} = (); | |
183 | $cache->{r} = $r; | |
184 | } | |
185 | $cache->{data}->{$dir} = [ \%dirents, $r, $props ]; | |
186 | wantarray ? (\%dirents, $r, $props) : \%dirents; | |
187 | } | |
188 | ||
9f7ad147 JN |
189 | # get_log(paths, start, end, limit, |
190 | # discover_changed_paths, strict_node_history, receiver) | |
191 | sub get_log { | |
192 | my ($self, @args) = @_; | |
193 | my $pool = SVN::Pool->new; | |
194 | ||
195 | # svn_log_changed_path_t objects passed to get_log are likely to be | |
196 | # overwritten even if only the refs are copied to an external variable, | |
197 | # so we should dup the structures in their entirety. Using an | |
198 | # externally passed pool (instead of our temporary and quickly cleared | |
199 | # pool in Git::SVN::Ra) does not help matters at all... | |
200 | my $receiver = pop @args; | |
201 | my $prefix = "/".$self->{svn_path}; | |
202 | $prefix =~ s#/+($)##; | |
203 | my $prefix_regex = qr#^\Q$prefix\E#; | |
204 | push(@args, sub { | |
205 | my ($paths) = $_[0]; | |
206 | return &$receiver(@_) unless $paths; | |
207 | $_[0] = (); | |
208 | foreach my $p (keys %$paths) { | |
209 | my $i = $paths->{$p}; | |
210 | # Make path relative to our url, not repos_root | |
211 | $p =~ s/$prefix_regex//; | |
212 | my %s = map { $_ => $i->$_; } | |
213 | qw/copyfrom_path copyfrom_rev action/; | |
214 | if ($s{'copyfrom_path'}) { | |
215 | $s{'copyfrom_path'} =~ s/$prefix_regex//; | |
705b49cb | 216 | $s{'copyfrom_path'} = canonicalize_path($s{'copyfrom_path'}); |
9f7ad147 JN |
217 | } |
218 | $_[0]{$p} = \%s; | |
219 | } | |
220 | &$receiver(@_); | |
221 | }); | |
222 | ||
223 | ||
224 | # the limit parameter was not supported in SVN 1.1.x, so we | |
225 | # drop it. Therefore, the receiver callback passed to it | |
226 | # is made aware of this limitation by being wrapped if | |
227 | # the limit passed to is being wrapped. | |
228 | if (::compare_svn_version('1.2.0') <= 0) { | |
229 | my $limit = splice(@args, 3, 1); | |
230 | if ($limit > 0) { | |
231 | my $receiver = pop @args; | |
232 | push(@args, sub { &$receiver(@_) if (--$limit >= 0) }); | |
233 | } | |
234 | } | |
235 | my $ret = $self->SUPER::get_log(@args, $pool); | |
236 | $pool->clear; | |
237 | $ret; | |
238 | } | |
239 | ||
240 | sub trees_match { | |
241 | my ($self, $url1, $rev1, $url2, $rev2) = @_; | |
242 | my $ctx = SVN::Client->new(auth => _auth_providers); | |
243 | my $out = IO::File->new_tmpfile; | |
244 | ||
245 | # older SVN (1.1.x) doesn't take $pool as the last parameter for | |
246 | # $ctx->diff(), so we'll create a default one | |
247 | my $pool = SVN::Pool->new_default_sub; | |
248 | ||
249 | $ra_invalid = 1; # this will open a new SVN::Ra connection to $url1 | |
250 | $ctx->diff([], $url1, $rev1, $url2, $rev2, 1, 1, 0, $out, $out); | |
251 | $out->flush; | |
252 | my $ret = (($out->stat)[7] == 0); | |
253 | close $out or croak $!; | |
254 | ||
255 | $ret; | |
256 | } | |
257 | ||
258 | sub get_commit_editor { | |
259 | my ($self, $log, $cb, $pool) = @_; | |
260 | ||
261 | my @lock = (::compare_svn_version('1.2.0') >= 0) ? (undef, 0) : (); | |
262 | $self->SUPER::get_commit_editor($log, $cb, @lock, $pool); | |
263 | } | |
264 | ||
265 | sub gs_do_update { | |
266 | my ($self, $rev_a, $rev_b, $gs, $editor) = @_; | |
267 | my $new = ($rev_a == $rev_b); | |
6a8d999e | 268 | my $path = $gs->path; |
9f7ad147 JN |
269 | |
270 | if ($new && -e $gs->{index}) { | |
271 | unlink $gs->{index} or die | |
272 | "Couldn't unlink index: $gs->{index}: $!\n"; | |
273 | } | |
274 | my $pool = SVN::Pool->new; | |
275 | $editor->set_path_strip($path); | |
276 | my (@pc) = split m#/#, $path; | |
277 | my $reporter = $self->do_update($rev_b, (@pc ? shift @pc : ''), | |
278 | 1, $editor, $pool); | |
279 | my @lock = (::compare_svn_version('1.2.0') >= 0) ? (undef) : (); | |
280 | ||
281 | # Since we can't rely on svn_ra_reparent being available, we'll | |
282 | # just have to do some magic with set_path to make it so | |
283 | # we only want a partial path. | |
284 | my $sp = ''; | |
285 | my $final = join('/', @pc); | |
286 | while (@pc) { | |
287 | $reporter->set_path($sp, $rev_b, 0, @lock, $pool); | |
288 | $sp .= '/' if length $sp; | |
289 | $sp .= shift @pc; | |
290 | } | |
291 | die "BUG: '$sp' != '$final'\n" if ($sp ne $final); | |
292 | ||
293 | $reporter->set_path($sp, $rev_a, $new, @lock, $pool); | |
294 | ||
295 | $reporter->finish_report($pool); | |
296 | $pool->clear; | |
297 | $editor->{git_commit_ok}; | |
298 | } | |
299 | ||
300 | # this requires SVN 1.4.3 or later (do_switch didn't work before 1.4.3, and | |
301 | # svn_ra_reparent didn't work before 1.4) | |
302 | sub gs_do_switch { | |
303 | my ($self, $rev_a, $rev_b, $gs, $url_b, $editor) = @_; | |
6a8d999e | 304 | my $path = $gs->path; |
9f7ad147 JN |
305 | my $pool = SVN::Pool->new; |
306 | ||
d2fd119c MS |
307 | my $old_url = $self->url; |
308 | my $full_url = add_path_to_url( $self->url, $path ); | |
9f7ad147 JN |
309 | my ($ra, $reparented); |
310 | ||
3747c015 | 311 | if ($old_url =~ m#^svn(\+\w+)?://# || |
9f7ad147 | 312 | ($full_url =~ m#^https?://# && |
9c27a57b | 313 | canonicalize_url($full_url) ne $full_url)) { |
9f7ad147 JN |
314 | $_[0] = undef; |
315 | $self = undef; | |
316 | $RA = undef; | |
317 | $ra = Git::SVN::Ra->new($full_url); | |
318 | $ra_invalid = 1; | |
319 | } elsif ($old_url ne $full_url) { | |
705b49cb MS |
320 | SVN::_Ra::svn_ra_reparent( |
321 | $self->{session}, | |
322 | canonicalize_url($full_url), | |
323 | $pool | |
324 | ); | |
b4943dc9 | 325 | $self->url($full_url); |
9f7ad147 JN |
326 | $reparented = 1; |
327 | } | |
328 | ||
329 | $ra ||= $self; | |
9c27a57b | 330 | $url_b = canonicalize_url($url_b); |
9f7ad147 JN |
331 | my $reporter = $ra->do_switch($rev_b, '', 1, $url_b, $editor, $pool); |
332 | my @lock = (::compare_svn_version('1.2.0') >= 0) ? (undef) : (); | |
333 | $reporter->set_path('', $rev_a, 0, @lock, $pool); | |
334 | $reporter->finish_report($pool); | |
335 | ||
336 | if ($reparented) { | |
337 | SVN::_Ra::svn_ra_reparent($self->{session}, $old_url, $pool); | |
b4943dc9 | 338 | $self->url($old_url); |
9f7ad147 JN |
339 | } |
340 | ||
341 | $pool->clear; | |
342 | $editor->{git_commit_ok}; | |
343 | } | |
344 | ||
345 | sub longest_common_path { | |
346 | my ($gsv, $globs) = @_; | |
347 | my %common; | |
348 | my $common_max = scalar @$gsv; | |
349 | ||
350 | foreach my $gs (@$gsv) { | |
6a8d999e | 351 | my @tmp = split m#/#, $gs->path; |
9f7ad147 JN |
352 | my $p = ''; |
353 | foreach (@tmp) { | |
354 | $p .= length($p) ? "/$_" : $_; | |
355 | $common{$p} ||= 0; | |
356 | $common{$p}++; | |
357 | } | |
358 | } | |
359 | $globs ||= []; | |
360 | $common_max += scalar @$globs; | |
361 | foreach my $glob (@$globs) { | |
362 | my @tmp = split m#/#, $glob->{path}->{left}; | |
363 | my $p = ''; | |
364 | foreach (@tmp) { | |
365 | $p .= length($p) ? "/$_" : $_; | |
366 | $common{$p} ||= 0; | |
367 | $common{$p}++; | |
368 | } | |
369 | } | |
370 | ||
371 | my $longest_path = ''; | |
372 | foreach (sort {length $b <=> length $a} keys %common) { | |
373 | if ($common{$_} == $common_max) { | |
374 | $longest_path = $_; | |
375 | last; | |
376 | } | |
377 | } | |
378 | $longest_path; | |
379 | } | |
380 | ||
381 | sub gs_fetch_loop_common { | |
382 | my ($self, $base, $head, $gsv, $globs) = @_; | |
383 | return if ($base > $head); | |
dfa72fdb EW |
384 | my $gpool = SVN::Pool->new_default; |
385 | my $ra_url = $self->url; | |
386 | my $reload_ra = sub { | |
387 | $_[0] = undef; | |
388 | $self = undef; | |
389 | $RA = undef; | |
390 | $gpool->clear; | |
391 | $self = Git::SVN::Ra->new($ra_url); | |
392 | $ra_invalid = undef; | |
393 | }; | |
9f7ad147 JN |
394 | my $inc = $_log_window_size; |
395 | my ($min, $max) = ($base, $head < $base + $inc ? $head : $base + $inc); | |
396 | my $longest_path = longest_common_path($gsv, $globs); | |
9f7ad147 JN |
397 | my $find_trailing_edge; |
398 | while (1) { | |
399 | my %revs; | |
400 | my $err; | |
401 | my $err_handler = $SVN::Error::handler; | |
402 | $SVN::Error::handler = sub { | |
403 | ($err) = @_; | |
404 | skip_unknown_revs($err); | |
405 | }; | |
406 | sub _cb { | |
407 | my ($paths, $r, $author, $date, $log) = @_; | |
408 | [ $paths, | |
409 | { author => $author, date => $date, log => $log } ]; | |
410 | } | |
411 | $self->get_log([$longest_path], $min, $max, 0, 1, 1, | |
412 | sub { $revs{$_[1]} = _cb(@_) }); | |
413 | if ($err) { | |
414 | print "Checked through r$max\r"; | |
415 | } else { | |
416 | $find_trailing_edge = 1; | |
417 | } | |
418 | if ($err and $find_trailing_edge) { | |
419 | print STDERR "Path '$longest_path' ", | |
420 | "was probably deleted:\n", | |
421 | $err->expanded_message, | |
422 | "\nWill attempt to follow ", | |
423 | "revisions r$min .. r$max ", | |
424 | "committed before the deletion\n"; | |
425 | my $hi = $max; | |
426 | while (--$hi >= $min) { | |
427 | my $ok; | |
428 | $self->get_log([$longest_path], $min, $hi, | |
429 | 0, 1, 1, sub { | |
430 | $ok = $_[1]; | |
431 | $revs{$_[1]} = _cb(@_) }); | |
432 | if ($ok) { | |
433 | print STDERR "r$min .. r$ok OK\n"; | |
434 | last; | |
435 | } | |
436 | } | |
437 | $find_trailing_edge = 0; | |
438 | } | |
439 | $SVN::Error::handler = $err_handler; | |
440 | ||
f3045919 | 441 | my %exists = map { $_->path => $_ } @$gsv; |
9f7ad147 | 442 | foreach my $r (sort {$a <=> $b} keys %revs) { |
aee7d04c | 443 | my ($paths, $logged) = @{delete $revs{$r}}; |
9f7ad147 JN |
444 | |
445 | foreach my $gs ($self->match_globs(\%exists, $paths, | |
446 | $globs, $r)) { | |
447 | if ($gs->rev_map_max >= $r) { | |
448 | next; | |
449 | } | |
450 | next unless $gs->match_paths($paths, $r); | |
451 | $gs->{logged_rev_props} = $logged; | |
452 | if (my $last_commit = $gs->last_commit) { | |
453 | $gs->assert_index_clean($last_commit); | |
454 | } | |
455 | my $log_entry = $gs->do_fetch($paths, $r); | |
456 | if ($log_entry) { | |
457 | $gs->do_git_commit($log_entry); | |
458 | } | |
459 | $Git::SVN::INDEX_FILES{$gs->{index}} = 1; | |
460 | } | |
461 | foreach my $g (@$globs) { | |
462 | my $k = "svn-remote.$g->{remote}." . | |
463 | "$g->{t}-maxRev"; | |
464 | Git::SVN::tmp_config($k, $r); | |
465 | } | |
dfa72fdb | 466 | $reload_ra->() if $ra_invalid; |
9f7ad147 JN |
467 | } |
468 | # pre-fill the .rev_db since it'll eventually get filled in | |
469 | # with '0' x40 if something new gets committed | |
470 | foreach my $gs (@$gsv) { | |
471 | next if $gs->rev_map_max >= $max; | |
472 | next if defined $gs->rev_map_get($max); | |
473 | $gs->rev_map_set($max, 0 x40); | |
474 | } | |
475 | foreach my $g (@$globs) { | |
476 | my $k = "svn-remote.$g->{remote}.$g->{t}-maxRev"; | |
477 | Git::SVN::tmp_config($k, $max); | |
478 | } | |
479 | last if $max >= $head; | |
480 | $min = $max + 1; | |
481 | $max += $inc; | |
482 | $max = $head if ($max > $head); | |
dfa72fdb EW |
483 | |
484 | $reload_ra->(); | |
9f7ad147 JN |
485 | } |
486 | Git::SVN::gc(); | |
487 | } | |
488 | ||
489 | sub get_dir_globbed { | |
490 | my ($self, $left, $depth, $r) = @_; | |
491 | ||
492 | my @x = eval { $self->get_dir($left, $r) }; | |
493 | return unless scalar @x == 3; | |
494 | my $dirents = $x[0]; | |
495 | my @finalents; | |
496 | foreach my $de (keys %$dirents) { | |
497 | next if $dirents->{$de}->{kind} != $SVN::Node::dir; | |
498 | if ($depth > 1) { | |
499 | my @args = ("$left/$de", $depth - 1, $r); | |
500 | foreach my $dir ($self->get_dir_globbed(@args)) { | |
501 | push @finalents, "$de/$dir"; | |
502 | } | |
503 | } else { | |
504 | push @finalents, $de; | |
505 | } | |
506 | } | |
507 | @finalents; | |
508 | } | |
509 | ||
510 | # return value: 0 -- don't ignore, 1 -- ignore | |
511 | sub is_ref_ignored { | |
512 | my ($g, $p) = @_; | |
513 | my $refname = $g->{ref}->full_path($p); | |
514 | return 1 if defined($g->{ignore_refs_regex}) && | |
515 | $refname =~ m!$g->{ignore_refs_regex}!; | |
516 | return 0 unless defined($_ignore_refs_regex); | |
517 | return 1 if $refname =~ m!$_ignore_refs_regex!o; | |
518 | return 0; | |
519 | } | |
520 | ||
521 | sub match_globs { | |
522 | my ($self, $exists, $paths, $globs, $r) = @_; | |
523 | ||
524 | sub get_dir_check { | |
525 | my ($self, $exists, $g, $r) = @_; | |
526 | ||
527 | my @dirs = $self->get_dir_globbed($g->{path}->{left}, | |
528 | $g->{path}->{depth}, | |
529 | $r); | |
530 | ||
531 | foreach my $de (@dirs) { | |
532 | my $p = $g->{path}->full_path($de); | |
533 | next if $exists->{$p}; | |
534 | next if (length $g->{path}->{right} && | |
535 | ($self->check_path($p, $r) != | |
536 | $SVN::Node::dir)); | |
537 | next unless $p =~ /$g->{path}->{regex}/; | |
b4943dc9 | 538 | $exists->{$p} = Git::SVN->init($self->url, $p, undef, |
9f7ad147 JN |
539 | $g->{ref}->full_path($de), 1); |
540 | } | |
541 | } | |
542 | foreach my $g (@$globs) { | |
543 | if (my $path = $paths->{"/$g->{path}->{left}"}) { | |
544 | if ($path->{action} =~ /^[AR]$/) { | |
545 | get_dir_check($self, $exists, $g, $r); | |
546 | } | |
547 | } | |
548 | foreach (keys %$paths) { | |
549 | if (/$g->{path}->{left_regex}/ && | |
550 | !/$g->{path}->{regex}/) { | |
551 | next if $paths->{$_}->{action} !~ /^[AR]$/; | |
552 | get_dir_check($self, $exists, $g, $r); | |
553 | } | |
554 | next unless /$g->{path}->{regex}/; | |
555 | my $p = $1; | |
556 | my $pathname = $g->{path}->full_path($p); | |
557 | next if is_ref_ignored($g, $p); | |
558 | next if $exists->{$pathname}; | |
559 | next if ($self->check_path($pathname, $r) != | |
560 | $SVN::Node::dir); | |
561 | $exists->{$pathname} = Git::SVN->init( | |
b4943dc9 | 562 | $self->url, $pathname, undef, |
9f7ad147 JN |
563 | $g->{ref}->full_path($p), 1); |
564 | } | |
565 | my $c = ''; | |
566 | foreach (split m#/#, $g->{path}->{left}) { | |
567 | $c .= "/$_"; | |
568 | next unless ($paths->{$c} && | |
569 | ($paths->{$c}->{action} =~ /^[AR]$/)); | |
570 | get_dir_check($self, $exists, $g, $r); | |
571 | } | |
572 | } | |
573 | values %$exists; | |
574 | } | |
575 | ||
576 | sub minimize_url { | |
577 | my ($self) = @_; | |
b4943dc9 | 578 | return $self->url if ($self->url eq $self->{repos_root}); |
9f7ad147 JN |
579 | my $url = $self->{repos_root}; |
580 | my @components = split(m!/!, $self->{svn_path}); | |
581 | my $c = ''; | |
582 | do { | |
d2fd119c | 583 | $url = add_path_to_url($url, $c); |
9f7ad147 JN |
584 | eval { |
585 | my $ra = (ref $self)->new($url); | |
586 | my $latest = $ra->get_latest_revnum; | |
587 | $ra->get_log("", $latest, 0, 1, 0, 1, sub {}); | |
588 | }; | |
589 | } while ($@ && ($c = shift @components)); | |
9c27a57b MS |
590 | |
591 | return canonicalize_url($url); | |
9f7ad147 JN |
592 | } |
593 | ||
594 | sub can_do_switch { | |
595 | my $self = shift; | |
596 | unless (defined $can_do_switch) { | |
597 | my $pool = SVN::Pool->new; | |
598 | my $rep = eval { | |
b4943dc9 | 599 | $self->do_switch(1, '', 0, $self->url, |
9f7ad147 JN |
600 | SVN::Delta::Editor->new, $pool); |
601 | }; | |
602 | if ($@) { | |
603 | $can_do_switch = 0; | |
604 | } else { | |
605 | $rep->abort_report($pool); | |
606 | $can_do_switch = 1; | |
607 | } | |
608 | $pool->clear; | |
609 | } | |
610 | $can_do_switch; | |
611 | } | |
612 | ||
613 | sub skip_unknown_revs { | |
614 | my ($err) = @_; | |
615 | my $errno = $err->apr_err(); | |
616 | # Maybe the branch we're tracking didn't | |
617 | # exist when the repo started, so it's | |
618 | # not an error if it doesn't, just continue | |
619 | # | |
620 | # Wonderfully consistent library, eh? | |
621 | # 160013 - svn:// and file:// | |
622 | # 175002 - http(s):// | |
623 | # 175007 - http(s):// (this repo required authorization, too...) | |
624 | # More codes may be discovered later... | |
625 | if ($errno == 175007 || $errno == 175002 || $errno == 160013) { | |
626 | my $err_key = $err->expanded_message; | |
627 | # revision numbers change every time, filter them out | |
628 | $err_key =~ s/\d+/\0/g; | |
629 | $err_key = "$errno\0$err_key"; | |
630 | unless ($ignored_err{$err_key}) { | |
631 | warn "W: Ignoring error from SVN, path probably ", | |
632 | "does not exist: ($errno): ", | |
633 | $err->expanded_message,"\n"; | |
634 | warn "W: Do not be alarmed at the above message ", | |
635 | "git-svn is just searching aggressively for ", | |
636 | "old history.\n", | |
637 | "This may take a while on large repositories\n"; | |
638 | $ignored_err{$err_key} = 1; | |
639 | } | |
640 | return; | |
641 | } | |
642 | die "Error from SVN, ($errno): ", $err->expanded_message,"\n"; | |
643 | } | |
644 | ||
645 | 1; | |
646 | __END__ | |
647 | ||
d301f181 JN |
648 | =head1 NAME |
649 | ||
9f7ad147 JN |
650 | Git::SVN::Ra - Subversion remote access functions for git-svn |
651 | ||
652 | =head1 SYNOPSIS | |
653 | ||
654 | use Git::SVN::Ra; | |
655 | ||
656 | my $ra = Git::SVN::Ra->new($branchurl); | |
657 | my ($dirents, $fetched_revnum, $props) = | |
658 | $ra->get_dir('.', $SVN::Core::INVALID_REVNUM); | |
659 | ||
660 | =head1 DESCRIPTION | |
661 | ||
662 | This is a wrapper around the L<SVN::Ra> module for use by B<git-svn>. | |
663 | It fills in some default parameters (such as the authentication | |
664 | scheme), smooths over incompatibilities between libsvn versions, adds | |
665 | caching, and implements some functions specific to B<git-svn>. | |
666 | ||
667 | Do not use it unless you are developing git-svn. The interface will | |
668 | change as git-svn evolves. | |
669 | ||
670 | =head1 DEPENDENCIES | |
671 | ||
672 | Subversion perl bindings, | |
673 | L<Git::SVN>. | |
674 | ||
675 | C<Git::SVN::Ra> has not been tested using callers other than | |
676 | B<git-svn> itself. | |
677 | ||
678 | =head1 SEE ALSO | |
679 | ||
680 | L<SVN::Ra>. | |
681 | ||
682 | =head1 INCOMPATIBILITIES | |
683 | ||
684 | None reported. | |
685 | ||
686 | =head1 BUGS | |
687 | ||
688 | None. |