[svk-commit] r2680 - in branches/mirror-boostrap/lib/SVK: Command
nobody at bestpractical.com
nobody at bestpractical.com
Tue Jan 15 12:17:12 EST 2008
Author: clkao
Date: Tue Jan 15 12:17:12 2008
New Revision: 2680
Modified:
branches/mirror-boostrap/lib/SVK/Command/Mirror.pm
branches/mirror-boostrap/lib/SVK/Mirror.pm
branches/mirror-boostrap/lib/SVK/Notify.pm
Log:
Move progress into SVK::Notify, and enable progress for bootstrap.
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 12:17:12 2008
@@ -150,6 +150,7 @@
package SVK::Command::Mirror::bootstrap;
use base qw(SVK::Command::Mirror);
use SVK::I18N;
+use SVK::Logger;
use constant narg => 2;
@@ -161,56 +162,65 @@
$self->SUPER::run($target,$uri, @options);
($m, $mpath) = $target->is_mirrored;
}
+ # XXX: make sure the mirror is fresh and not synced at all
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;
my $hint;
- if ($self->{bootstrap} eq 'auto') {
+ 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);
+ $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'} ) {
+ $logger->info( loc( "Downloading dump file: %1", $hint ) );
+ $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;
+ # XXX: switch to a default notify object that takes care
+ # of quiet and gui variants.
+ my $progress = SVK::Notify->new->progress(
+ {
+ count => 1024,
+ ETA => 'linear',
}
- }
- $received_size += length $data;
- print {$self->{bootstrap}} $data;
- $next_update = $progress->update($received_size) if
- $received_size >= $next_update;
- },
- ':read_size_hint' => 16384,
- );
- }
+ );
+ $ua->get(
+ $hint,
+ ':content_cb' => sub {
+ my ( $data, $cb_response, $protocol ) = @_;
+
+ if ($progress) {
+ 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 $progress && $received_size >= $next_update;
+ },
+ ':read_size_hint' => 16384,
+ );
+ }
}
die loc("No such dump file: %1.\n", $self->{bootstrap})
unless -f ($self->{bootstrap});
+ $logger->info( loc("Bootstrapping mirror from dump") );
$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 12:17:12 2008
@@ -254,6 +254,8 @@
my $rev = 0;
my $buf;
my $header;
+ my $progress = SVK::Notify->new->progress( { count => 1024, ETA => 'linear' } );
+ $progress->target( $self->_backend->_new_ra->get_latest_revnum ) if $progress;
while ( my $record = $dump->next_record() ) {
if ($record->type eq 'format' || $record->type eq 'uuid') {
$header = $header.$record->as_string;
@@ -275,7 +277,9 @@
if ($rec->get_header('Revision-number')) {
$rev = $rec->get_header('Revision-number');
$prev = $rev if !$prev;
- $rec->set_property('svm:headrev',$self->source_uuid.':'.$rec->get_header('Revision-number')."\n");
+ $rec->set_property('svm:headrev',$self->source_uuid.':'.$rev."\n");
+ $progress->update($rev);
+ $progress->message( loc("Loaded revision %1", $rev) );
}
Modified: branches/mirror-boostrap/lib/SVK/Notify.pm
==============================================================================
--- branches/mirror-boostrap/lib/SVK/Notify.pm (original)
+++ branches/mirror-boostrap/lib/SVK/Notify.pm Tue Jan 15 12:17:12 2008
@@ -209,5 +209,15 @@
$self->flush ($path, 1);
}
+sub progress {
+ my $self = shift;
+ require Term::ProgressBar;
+ return if $self->{quiet};
+ my $progress = Term::ProgressBar->new(@_);
+ $progress->minor(0);
+ $progress->max_update_rate(1);
+ return $progress;
+
+}
1;
More information about the svk-commit
mailing list