[Bps-public-commit] Prophet branch, master, updated. 0.743-47-g98529f5

Christine Spang spang at bestpractical.com
Wed Mar 2 22:18:48 EST 2011


The branch, master has been updated
       via  98529f593f35009bf93130d0926836da56836669 (commit)
       via  b641cd385ed4f56f9257a0ad6677ac84ef09cf82 (commit)
       via  95c3e7b975168c2c017fe152a42a77830f2114ea (commit)
       via  fe5b0a42a008167337bb61d4cf9def7621bd5182 (commit)
       via  6c4ccb156b1248d786dd6cb1531cc187d1c320be (commit)
       via  59c776546d3094c99f8a3c2c8b13f17858f3511a (commit)
       via  598a3e730d2c8b73bdc6704fd51b0bb9e9deacef (commit)
       via  c717a701bdd49384d292db8f2fc895d56e9aa2ef (commit)
      from  e270f82ddf874b5c7e9459b1012383749febbaf0 (commit)

Summary of changes:
 lib/Prophet/CLI/CollectionCommand.pm   |    2 +-
 lib/Prophet/CLI/Command/Merge.pm       |    8 +-
 lib/Prophet/CLI/Command/Search.pm      |   25 +++++-
 lib/Prophet/CLI/MirrorCommand.pm       |    2 +-
 lib/Prophet/CLI/Parameters.pm          |    2 +-
 lib/Prophet/CLI/ProgressBar.pm         |    3 +-
 lib/Prophet/CLI/PublishCommand.pm      |    2 +-
 lib/Prophet/CLI/RecordCommand.pm       |    2 +-
 lib/Prophet/CLI/TextEditorCommand.pm   |    2 +-
 lib/Prophet/FilesystemReplica.pm       |    1 +
 lib/Prophet/ForeignReplica.pm          |   79 ++++++++-----------
 lib/Prophet/Meta/Types.pm              |    3 +
 lib/Prophet/Replica.pm                 |  136 +++++++++++++++++++++-----------
 lib/Prophet/Replica/FS/Backend/File.pm |    2 +
 lib/Prophet/Replica/FS/Backend/LWP.pm  |    2 +
 lib/Prophet/Replica/FS/Backend/SSH.pm  |    5 +
 lib/Prophet/Replica/file.pm            |    1 +
 lib/Prophet/Replica/prophet.pm         |   10 ++-
 lib/Prophet/Replica/prophet_cache.pm   |    2 +
 lib/Prophet/Server.pm                  |    3 +
 lib/Prophet/Server/Dispatcher.pm       |    1 +
 lib/Prophet/Web/Menu.pm                |    4 +
 22 files changed, 185 insertions(+), 112 deletions(-)

- Log -----------------------------------------------------------------
commit c717a701bdd49384d292db8f2fc895d56e9aa2ef
Author: Christine Spang <christine at debian.org>
Date:   Mon Feb 21 13:05:06 2011 -0500

    allow sort_by_prop to sort undef items either first or last

diff --git a/lib/Prophet/CLI/Command/Search.pm b/lib/Prophet/CLI/Command/Search.pm
index b8b39c1..92601c3 100644
--- a/lib/Prophet/CLI/Command/Search.pm
+++ b/lib/Prophet/CLI/Command/Search.pm
@@ -151,19 +151,34 @@ sub display_terminal {
 
 }
 
-=head2 sort_by_prop $prop, $records
+=head2 sort_by_prop $prop, $records, $sort_undef_last
 
-Given a property name and an arrayref to a list of records, returns a list of the records
-sorted by their C<created> property, in ascending order.
+Given a property name and an arrayref to a list of records, returns a list of
+the records sorted by their C<created> property, in ascending order.
+
+If $sort_undef_last is true, records which don't have a property defined
+are sorted *after* all other records; otherwise, they are sorted before.
 
 =cut
 
 sub sort_by_prop {
-    my ($self, $prop, $records) = @_;
+    my ($self, $prop, $records, $sort_undef_last) = @_;
 
     no warnings 'uninitialized'; # some records might not have this prop
 
-    return (sort { $a->prop($prop) cmp $b->prop($prop) } @{$records});
+    return (sort {
+        my $prop_a = $a->prop($prop);
+        my $prop_b = $b->prop($prop);
+        if ( $sort_undef_last && !defined($prop_a) ) {
+            return 1;
+        }
+        elsif ( $sort_undef_last && !defined($prop_b) ) {
+            return -1;
+        }
+        else {
+            return $prop_a cmp $prop_b;
+        }
+    } @{$records});
 }
 
 

commit 598a3e730d2c8b73bdc6704fd51b0bb9e9deacef
Author: Christine Spang <christine at debian.org>
Date:   Mon Feb 21 13:05:50 2011 -0500

    use group_set when setting foreign replica username/token in config
    
    Avoids a double-write. Also, we should be writing replica-specific
    config information to the replica config file, not what might be
    a global config file.

