[Bps-public-commit] r14551 - in Prophet/trunk: lib/Prophet/CLI/Command t

simonw at bestpractical.com simonw at bestpractical.com
Sun Jul 27 17:27:32 EDT 2008


Author: simonw
Date: Sun Jul 27 17:27:32 2008
New Revision: 14551

Modified:
   Prophet/trunk/lib/Prophet/CLI/Command/Pull.pm
   Prophet/trunk/lib/Prophet/Replica.pm
   Prophet/trunk/t/publish-pull.t

Log:
All 'pull --all' to automatically pull from all upstream repositories that you've 
previously pulled from


Modified: Prophet/trunk/lib/Prophet/CLI/Command/Pull.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Pull.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Pull.pm	Sun Jul 27 17:27:32 2008
@@ -3,20 +3,51 @@
 extends 'Prophet::CLI::Command::Merge';
 
 override run => sub {
-    my $self = shift;
+    my $self  = shift;
 
-    die "Please specify a --from.\n" if !$self->has_arg('from');
+    my @from;
+    my %replicas = $self->_read_cached_upstream_replicas;
+    if ($self->has_arg('from')) { 
+        my $from = $self->arg('from');
+        push @from, $from;
+        unless (exists $replicas{$from}) {
+            $replicas{$from} = 1;
+            $self->_write_cached_upstream_replicas(%replicas);
+        }
+    }
+
+    if ($self->has_arg('all')) {
+        push @from, keys %replicas;
+    }
 
-    $self->set_arg(to => $self->cli->app_handle->default_replica_type.":file://"
-.$self->cli->app_handle->handle->fs_root);
+    die "Please specify a --from.\n" unless @from;
 
+    
+    $self->set_arg(to => $self->cli->app_handle->default_replica_type.":file://".$self->cli->app_handle->handle->fs_root);
     $self->set_arg(db_uuid => $self->app_handle->handle->db_uuid);
 
-    super();
+    for my $from (@from) {
+            print "Pulling from $from\n" if $self->has_arg('all');
+            $self->set_arg(from => $from);
+            super();
+    }
 };
 
+sub _read_cached_upstream_replicas {
+    my $self = shift;
+    return map { $_ => 1 } $self->cli->app_handle->resdb_handle->_read_cached_upstream_replicas;
+}
+
+sub _write_cached_upstream_replicas {
+    my $self  = shift;
+    my %repos = @_;
+    return $self->cli->app_handle->resdb_handle->_write_cached_upstream_replicas(keys %repos);
+}
+
 __PACKAGE__->meta->make_immutable;
 no Moose;
 
+
+
 1;
 

Modified: Prophet/trunk/lib/Prophet/Replica.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Replica.pm	(original)
+++ Prophet/trunk/lib/Prophet/Replica.pm	Sun Jul 27 17:27:32 2008
@@ -656,28 +656,59 @@
     return ++$map->{'_meta'}{'maximum_luid'};
 }
 
-sub _guid2luid_file { "local-id-cache" }
-
-sub _read_guid2luid_mappings {
-    my $self = shift;
-    my $json = $self->read_metadata_file(path => $self->_guid2luid_file)
-            || '{}';
-
+sub _do_metadata_read {
+    my $self    = shift;
+    my $path    = shift;
+    my $default = shift;
+    my $json = $self->read_metadata_file( path => $path ) || $default;
     require JSON;
     return JSON::from_json($json, { utf8 => 1 });
+
 }
 
-sub _write_guid2luid_mappings {
-    my $self = shift;
-    my $map  = shift;
+sub _do_metadata_write {
+    my $self  = shift;
+    my $path  = shift;
+    my $value = shift;
 
     require JSON;
-    my $content = JSON::to_json($map, { canonical => 1, pretty => 0, utf8 => 1 });
+    my $content = JSON::to_json($value, { canonical => 1, pretty => 0, utf8 => 1 });
 
     $self->write_metadata_file(
-        path    => $self->_guid2luid_file,
+        path    => $path,
         content => $content,
     );
+
+}
+
+# NOTE: to be honest I'm not sure this is the correct way to do this
+# or if there should be a more generic metadata store somewhere
+sub _upstream_replica_cache_file { "upstream-replica-cache" }
+
+sub _read_cached_upstream_replicas {
+    my $self = shift;
+    return @{ $self->_do_metadata_read( $self->_upstream_replica_cache_file, '[]' ) || [] };
+}
+
+sub _write_cached_upstream_replicas {
+    my $self     = shift;
+    my @replicas = @_;
+    return $self->_do_metadata_write( $self->_upstream_replica_cache_file, [@replicas] );
+
+}
+
+sub _guid2luid_file { "local-id-cache" }
+
+sub _read_guid2luid_mappings {
+    my $self = shift;
+    return $self->_do_metadata_read( $self->_guid2luid_file, '{}' );
+}
+
+sub _write_guid2luid_mappings {
+    my $self = shift;
+    my $map  = shift;
+
+    return $self->_do_metadata_write( $self->_guid2luid_file, $map );
 }
 
 sub _read_luid2guid_mappings {

Modified: Prophet/trunk/t/publish-pull.t
==============================================================================
--- Prophet/trunk/t/publish-pull.t	(original)
+++ Prophet/trunk/t/publish-pull.t	Sun Jul 27 17:27:32 2008
@@ -21,6 +21,8 @@
 as_bob {
     run_ok( 'prophet', ['pull', '--from', "file:$path", '--force'] );
     run_output_matches( 'prophet', [qw(search --type Bug --regex .)], [qr/new/], " Found our record" );
+    run_ok( 'prophet', ['pull', '--all', '--force'] );
+    run_output_matches( 'prophet', [qw(search --type Bug --regex .)], [qr/new/], " Found our record" );
 };
 
 # see if uuid intuition works



More information about the Bps-public-commit mailing list