[svk-commit] r2679 - in branches/mirror-boostrap: lib/SVK/Command
t/mirror
nobody at bestpractical.com
nobody at bestpractical.com
Tue Jan 15 11:25:47 EST 2008
Author: clkao
Date: Tue Jan 15 11:25:46 2008
New Revision: 2679
Modified:
branches/mirror-boostrap/lib/SVK/Command/Mirror.pm
branches/mirror-boostrap/lib/SVK/Mirror.pm
branches/mirror-boostrap/t/mirror/sync-bootstrap.t
Log:
first cut of dumpfile downloading for mirror --bootstrap,
with progress bar.
Modified: branches/mirror-boostrap/lib/SVK/Command/Mirror.pm
==============================================================================
--- branches/mirror-boostrap/lib/SVK/Command/Mirror.pm (original)
+++ branches/mirror-boostrap/lib/SVK/Command/Mirror.pm Tue Jan 15 11:25:46 2008
@@ -104,17 +104,7 @@
}
);
- if ($self->{bootstrap}) {
- my ($m, $mpath) = $target->is_mirrored;
- die loc("%1 is not a mirrored path.\n", $target->depotpath) if !$m;
- die loc("%1 is inside a mirrored path.\n", $target->depotpath) if $mpath;
-
- $logger->info( loc("Mirror initialized.\n"));
- $m->bootstrap($self->{bootstrap}); # load from dumpfile
- $logger->info( loc("Mirror path '%1' synced from dumpfile.\n", $target->depotpath));
- } else {
- $logger->info( loc("Mirror initialized. Run svk sync %1 to start mirroring.\n", $target->report));
- }
+ $logger->info( loc("Mirror initialized. Run svk sync %1 to start mirroring.\n", $target->report));
return;
}
@@ -167,17 +157,61 @@
my ($self, $target, $uri, @options) = @_;
my ($m, $mpath) = $target->is_mirrored;
- die loc("No such dump file: %1.\n", $self->{bootstrap})
- unless -f ($self->{bootstrap});
-
if (!$m) {
$self->SUPER::run($target,$uri, @options);
- return;
+ ($m, $mpath) = $target->is_mirrored;
}
+
die loc("%1 is not a mirrored path.\n", $target->depotpath) if !$m;
die loc("%1 is inside a mirrored path.\n", $target->depotpath) if $mpath;
- $m->bootstrap($self->{bootstrap}); # load from dumpfile
+ my $hint;
+ if ($self->{bootstrap} eq 'auto') {
+ my $ra = $m->_backend->_new_ra;
+ $ra->reparent($ra->get_repos_root());
+ my %prop = %{ ($ra->get_file('',$ra->get_latest_revnum, undef))[1] };
+ $m->_backend->_ra_finished($ra);
+ if ( $hint = $prop{'svk:dump-url'} ) {
+ $self->{bootstrap} = File::Temp->new;
+ require LWP::UserAgent;
+ my $ua = LWP::UserAgent->new;
+ my ($received_size, $next_update) = (0, 0);
+ my $did_set_target = 0;
+ require Term::ProgressBar;
+ my $progress = Term::ProgressBar->new({
+ count => 1024,
+ ETA => 'linear',
+ });
+ $progress->message( loc("Downloading dump file: %1", $hint));
+ $progress->minor(0); # turns off the floating asterisks.
+ $progress->max_update_rate(1); # only relevant when ETA is used.
+ $ua->get($hint,
+ ':content_cb' => sub {
+ my ($data, $cb_response, $protocol) = @_;
+
+ unless ($did_set_target) {
+ if (my $content_length = $cb_response->content_length) {
+ $progress->target($content_length);
+ $did_set_target = 1;
+ } else {
+ $progress->target($received_size + 2 * length $data);
+ }
+ }
+ $received_size += length $data;
+ print {$self->{bootstrap}} $data;
+ $next_update = $progress->update($received_size) if
+ $received_size >= $next_update;
+ },
+ ':read_size_hint' => 16384,
+ );
+ }
+
+ }
+
+ die loc("No such dump file: %1.\n", $self->{bootstrap})
+ unless -f ($self->{bootstrap});
+
+ $m->bootstrap($self->{bootstrap}, $hint); # load from dumpfile
print loc("Mirror path '%1' synced from dumpfile.\n", $target->depotpath);
return;
}
Modified: branches/mirror-boostrap/lib/SVK/Mirror.pm
==============================================================================
--- branches/mirror-boostrap/lib/SVK/Mirror.pm (original)
+++ branches/mirror-boostrap/lib/SVK/Mirror.pm Tue Jan 15 11:25:46 2008
@@ -235,7 +235,8 @@
=cut
sub bootstrap {
- my ($self, $dumpfile) = @_;
+ my ($self, $dumpfile, $file_hint) = @_;
+ $file_hint ||= $dumpfile;
# XXX make these all 'require' not 'use' and fail optionally
# XXX requires unreleased SVN::Dump that removes binmode() in ::reader
# for compressed streams to work
@@ -243,8 +244,8 @@
use PerlIO::via::Bzip2;
use PerlIO::gzip;
open my $fh, '<', $dumpfile or die $!;
- binmode($fh, ':via(Bzip2)') if $dumpfile =~ m/bz2/i;
- binmode($fh, ':gzip') if $dumpfile =~ m/gz/i;
+ binmode($fh, ':via(Bzip2)') if $file_hint =~ m/bz2/i;
+ binmode($fh, ':gzip') if $file_hint =~ m/gz/i;
my $dump = SVN::Dump->new( { fh => $fh } );
my $prefix = $self->path.'/';
Modified: branches/mirror-boostrap/t/mirror/sync-bootstrap.t
==============================================================================
--- branches/mirror-boostrap/t/mirror/sync-bootstrap.t (original)
+++ branches/mirror-boostrap/t/mirror/sync-bootstrap.t Tue Jan 15 11:25:46 2008
@@ -11,7 +11,6 @@
my $tree = create_basic_tree($xd, '/test/');
my $depot = $xd->find_depot('test');
-diag $depot->repospath;
my $uri = uri($depot->repospath);
More information about the svk-commit
mailing list