[Bps-public-commit] r17386 - Prophet/trunk/lib/Prophet/CLI/Command

jesse at bestpractical.com jesse at bestpractical.com
Sat Dec 27 16:25:23 EST 2008


Author: jesse
Date: Sat Dec 27 16:25:23 2008
New Revision: 17386

Modified:
   Prophet/trunk/lib/Prophet/CLI/Command/Merge.pm
   Prophet/trunk/lib/Prophet/CLI/Command/Pull.pm

Log:
* starting to track the uuids of replicas we sync from

Modified: Prophet/trunk/lib/Prophet/CLI/Command/Merge.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Merge.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Merge.pm	Sat Dec 27 16:25:23 2008
@@ -2,29 +2,33 @@
 use Moose;
 extends 'Prophet::CLI::Command';
 
+has source => ( isa => 'Prophet::Replica', is => 'rw');
+has target => ( isa => 'Prophet::Replica', is => 'rw');
+
+
 sub run {
     my $self = shift;
 
-    my $source = Prophet::Replica->new(
+    $self->source( Prophet::Replica->new(
         url       => $self->arg('from'),
         app_handle => $self->app_handle,
-    );
+    ));
 
-    my $target = Prophet::Replica->new(
+    $self->target( Prophet::Replica->new(
         url       => $self->arg('to'),
         app_handle => $self->app_handle,
-    );
+    ));
 
 
     
-    return  unless $self->validate_merge_replicas($source => $target);
+    return  unless $self->validate_merge_replicas($self->source => $self->target);
 
-    $target->import_resolutions_from_remote_replica(
-        from  => $source,
+    $self->target->import_resolutions_from_remote_replica(
+        from  => $self->source,
         force => $self->has_arg('force'),
     );
 
-    my $changesets = $self->_do_merge( $source, $target );
+    my $changesets = $self->_do_merge();
 
     $self->print_report($changesets);
 }
@@ -43,7 +47,7 @@
     }
 }
 
-=head2 _do_merge $source $target
+=head2 _do_merge
 
 Merges changesets from the source replica into the target replica.
 
@@ -61,10 +65,10 @@
 =cut
 
 sub _do_merge {
-    my ( $self, $source, $target ) = @_;
+    my ( $self) = @_;
 
     my %import_args = (
-        from  => $source,
+        from  => $self->source,
         resdb => $self->resdb_handle,
         force => $self->has_arg('force'),
     );
@@ -76,8 +80,8 @@
 
     my $changesets = 0;
 
-    my $source_latest = $source->latest_sequence_no() || 0;
-    my $source_last_seen = $target->last_changeset_from_source($source->uuid) || 0;
+    my $source_latest = $self->source->latest_sequence_no() || 0;
+    my $source_last_seen = $self->target->last_changeset_from_source($self->source->uuid) || 0;
 
     if( $self->has_arg('verbose') ) {
         print "Integrating changes from ".$source_last_seen . " to ". $source_latest."\n";
@@ -104,11 +108,10 @@
 
     }
 
-    $target->import_changesets( %import_args);
+    $self->target->import_changesets( %import_args);
     return $changesets;
 }
 
-
 sub validate_merge_replicas {
     my $self = shift;
     my $source = shift;

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	Sat Dec 27 16:25:23 2008
@@ -2,7 +2,7 @@
 use Moose;
 extends 'Prophet::CLI::Command::Merge';
 
-override run => sub {
+sub run {
     my $self = shift;
     my @from;
 
@@ -29,27 +29,35 @@
         print "Pulling from $from\n";
         #if ( $self->has_arg('all') || $self->has_arg('local') );
         $self->set_arg( from => $from );
-        super();
+        $self->SUPER::run();
+        if ($from eq $explicit_from) {
+            $self->record_pull_from_source($explicit_from, $self->source->uuid);
+        }
         print "\n";
     }
 
-    $self->record_pull_from_source($explicit_from) if ($explicit_from);
-};
+}
 
 sub record_pull_from_source {
     my $self = shift;
     my $source = shift;
+    my $from_uuid = shift;
     my $previous_sources = $self->app_handle->config->sources;
-    my %sources_by_url = map { $previous_sources->{$_} => $_ }
-        %$previous_sources;
+    my %sources_by_url = map {
+            my $meta = $_;
+            my ($url,$uuid);
+            ($url, $uuid ) = split(qr/ \| /,$meta,2);
+         ($previous_sources->{$meta} => $url
+         
+         )
+     } keys %$previous_sources;
     if ( !exists $sources_by_url{$source}) {
-        $previous_sources->{$source} = $source;
+        $previous_sources->{$source} = $source ." | ".$from_uuid;
         $self->app_handle->config->set(_sources => $previous_sources );
         $self->app_handle->config->save;
     }
 }
 
-
 sub validate_args {
     my $self = shift;
     die "Please specify a --from, --local or --all.\n"



More information about the Bps-public-commit mailing list