diff --git a/lib/Prophet/ForeignReplica.pm b/lib/Prophet/ForeignReplica.pm
index c9381fb..b0110d2 100644
--- a/lib/Prophet/ForeignReplica.pm
+++ b/lib/Prophet/ForeignReplica.pm
@@ -153,21 +153,21 @@ sub prompt_for_login {
     }
     Prophet::CLI->start_pager() if ($was_in_pager);
 
+    # make sure replica is initialized
+    $self->app_handle->handle->initialize;
+
     # store username and secret token in config file
     if ( !$self->app_handle->config->get( key => $replica_username ) ) {
-        print "Setting replica's username in the config file";
-        $self->app_handle->config->set(
+        print "Setting replica's username and token in the config file";
+        $self->app_handle->config->group_set(
+            $self->app_handle->config->replica_config_file,
+         [ {
             key      => $replica_username,
             value    => $args{username},
-            filename => $self->app_handle->config->origins->{
-                'core.config-format-version'},
-        );
-        print "Setting replica's secret_token in the config file";
-        $self->app_handle->config->set(
+         }, {
             key      => $replica_secret_token,
             value    => $secret,
-            filename => $self->app_handle->config->origins->{
-                'core.config-format-version'},
+         } ],
         );
     }
 

commit 59c776546d3094c99f8a3c2c8b13f17858f3511a
Author: Christine Spang <christine at debian.org>
Date:   Mon Feb 21 14:57:17 2011 -0500

    remove trailing whitespace

diff --git a/lib/Prophet/ForeignReplica.pm b/lib/Prophet/ForeignReplica.pm
index b0110d2..10154c3 100644
--- a/lib/Prophet/ForeignReplica.pm
+++ b/lib/Prophet/ForeignReplica.pm
@@ -21,14 +21,14 @@ records and so on.
 sub fetch_local_metadata { my $self = shift;
     my $key = shift;
     $self->app_handle->handle->fetch_local_metadata( $self->uuid . "-".$key )
-    
+
     }
 sub store_local_metadata { my $self = shift;
     my $key = shift;
     my $value = shift;
    $self->app_handle->handle->store_local_metadata( $self->uuid."-".$key => $value);
-    
-    
+
+
     }
 
 
@@ -124,7 +124,7 @@ sub prompt_for_login {
             = $self->app_handle->config->get( key => $replica_username );
         $args{username} = $check_username if $check_username;
     }
-    
+
     my $secret;
 
     my $was_in_pager = Prophet::CLI->in_pager();

commit 6c4ccb156b1248d786dd6cb1531cc187d1c320be
Author: Christine Spang <christine at debian.org>
Date:   Mon Feb 21 15:10:43 2011 -0500

    use correct format for replica username/token lookup, remove saving
    
    Saving is moving to SD so that replicas can only save if the
    credentials are actually verified as being correct.

diff --git a/lib/Prophet/ForeignReplica.pm b/lib/Prophet/ForeignReplica.pm
index 10154c3..e70cf39 100644
--- a/lib/Prophet/ForeignReplica.pm
+++ b/lib/Prophet/ForeignReplica.pm
@@ -116,12 +116,12 @@ sub prompt_for_login {
     );
 
     # check if username is in config
-    my $replica_username     = 'replica.' . $self->{url} . '.username';
-    my $replica_secret_token = 'replica.' . $self->{url} . '.secret_token';
+    my $replica_username_key     = 'replica.' . $self->scheme . ":" . $self->{url} . '.username';
+    my $replica_token_key        = 'replica.' . $self->scheme . ":" . $self->{url} . '.secret_token';
 
     if ( !$args{username} ) {
         my $check_username
-            = $self->app_handle->config->get( key => $replica_username );
+            = $self->app_handle->config->get( key => $replica_username_key );
         $args{username} = $check_username if $check_username;
     }
 
@@ -140,7 +140,7 @@ sub prompt_for_login {
     }
 
     if ( my $check_password
-        = $self->app_handle->config->get( key => $replica_secret_token ) )
+        = $self->app_handle->config->get( key => $replica_token_key ) )
     {
         $secret = $check_password;
     }
@@ -153,24 +153,6 @@ sub prompt_for_login {
     }
     Prophet::CLI->start_pager() if ($was_in_pager);
 
-    # make sure replica is initialized
-    $self->app_handle->handle->initialize;
-
-    # store username and secret token in config file
-    if ( !$self->app_handle->config->get( key => $replica_username ) ) {
-        print "Setting replica's username and token in the config file";
-        $self->app_handle->config->group_set(
-            $self->app_handle->config->replica_config_file,
-         [ {
-            key      => $replica_username,
-            value    => $args{username},
-         }, {
-            key      => $replica_secret_token,
-            value    => $secret,
-         } ],
-        );
-    }
-
     return ( $args{username}, $secret );
 }
 

