git-svn: run get_log() on a sub-directory if possible
This is an optimization that should conserve network bandwidth on certain repositories and configurations. Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Feb 7, 2007 at 11:50 UTC
d2ae14346c71d57c57dc7b1c1f8272c09f51ccf9
1 file changed
+48
-7
git-svn.perl
+48
-7
@@ -2433,21 +2433,62 @@ sub gs_fetch_loop_common {
2433
my ($self, $base, $head, @gs) = @_;
2434
my $inc = 1000;
2435
my ($min, $max) = ($base, $head < $base + $inc ? $head : $base + $inc);
2436
+
2437
+ my %common;
2438
foreach my $gs (@gs) {
2439
if (my $last_commit = $gs->last_commit) {
2440
$gs->assert_index_clean($last_commit);
2441
}
2442
+ my @tmp = split m#/#, $gs->{path};
2443
+ my $p = '';
2444
+ foreach (@tmp) {
2445
+ $p .= length($p) ? "/$_" : $_;
2446
+ $common{$p} ||= 0;
2447
+ $common{$p}++;
2448
+ }
2449
+ }
2450
+ my $longest_path = '';
2451
+ foreach (sort {length $b <=> length $a} keys %common) {
2452
+ if ($common{$_} == @gs) {
2453
+ $longest_path = $_;
2454
+ last;
2455
+ }
2456
}
2457
while (1) {
2458
my %revs;
2459
+ my $err;
2460
my $err_handler = $SVN::Error::handler;
2444
- $SVN::Error::handler = \&skip_unknown_revs;
2445
- $self->get_log([''], $min, $max, 0, 1, 1, sub {
2446
- my ($paths, $r, $author, $date, $log) = @_;
2447
- $revs{$r} = [ dup_changed_paths($paths),
2448
- { author => $author,
2449
- date => $date,
2450
- log => $log } ] });
2461
+ $SVN::Error::handler = sub {
2462
+ ($err) = @_;
2463
+ skip_unknown_revs($err);
2464
+ };
2465
+ sub _cb {
2466
+ my ($paths, $r, $author, $date, $log) = @_;
2467
+ [ dup_changed_paths($paths),
2468
+ { author => $author, date => $date, log => $log } ];
2469
+ }
2470
+ $self->get_log([$longest_path], $min, $max, 0, 1, 1,
2471
+ sub { $revs{$_[1]} = _cb(@_) });
2472
+ if ($err && $max >= $head) {
2473
+ print STDERR "Path '$longest_path' ",
2474
+ "was probably deleted:\n",
2475
+ $err->expanded_message,
2476
+ "\nWill attempt to follow ",
2477
+ "revisions r$min .. r$max ",
2478
+ "committed before the deletion\n";
2479
+ my $hi = $max;
2480
+ while (--$hi >= $min) {
2481
+ my $ok;
2482
+ $self->get_log([$longest_path], $min, $hi,
2483
+ 0, 1, 1, sub {
2484
+ $ok ||= $_[1];
2485
+ $revs{$_[1]} = _cb(@_) });
2486
+ if ($ok) {
2487
+ print STDERR "r$min .. r$ok OK\n";
2488
+ last;
2489
+ }
2490
+ }
2491
+ }
2492
$SVN::Error::handler = $err_handler;
2493
2494
foreach my $r (sort {$a <=> $b} keys %revs) {