@matheusbsbs / matheus-bagliano / commits / d4eff2bda5
Fork 0

git-svn: make (multi-)fetch safer but slower

get_log with explicit paths is the safest way to get revisions that change a particular path we're interested in. Unfortunately that means we still have to run get_log multiple times for each path we're interested in, and even more if a path gets deleted. The first argument of get_log() is an array reference, but we shouldn't use more than one element in that array ref because the non-existence of _one_ of those paths for a particular range would cause an error for all paths in that range, so yes, we need multiple get_log calls to be on the safe side... Signed-off-by: Eric Wong <normalperson@yhbt.net>

Eric Wong committed Jan 30, 2007 at 14:04 UTC d4eff2bda5fc28559e96d62604ecaf78a4ff806b
1 file changed +37 -38
git-svn.perl
+37 -38
@@ -1038,27 +1038,15 @@ sub revisions_eq {
1038 return 1;
1039 }
1040
1041 -sub match_paths {
1042 - my ($self, $paths) = @_;
1043 - return 1 if $paths->{'/'};
1044 - $self->{path_regex} ||= qr/^\/\Q$self->{path}\E\/?/;
1045 - grep /$self->{path_regex}/, keys %$paths and return 1;
1046 - my $c = '';
1047 - foreach (split m#/#, $self->rel_path) {
1048 - $c .= "/$_";
1049 - return 1 if $paths->{$c};
1050 - }
1051 - return 0;
1052 -}
1053 -
1041 sub find_parent_branch {
1042 my ($self, $paths, $rev) = @_;
1043 return undef unless $_follow_parent;
1044 unless (defined $paths) {
1045 my $err_handler = $SVN::Error::handler;
1046 $SVN::Error::handler = \&Git::SVN::Ra::skip_unknown_revs;
1060 - $self->ra->get_log([$self->{path}], $rev, $rev, 0, 1, 1,
1061 - sub { $paths = dup_changed_paths($_[0]) });
1047 + $self->ra->get_log([$self->{path}], $rev, $rev, 0, 1, 1, sub {
1048 + $paths =
1049 + Git::SVN::Ra::dup_changed_paths($_[0]) });
1050 $SVN::Error::handler = $err_handler;
1051 }
1052 return undef unless defined $paths;
@@ -1134,7 +1122,6 @@ sub find_parent_branch {
1122 or die "SVN connection failed somewhere...\n";
1123 }
1124 print STDERR "Successfully followed parent\n";
1137 - $ed->{new_fetch} = 1;
1125 return $self->make_log_entry($rev, [$parent], $ed);
1126 }
1127 not_found:
@@ -1170,7 +1157,6 @@ sub do_fetch {
1157 return $log_entry;
1158 }
1159 $ed = SVN::Git::Fetcher->new($self);
1173 - $ed->{new_fetch} = 1;
1160 }
1161 unless ($self->ra->gs_do_update($last_rev, $rev, $self, $ed)) {
1162 die "SVN connection failed somewhere...\n";
@@ -1243,8 +1229,6 @@ sub make_log_entry {
1229 my ($self, $rev, $parents, $ed) = @_;
1230 my $untracked = $self->get_untracked($ed);
1231
1246 - return undef if (! $ed->{new_fetch} && ! $ed->{nr} && ! @$untracked);
1247 -
1232 open my $un, '>>', "$self->{dir}/unhandled.log" or croak $!;
1233 print $un "r$rev\n" or croak $!;
1234 print $un $_, "\n" foreach @$untracked;
@@ -2314,38 +2298,53 @@ sub gs_fetch_loop_common {
2298 my ($self, $base, $head, @gs) = @_;
2299 my $inc = 1000;
2300 my ($min, $max) = ($base, $head < $base + $inc ? $head : $base + $inc);
2317 - my @paths = @gs == 1 ? ($gs[0]->{path}) : ('');
2301 foreach my $gs (@gs) {
2302 if (my $last_commit = $gs->last_commit) {
2303 $gs->assert_index_clean($last_commit);
2304 }
2305 }
2306 while (1) {
2324 - my @revs;
2307 + my %revs;
2308 my $err;
2309 my $err_handler = $SVN::Error::handler;
2310 $SVN::Error::handler = sub {
2311 ($err) = @_;
2312 skip_unknown_revs($err);
2313 };
2331 - $self->get_log(\@paths, $min, $max, 0, 1, 1,
2332 - sub { push @revs, [ dup_changed_paths($_[0]), $_[1] ]; });
2333 - $SVN::Error::handler = $err_handler;
2334 -
2335 - if (! @revs && $err && $max >= $head) {
2336 - print STDERR "Branch probably deleted:\n ",
2337 - $err->expanded_message,
2338 - "\nWill attempt to follow revisions ",
2339 - "r$min .. r$max ",
2340 - "committed before the deletion\n";
2341 - @revs = map { [ undef, $_ ] } ($min .. $max);
2342 - }
2343 - foreach (@revs) {
2344 - my ($paths, $r) = @$_;
2345 - foreach my $gs (@gs) {
2346 - if ($paths) {
2347 - $gs->match_paths($paths) or next;
2314 + foreach my $gs (@gs) {
2315 + $self->get_log([$gs->{path}], $min, $max, 0, 1, 1, sub
2316 + { my ($paths, $rev) = @_;
2317 + push @{$revs{$rev}},
2318 + [ $gs,
2319 + dup_changed_paths($paths) ] });
2320 +
2321 + next unless ($err && $max >= $head);
2322 +
2323 + print STDERR "Path '$gs->{path}' ",
2324 + "was probably deleted:\n",
2325 + $err->expanded_message,
2326 + "\nWill attempt to follow ",
2327 + "revisions r$min .. r$max ",
2328 + "committed before the deletion\n";
2329 + my $hi = $max;
2330 + while (--$hi >= $min) {
2331 + my $ok;
2332 + $self->get_log([$gs->{path}], $min, $hi,
2333 + 0, 1, 1, sub {
2334 + my ($paths, $rev) = @_;
2335 + $ok = $rev;
2336 + push @{$revs{$rev}}, [ $gs,
2337 + dup_changed_paths($_[0])]});
2338 + if ($ok) {
2339 + print STDERR "r$min .. r$ok OK\n";
2340 + last;
2341 }
2342 + }
2343 + }
2344 + $SVN::Error::handler = $err_handler;
2345 + foreach my $r (sort {$a <=> $b} keys %revs) {
2346 + foreach (@{$revs{$r}}) {
2347 + my ($gs, $paths) = @$_;
2348 my $lr = $gs->last_rev;
2349 next if defined $lr && $lr >= $r;
2350 next if defined $gs->rev_db_get($r);