commit fe5b0a42a008167337bb61d4cf9def7621bd5182
Author: Christine Spang <christine at debian.org>
Date:   Mon Feb 21 17:19:07 2011 -0500

    use consistent moose make_immutable & no Any::Moose

diff --git a/lib/Prophet/CLI/CollectionCommand.pm b/lib/Prophet/CLI/CollectionCommand.pm
index c38e7c5..53c12b7 100644
--- a/lib/Prophet/CLI/CollectionCommand.pm
+++ b/lib/Prophet/CLI/CollectionCommand.pm
@@ -22,7 +22,7 @@ sub get_collection_object {
     return $records;
 }
 
-no Any::Moose;
+no Any::Moose 'Role';
 
 1;
 
diff --git a/lib/Prophet/CLI/MirrorCommand.pm b/lib/Prophet/CLI/MirrorCommand.pm
index 7771cb9..b037355 100644
--- a/lib/Prophet/CLI/MirrorCommand.pm
+++ b/lib/Prophet/CLI/MirrorCommand.pm
@@ -39,7 +39,7 @@ sub sync_cache_from_source {
     );
 }
 
-no Any::Moose;
+no Any::Moose 'Role';
 
 1;
 
diff --git a/lib/Prophet/CLI/Parameters.pm b/lib/Prophet/CLI/Parameters.pm
index 8771cc3..5130356 100644
--- a/lib/Prophet/CLI/Parameters.pm
+++ b/lib/Prophet/CLI/Parameters.pm
@@ -11,7 +11,7 @@ sub context {
     $self->cli->context;
 }
 
-no Any::Moose;
+no Any::Moose 'Role';
 
 1;
 
diff --git a/lib/Prophet/CLI/ProgressBar.pm b/lib/Prophet/CLI/ProgressBar.pm
index f81482a..f8a9de6 100644
--- a/lib/Prophet/CLI/ProgressBar.pm
+++ b/lib/Prophet/CLI/ProgressBar.pm
@@ -19,7 +19,8 @@ sub progress_bar {
        print $bar->report(  $format, ++$bar_count );
     }
 }
-no Any::Moose;
+
+no Any::Moose 'Role';
 
 1;
 
diff --git a/lib/Prophet/CLI/PublishCommand.pm b/lib/Prophet/CLI/PublishCommand.pm
index 46291b2..955c56a 100644
--- a/lib/Prophet/CLI/PublishCommand.pm
+++ b/lib/Prophet/CLI/PublishCommand.pm
@@ -81,7 +81,7 @@ END_DIE_MSG
     }
 }
 
-no Any::Moose;
+no Any::Moose 'Role';
 
 1;
 
diff --git a/lib/Prophet/CLI/RecordCommand.pm b/lib/Prophet/CLI/RecordCommand.pm
index 6783c77..2e805eb 100644
--- a/lib/Prophet/CLI/RecordCommand.pm
+++ b/lib/Prophet/CLI/RecordCommand.pm
@@ -98,7 +98,7 @@ sub _type_to_record_class {
     return 'Prophet::Record';
 }
 
-no Any::Moose;
+no Any::Moose 'Role';
 
 1;
 
diff --git a/lib/Prophet/CLI/TextEditorCommand.pm b/lib/Prophet/CLI/TextEditorCommand.pm
index 3021ef7..dc269e6 100644
--- a/lib/Prophet/CLI/TextEditorCommand.pm
+++ b/lib/Prophet/CLI/TextEditorCommand.pm
@@ -134,5 +134,5 @@ process_template
 
 =cut
 
-no Any::Moose;
+no Any::Moose 'Role';
 1;
diff --git a/lib/Prophet/FilesystemReplica.pm b/lib/Prophet/FilesystemReplica.pm
index f1452a7..31b21aa 100644
--- a/lib/Prophet/FilesystemReplica.pm
+++ b/lib/Prophet/FilesystemReplica.pm
@@ -314,5 +314,6 @@ sub fetch_local_metadata {
 
 }
 
+no Any::Moose;
 
 1;
diff --git a/lib/Prophet/Meta/Types.pm b/lib/Prophet/Meta/Types.pm
index 26dc838..60387e1 100644
--- a/lib/Prophet/Meta/Types.pm
+++ b/lib/Prophet/Meta/Types.pm
@@ -5,6 +5,9 @@ use Any::Moose 'Util::TypeConstraints';
 enum 'Prophet::Type::ChangeType' => qw/add_file add_dir update_file delete/;
 enum 'Prophet::Type::FileOpConflict' => qw/delete_missing_file update_missing_file create_existing_file create_existing_dir/;
 
+__PACKAGE__->meta->make_immutable;
+no Any::Moose;
+
 1;
 
 __END__
diff --git a/lib/Prophet/Replica/FS/Backend/File.pm b/lib/Prophet/Replica/FS/Backend/File.pm
index 31b8a39..0e7509d 100644
--- a/lib/Prophet/Replica/FS/Backend/File.pm
+++ b/lib/Prophet/Replica/FS/Backend/File.pm
@@ -101,4 +101,6 @@ sub can_write { 1;
 
 }
 
+no Any::Moose;
+
 1;
diff --git a/lib/Prophet/Replica/FS/Backend/LWP.pm b/lib/Prophet/Replica/FS/Backend/LWP.pm
index 56d4423..08420b7 100644
--- a/lib/Prophet/Replica/FS/Backend/LWP.pm
+++ b/lib/Prophet/Replica/FS/Backend/LWP.pm
@@ -71,4 +71,6 @@ sub can_write { 0;
 
 }
 
+no Any::Moose;
+
 1;
diff --git a/lib/Prophet/Replica/FS/Backend/SSH.pm b/lib/Prophet/Replica/FS/Backend/SSH.pm
index ed599d3..f7976cb 100644
--- a/lib/Prophet/Replica/FS/Backend/SSH.pm
+++ b/lib/Prophet/Replica/FS/Backend/SSH.pm
@@ -1 +1,6 @@
 package Prophet::FSR::Backend::SSH;
+use Any::Moose;
+
+no Any::Moose;
+
+1;
diff --git a/lib/Prophet/Replica/file.pm b/lib/Prophet/Replica/file.pm
index e38abc0..c39a3be 100644
--- a/lib/Prophet/Replica/file.pm
+++ b/lib/Prophet/Replica/file.pm
@@ -37,4 +37,5 @@ sub new {
     }
 }
 
+no Any::Moose;
 1;
diff --git a/lib/Prophet/Replica/prophet_cache.pm b/lib/Prophet/Replica/prophet_cache.pm
index ef569dc..fd2ffd6 100644
--- a/lib/Prophet/Replica/prophet_cache.pm
+++ b/lib/Prophet/Replica/prophet_cache.pm
@@ -236,4 +236,6 @@ sub mirror_from {
     }
 }
 
+no Any::Moose;
+
 1;
diff --git a/lib/Prophet/Server.pm b/lib/Prophet/Server.pm
index b3f16a0..f7e2789 100644
--- a/lib/Prophet/Server.pm
+++ b/lib/Prophet/Server.pm
@@ -487,4 +487,7 @@ sub make_link_relative {
     return URI::file->new($link)->rel("file://".$self->cgi->path_info());
 }
 
+__PACKAGE__->meta->make_immutable;
+no Any::Moose;
+
 1;
diff --git a/lib/Prophet/Server/Dispatcher.pm b/lib/Prophet/Server/Dispatcher.pm
index 1a0d840..c2c0221 100644
--- a/lib/Prophet/Server/Dispatcher.pm
+++ b/lib/Prophet/Server/Dispatcher.pm
@@ -81,6 +81,7 @@ under { method => 'GET' } => sub {
 
 on qr'^(.*)$' => sub { shift->server->show_template($1) || next_rule; };
 
+__PACKAGE__->meta->make_immutable;
 no Any::Moose;
 
 1;
diff --git a/lib/Prophet/Web/Menu.pm b/lib/Prophet/Web/Menu.pm
index fd41616..6455a4e 100644
--- a/lib/Prophet/Web/Menu.pm
+++ b/lib/Prophet/Web/Menu.pm
@@ -300,4 +300,8 @@ sub as_link {
         return $self->label;
     }
 }
+
+__PACKAGE__->meta->make_immutable;
+no Any::Moose;
+
 1;

commit 95c3e7b975168c2c017fe152a42a77830f2114ea
Author: Christine Spang <christine at debian.org>
Date:   Sun Feb 27 00:02:50 2011 -0500

    we don't need to set $| anymore here
    
    We set it in progress_bar now.

diff --git a/lib/Prophet/CLI/Command/Merge.pm b/lib/Prophet/CLI/Command/Merge.pm
index 1fa36c1..03186c6 100644
--- a/lib/Prophet/CLI/Command/Merge.pm
+++ b/lib/Prophet/CLI/Command/Merge.pm
@@ -109,9 +109,6 @@ sub _do_merge {
         force => $self->has_arg('force'),
     );
 
-    local $| = 1;
-
-
     my $changesets = 0;
 
 

commit b641cd385ed4f56f9257a0ad6677ac84ef09cf82
Author: Christine Spang <christine at debian.org>
Date:   Sun Feb 27 00:13:49 2011 -0500

    misc style / formatting cleanup

diff --git a/lib/Prophet/CLI/Command/Merge.pm b/lib/Prophet/CLI/Command/Merge.pm
index 03186c6..8910d4f 100644
--- a/lib/Prophet/CLI/Command/Merge.pm
+++ b/lib/Prophet/CLI/Command/Merge.pm
@@ -51,6 +51,8 @@ sub run {
         #   $self->sync_cache_from_source( target=> $self->source, source => $original_source);
     }
 
+    # foreign replicas don't typically have a resdb handle, since they aren't
+    # native
     $self->target->import_resolutions_from_remote_replica(
         from  => $self->source,
         force => $self->has_arg('force'),
@@ -111,7 +113,6 @@ sub _do_merge {
 
     my $changesets = 0;
 
-
     if ( $self->has_arg('dry-run') ) {
 
         $self->source->traverse_changesets(
@@ -137,7 +138,7 @@ sub _do_merge {
         );
 
     } else {
-		my $source_latest = $self->source->latest_sequence_no() || 0;
+	my $source_latest = $self->source->latest_sequence_no() || 0;
         if ( $self->has_arg('verbose') ) {
             print "Integrating changes from " . $last_seen_from_source . " to " . $source_latest . "\n";
             $import_args{reporting_callback} = sub {
diff --git a/lib/Prophet/ForeignReplica.pm b/lib/Prophet/ForeignReplica.pm
index e70cf39..c2ace6e 100644
--- a/lib/Prophet/ForeignReplica.pm
+++ b/lib/Prophet/ForeignReplica.pm
@@ -18,30 +18,31 @@ records and so on.
 
 =cut
 
-sub fetch_local_metadata { my $self = shift;
+sub fetch_local_metadata {
+    my $self = shift;
     my $key = shift;
-    $self->app_handle->handle->fetch_local_metadata( $self->uuid . "-".$key )
+    return $self->app_handle->handle->fetch_local_metadata(
+       $self->uuid . "-".$key );
+}
 
-    }
-sub store_local_metadata { my $self = shift;
+sub store_local_metadata {
+    my $self = shift;
     my $key = shift;
     my $value = shift;
-   $self->app_handle->handle->store_local_metadata( $self->uuid."-".$key => $value);
-
-
-    }
-
-
-
+    return $self->app_handle->handle->store_local_metadata(
+       $self->uuid."-".$key => $value);
+}
 
 sub conflicts_from_changeset { return; }
 sub can_write_changesets     {1}
 
-sub record_resolutions { die "Resolution handling is not for foreign replicas" }
+sub record_resolutions {
+   die "Resolution handling is not for foreign replicas";
+}
 
 sub import_resolutions_from_remote_source {
     warn 'resdb not implemented yet';
-    return
+    return;
 }
 
 =head2 record_changes L<Prophet::ChangeSet>
@@ -50,7 +51,6 @@ Integrate all changes in this changeset.
 
 =cut
 
-
 sub record_changes {
     my $self = shift;
     my ($changeset) = validate_pos( @_, { isa => 'Prophet::ChangeSet' } );
@@ -116,8 +116,10 @@ sub prompt_for_login {
     );
 
     # check if username is in config
-    my $replica_username_key     = 'replica.' . $self->scheme . ":" . $self->{url} . '.username';
-    my $replica_token_key        = 'replica.' . $self->scheme . ":" . $self->{url} . '.secret_token';
+    my $replica_username_key = 'replica.' . $self->scheme
+                                          .":" . $self->{url} . '.username';
+    my $replica_token_key    = 'replica.' . $self->scheme . ":"
+                                          . $self->{url} . '.secret_token';
 
     if ( !$args{username} ) {
         my $check_username
@@ -163,7 +165,6 @@ sub log {
     $self->app_handle->log($self->url.": " .$msg);
 }
 
-
 no Any::Moose;
 __PACKAGE__->meta->make_immutable;
 
diff --git a/lib/Prophet/Replica.pm b/lib/Prophet/Replica.pm
index 605bba1..62ddf64 100644
--- a/lib/Prophet/Replica.pm
+++ b/lib/Prophet/Replica.pm
@@ -258,7 +258,7 @@ sub import_changesets {
                     # If we've seen the changeset, yet we still got here, it
                     # means we saw it by original
 
-                    # replica/sequence pair, but not # the direct upstream's
+                    # replica/sequence pair, but not the direct upstream's
                     # uuid/sequence pair.
                     # recording that can help performance a whole bunch for
                     # next sync
@@ -359,7 +359,6 @@ sub integrate_changeset {
 
     my $changeset = $args{'changeset'};
 
-
     $self->log_debug("Considering changeset ".$changeset->original_sequence_no .
         " from " . $self->display_name_for_replica($changeset->original_source_uuid));
 
@@ -374,8 +373,7 @@ sub integrate_changeset {
     #   - merge tickets for the same
     # we'll want to skip or remove those changesets
 
-
-    if (!  $self->should_accept_changeset($changeset) ){
+    if ( !$self->should_accept_changeset($changeset) ) {
         # if it's a changeset we don't care about, mark it as seen and move on
         $self->record_integration_of_changeset($changeset);
         $args{'reporting_callback'}->( changeset => $changeset, )
@@ -419,11 +417,15 @@ sub integrate_changeset {
             conflict  => $conflict
         ) if ( $args{'reporting_callback'} );
         return 1;
-    } else {
-        $self->log_debug("Integrating changeset ".$changeset->original_sequence_no .
-            " from " . $self->display_name_for_replica($changeset->original_source_uuid));
+    }
+    else {
+        $self->log_debug("Integrating changeset ".
+            $changeset->original_sequence_no .
+            " from " .
+            $self->display_name_for_replica($changeset->original_source_uuid));
         $self->record_changeset_and_integration($changeset);
-        $args{'reporting_callback'}->( changeset => $changeset ) if ( $args{'reporting_callback'} );
+        $args{'reporting_callback'}->( changeset => $changeset )
+            if ( $args{'reporting_callback'} );
         return 1;
     }
 }
@@ -469,7 +471,6 @@ sub last_changeset_from_source {
     return defined $changeset_num ? $changeset_num : -1;
 }
 
-
 =head3 has_seen_changeset { source_uuid => <uuid>, sequence_no => <int> }
 
 Returns true if we've previously integrated this changeset, even if we
@@ -480,16 +481,19 @@ originally received it from a different peer.
 sub has_seen_changeset {
     my $self = shift;
     my %args = validate( @_, {source_uuid => 1, sequence_no => 1});
+
     $self->log_debug("Checking to see if we've ever seen changeset " .
         $args{sequence_no} . " from " .
         $self->display_name_for_replica($args{source_uuid}));
 
+    $self->log_debug("Last changeset from source: "
+                     . $self->last_changeset_from_source($args{source_uuid}));
+
     # If the changeset originated locally, we never want it
     if (lc($args{source_uuid}) eq lc($self->uuid) ) {
         $self->log_debug("\t  - We have. (It originated locally.)");
-        return 1 
+        return 1;
     }
-
     # Otherwise, if the we have a merge ticket from the source, we don't want
     # the changeset if the source's sequence # is >= the changeset's sequence
     # #, we can safely skip it
@@ -537,7 +541,8 @@ sub conflicts_from_changeset {
 
     return undef unless $conflict->has_conflicting_changes;
 
-    $self->log_debug("Conflicting changeset: ".JSON::to_json($conflict, {allow_blessed => 1}));
+    $self->log_debug("Conflicting changeset: ".
+        JSON::to_json($conflict, {allow_blessed => 1}));
 
     return $conflict;
 }
@@ -564,28 +569,37 @@ sub _check_db_uuids_on_merge {
 
 =head3 should_accept_changeset { from => L<Prophet::Replica>, changeset => L<Prophet::ChangeSet> }
 
-Returns true if this replica hasn't yet seen the changeset C<changeset>.
+Returns true if this replica should integrate C<changeset>, false otherwise.
 
 =cut
 
 sub should_accept_changeset {
     my $self = shift;
-    my ($changeset) = validate_pos( @_, { changeset => { isa => 'Prophet::ChangeSet' } });
+    my ($changeset) = validate_pos( @_,
+        { changeset => { isa => 'Prophet::ChangeSet' } });
 
 
     $self->log_debug("Should I accept " .$changeset->original_sequence_no .
-        " from ".$self->display_name_for_replica($changeset->original_source_uuid));
-    return undef if (! $changeset->has_changes);
-    return undef if ( $changeset->is_nullification || $changeset->is_resolution );
-    return undef if $self->has_seen_changeset( sequence_no => $changeset->original_sequence_no,  source_uuid => $changeset->original_source_uuid );
-    $self->log_debug("Yes, it has changes, isn't a nullification and I haven't seen it before");
-
-    return 1;
+        " from ".
+        $self->display_name_for_replica($changeset->original_source_uuid));
+
+    if ( !$changeset->has_changes || $changeset->is_nullification ||
+          $changeset->is_resolution || $self->has_seen_changeset(
+                sequence_no => $changeset->original_sequence_no,
+                source_uuid => $changeset->original_source_uuid ) ) {
+        return 0;
+    }
+    else {
+        $self->log_debug("Yes, it has changes, isn't a nullification ".
+                        "and I haven't seen it before");
+        return 1;
+    }
 }
 
 =head3 fetch_changesets { after => SEQUENCE_NO }
 
-Fetch all changesets from this replica after the local sequence number SEQUENCE_NO.
+Fetch all changesets from this replica after the local sequence number
+SEQUENCE_NO.
 
 Returns a reference to an array of L<Prophet::ChangeSet> objects.
 
@@ -599,7 +613,8 @@ sub fetch_changesets {
     my %args = validate( @_, { after => 1 } );
     my @results;
 
-    $self->traverse_changesets( %args, callback => sub { my %args = @_; push @results, $args{changeset} } );
+    $self->traverse_changesets( %args,
+        callback => sub { my %args = @_; push @results, $args{changeset} } );
 
     return \@results;
 }
@@ -904,8 +919,9 @@ and then call the _after_record_changes() hook.
 
 sub record_changes {
     my $self      = shift;
-    my ($changeset) = validate_pos(@_, { isa => 'Prophet::ChangeSet'});
-    $self->_unimplemented ('record_changes') unless ($self->can_write_changesets);
+    my ($changeset) = validate_pos(@_, { isa => 'Prophet::ChangeSet' });
+    $self->_unimplemented ('record_changes')
+        unless ($self->can_write_changesets);
     eval {
         local $SIG{__DIE__} = 'DEFAULT';
         my $inside_edit = $self->current_edit ? 1 : 0;
@@ -934,35 +950,57 @@ sub integrate_changes {
     my ($self, $changeset) = validate_pos( @_, {isa => 'Prophet::Replica'},
                                           { isa => 'Prophet::ChangeSet' } );
     $self->integrate_change($_, $changeset) for ( $changeset->changes );
-
+    use Data::Dump qw(pp);
+    # warn pp $changeset->changes;
 }
 
 =head2 integrate_change L<Prophet::Change> <Prophet::ChangeSet>
 
-Integrates the given change into the current replica. Used in
-L</integrate_changes>.
+Integrates the given change into the current replica using the currently active
+replica backend. Used in L</integrate_changes>.
+
+Changes can have the following types:
+- add_file
+- add_dir
+- update_file
+- delete
+
+Trying to integrate a change of an unknown type will result in a fatal error.
 
 =cut
 
 sub integrate_change {
     my ($self, $change) = validate_pos(@_, { isa => 'Prophet::Replica' },
                                            { isa => 'Prophet::Change' }, 
-                                           { isa => 'Prophet::ChangeSet' } 
-);
+                                           { isa => 'Prophet::ChangeSet' },
+    );
 
     my %new_props = map { $_->name => $_->new_value } $change->prop_changes;
     if ( $change->change_type eq 'add_file' ) {
-        $self->log_debug("add_file: " .$change->record_type. " " .$change->record_uuid);
-        $self->create_record( type  => $change->record_type, uuid  => $change->record_uuid, props => \%new_props);
-    } elsif ( $change->change_type eq 'add_dir' ) {
-        $self->log_debug("(IGNORED) add_dir: " .$change->record_type. " " .$change->record_uuid);
-    } elsif ( $change->change_type eq 'update_file' ) {
-        $self->log_debug("update_file: " .$change->record_type. " " .$change->record_uuid);
-        $self->set_record_props( type  => $change->record_type, uuid  => $change->record_uuid, props => \%new_props);
-    } elsif ( $change->change_type eq 'delete' ) {
-        $self->log_debug("delete_file: " .$change->record_type. " " .$change->record_uuid);
-        $self->delete_record( type => $change->record_type, uuid => $change->record_uuid);
-    } else {
+        $self->log_debug("add_file: " . $change->record_type
+                                      . " " . $change->record_uuid);
+        $self->create_record( type  => $change->record_type,
+                              uuid  => $change->record_uuid,
+                              props => \%new_props );
+    }
+    elsif ( $change->change_type eq 'add_dir' ) {
+        $self->log_debug("(IGNORED) add_dir: "
+                         . $change->record_type. " " . $change->record_uuid);
+    }
+    elsif ( $change->change_type eq 'update_file' ) {
+        $self->log_debug("update_file: "
+                         .$change->record_type. " " .$change->record_uuid);
+        $self->set_record_props( type  => $change->record_type,
+                                 uuid  => $change->record_uuid,
+                                 props => \%new_props );
+    }
+    elsif ( $change->change_type eq 'delete' ) {
+        $self->log_debug("delete_file: "
+                         . $change->record_type. " " .$change->record_uuid);
+        $self->delete_record( type => $change->record_type,
+                              uuid => $change->record_uuid );
+    }
+    else {
         Carp::confess( "Unknown change type: " . $change->change_type );
     }
 }
@@ -980,14 +1018,19 @@ sub record_integration_of_changeset {
     my ($changeset) = validate_pos( @_, { isa => 'Prophet::ChangeSet' } );
 
     if ( $changeset->original_source_uuid ne $self->uuid
-        && ( $self->last_changeset_from_source( $changeset->original_source_uuid ) < $changeset->original_sequence_no )
+        && ( $self->last_changeset_from_source(
+                $changeset->original_source_uuid
+            ) < $changeset->original_sequence_no )
         ) {
         $self->record_last_changeset_from_replica(
-            $changeset->original_source_uuid => $changeset->original_sequence_no );
+            $changeset->original_source_uuid,
+            $changeset->original_sequence_no );
     }
     if ( $changeset->source_uuid ) {
-        if ( $self->last_changeset_from_source( $changeset->source_uuid ) < $changeset->sequence_no ) {
-            $self->record_last_changeset_from_replica( $changeset->source_uuid => $changeset->sequence_no );
+        if ( $self->last_changeset_from_source(
+                $changeset->source_uuid ) < $changeset->sequence_no ) {
+            $self->record_last_changeset_from_replica(
+                $changeset->source_uuid => $changeset->sequence_no );
         }
     }
 }
@@ -995,8 +1038,9 @@ sub record_integration_of_changeset {
 sub record_last_changeset_from_replica {
     my $self = shift;
     my ($uuid, $sequence) = validate_pos(@_, 1,1);
-        return $self->store_local_metadata( 'last-changeset-from-' . $uuid => $sequence );
 
+    return $self->store_local_metadata(
+        'last-changeset-from-' . $uuid, $sequence );
 }
 
 =head2 routines which need to be implemented by any Prophet backend store
diff --git a/lib/Prophet/Replica/prophet.pm b/lib/Prophet/Replica/prophet.pm
index e28b7c3..6037e74 100755
--- a/lib/Prophet/Replica/prophet.pm
+++ b/lib/Prophet/Replica/prophet.pm
@@ -77,7 +77,10 @@ has changeset_cas => (
     },
 );
 
-has current_edit => ( is => 'rw', );
+has current_edit => (
+    is  => 'rw',
+    isa => 'Maybe[Prophet::ChangeSet]',
+);
 
 has current_edit_records => (
     is        => 'rw',
@@ -614,7 +617,11 @@ sub changesets_for_record {
 }
 
 
+=head2 begin_edit
 
+Creates a new L<Prophet::ChangeSet>, which new changes will be added to.
+
+=cut
 
 sub begin_edit {
     my $self = shift;
@@ -638,7 +645,6 @@ sub begin_edit {
     );
     $self->current_edit($changeset);
     $self->current_edit_records( [] );
-
 }
 
 sub _set_original_source_metadata_for_current_edit {

commit 98529f593f35009bf93130d0926836da56836669
Author: Christine Spang <christine at debian.org>
Date:   Sun Feb 27 14:57:43 2011 -0500

    make prompt_for_login support not prompting for password if passed in
    
    Sometimes we want to be able to throw this in a loop to check
    predefined credentials and to re-prompt for them in the
    case that they're wrong.

diff --git a/lib/Prophet/ForeignReplica.pm b/lib/Prophet/ForeignReplica.pm
index c2ace6e..8a6ff74 100644
--- a/lib/Prophet/ForeignReplica.pm
+++ b/lib/Prophet/ForeignReplica.pm
@@ -79,12 +79,15 @@ Named parameters:
 
     uri
     username
+    password
     username_prompt
     secret_prompt
 
 To use the default prompts, which ask for a username and password, pass in
-C<uri> and (optionally) C<username>.  The username prompt will be skipped
-if a username is passed in.
+C<uri> and (optionally) C<username>.  Either prompt will be skipped if
+a value is passed in to begin, making this suitable for use in a login
+loop that prompts for values and then tests that they work for authentication,
+looping around if they don't.
 
 You can also override the default prompts by passing in subroutines for
 C<username_prompt> and/or C<secret_prompt>. These subroutines return strings
@@ -104,6 +107,7 @@ sub prompt_for_login {
     my %args = (
         uri             => undef,
         username        => undef,
+        password        => undef,
         secret_prompt   => sub {
             my ($uri, $username) = @_;
             return "Password for $username: @ $uri: ";
@@ -115,7 +119,7 @@ sub prompt_for_login {
         @_,
     );
 
-    # check if username is in config
+    # check if username and password are in config
     my $replica_username_key = 'replica.' . $self->scheme
                                           .":" . $self->{url} . '.username';
     my $replica_token_key    = 'replica.' . $self->scheme . ":"
@@ -127,8 +131,6 @@ sub prompt_for_login {
         $args{username} = $check_username if $check_username;
     }
 
-    my $secret;
-
     my $was_in_pager = Prophet::CLI->in_pager();
     Prophet::CLI->end_pager();
 
@@ -144,18 +146,18 @@ sub prompt_for_login {
     if ( my $check_password
         = $self->app_handle->config->get( key => $replica_token_key ) )
     {
-        $secret = $check_password;
+        $args{password} = $check_password;
     }
-    else {
+    elsif ( !defined($args{password}) ) {
         print $args{secret_prompt}( $args{uri}, $args{username} );
         ReadMode 2;
-        chomp( $secret = ReadLine 0 );
+        chomp( $args{password} = ReadLine 0 );
         ReadMode 1;
         print "\n";
     }
     Prophet::CLI->start_pager() if ($was_in_pager);
 
-    return ( $args{username}, $secret );
+    return ( $args{username}, $args{password} );
 }
 
 sub log {

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list