[Bps-public-commit] r15531 - in Prophet/branches/dispatcher: . lib/Prophet lib/Prophet/CLI lib/Prophet/Resolver

sartak at bestpractical.com sartak at bestpractical.com
Wed Aug 27 11:19:36 EDT 2008


Author: sartak
Date: Wed Aug 27 11:19:23 2008
New Revision: 15531

Modified:
   Prophet/branches/dispatcher/   (props changed)
   Prophet/branches/dispatcher/lib/Prophet/CLI/Command.pm
   Prophet/branches/dispatcher/lib/Prophet/CLI/Command/Log.pm
   Prophet/branches/dispatcher/lib/Prophet/Change.pm
   Prophet/branches/dispatcher/lib/Prophet/ChangeSet.pm
   Prophet/branches/dispatcher/lib/Prophet/ConflictingChange.pm
   Prophet/branches/dispatcher/lib/Prophet/Record.pm
   Prophet/branches/dispatcher/lib/Prophet/Resolver/IdenticalChanges.pm

Log:
Bring dispatcher up to trunk

Modified: Prophet/branches/dispatcher/lib/Prophet/CLI/Command.pm
==============================================================================
--- Prophet/branches/dispatcher/lib/Prophet/CLI/Command.pm	(original)
+++ Prophet/branches/dispatcher/lib/Prophet/CLI/Command.pm	Wed Aug 27 11:19:23 2008
@@ -15,17 +15,12 @@
 has context => (
     is => 'rw',
     isa => 'Prophet::CLIContext',
-    lazy => 1,
     handles => [ 
         qw/args  set_arg  arg  has_arg  delete_arg  arg_names/,
         qw/props set_prop prop has_prop delete_prop prop_names/,
         'add_to_prop_set', 'prop_set',
     ],
 
-    default => sub {
-        return Prophet::CLIContext->new( app_handle => shift->app_handle);
-    }
-
 );
 
 

Modified: Prophet/branches/dispatcher/lib/Prophet/CLI/Command/Log.pm
==============================================================================
--- Prophet/branches/dispatcher/lib/Prophet/CLI/Command/Log.pm	(original)
+++ Prophet/branches/dispatcher/lib/Prophet/CLI/Command/Log.pm	Wed Aug 27 11:19:23 2008
@@ -3,25 +3,49 @@
 extends 'Prophet::CLI::Command';
 
 sub run {
-    my $self = shift;
+    my $self   = shift;
     my $handle = $self->handle;
     my $newest = $self->arg('last') || $handle->latest_sequence_no;
-    my $start = $newest - ($self->arg('count') || '20');
+    my $start  = $newest - ( $self->arg('count') || '20' );
     $start = 0 if $start < 0;
 
     $handle->traverse_changesets(
         after    => $start,
         callback => sub {
             my $changeset = shift;
-          print $changeset->as_string(change_header => sub {
-                    my $change = shift;
-                    return " # " . $change->record_type. " ".$self->app_handle->handle->find_or_create_luid(uuid => $change->record_uuid)." (" . $change->record_uuid.")\n";
-                       
-              });
+            $self->handle_changeset($changeset);
+
         },
     );
 
+}
+
+
+sub handle_changeset {
+    my $self      = shift;
+    my $changeset = shift;
+    print $changeset->as_string(
+        change_header => sub {
+            my $change = shift;
+            $self->change_header($change);
+        }
+    );
+
+}
+sub change_header {
+    my $self   = shift;
+    my $change = shift;
+    return
+          " # "
+        . $change->record_type . " "
+        . $self->app_handle->handle->find_or_create_luid(
+        uuid => $change->record_uuid )
+        . " ("
+        . $change->record_uuid . ")\n";
 
 }
 
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
 1;

Modified: Prophet/branches/dispatcher/lib/Prophet/Change.pm
==============================================================================
--- Prophet/branches/dispatcher/lib/Prophet/Change.pm	(original)
+++ Prophet/branches/dispatcher/lib/Prophet/Change.pm	Wed Aug 27 11:19:23 2008
@@ -121,6 +121,23 @@
     };
 }
 
+sub as_string {
+    my $self         = shift;
+    my %args         = validate( @_, { header_callback => 0, } );
+    my $out          = "";
+    my @prop_changes = $self->prop_changes;
+    next if @prop_changes == 0;
+    $out .= $args{header_callback}->($self) if ( $args{header_callback} );
+
+    for my $prop_change (@prop_changes) {
+        $out .= "  " . $prop_change->summary . "\n";
+    }
+
+    return $out;
+
+}
+
+
 sub new_from_hashref {
     my $class   = shift;
     my $uuid    = shift;

Modified: Prophet/branches/dispatcher/lib/Prophet/ChangeSet.pm
==============================================================================
--- Prophet/branches/dispatcher/lib/Prophet/ChangeSet.pm	(original)
+++ Prophet/branches/dispatcher/lib/Prophet/ChangeSet.pm	Wed Aug 27 11:19:23 2008
@@ -162,45 +162,36 @@
 
 sub as_string {
     my $self = shift;
-    my %args = validate(@_, {
-        change_filter => 0,
-        change_header => 0,
-    });
-
-    my $change_filter = $args{change_filter};
-
-    my $out = '';
-
-    $out .= sprintf "Change %d by %s at %s\n\t\t\t\t\(%d@%s)\n\n",
-            $self->sequence_no,
-                ($self->creator || '(unknown)'),
-                $self->created,
-                $self->original_sequence_no,
-                $self->original_source_uuid;
-
-    for my $change ($self->changes) {
-        my @prop_changes = $change->prop_changes;
-        next if @prop_changes == 0;
-
-        if ($change_filter) {
-            next unless $change_filter->($change);
+    my %args = validate(
+        @_,
+        {   change_filter => 0,
+            change_header => 0,
+            header_callback => 0
         }
+    );
 
-        if ($args{change_header}) {
-          $out .=   $args{change_header}->($change);
-        }
 
-        for my $prop_change (@prop_changes) {
-            $out .= "  " . $prop_change->summary . "\n";
-        }
+    my $out = $args{header_callback} ? $args{header_callback}->($self) :  $self->description_as_string;
+
+    for my $change ( $self->changes ) {
+        next if $args{change_filter} && !$args{change_filter}->($change);
+        $out .= $change->as_string( header_callback => $args{change_header} );
         $out .= "\n";
     }
 
     $out .= "\n";
-
     return $out;
 }
 
+sub description_as_string {
+    my $self = shift;
+     sprintf "Change %d by %s at %s\n\t\t\t\t\(%d@%s)\n\n",
+        $self->sequence_no,
+        ( $self->creator || '(unknown)' ),
+        $self->created,
+        $self->original_sequence_no,
+        $self->original_source_uuid;
+    }
 __PACKAGE__->meta->make_immutable;
 no Moose;
 

Modified: Prophet/branches/dispatcher/lib/Prophet/ConflictingChange.pm
==============================================================================
--- Prophet/branches/dispatcher/lib/Prophet/ConflictingChange.pm	(original)
+++ Prophet/branches/dispatcher/lib/Prophet/ConflictingChange.pm	Wed Aug 27 11:19:23 2008
@@ -73,7 +73,7 @@
 
     my $struct = $self->as_hash;
     for ( @{ $struct->{prop_conflicts} } ) {
-        $_->{choices} = [ sort ( delete $_->{source_new_value}, delete $_->{target_value} ) ];
+        $_->{choices} = [ sort grep { defined} ( delete $_->{source_new_value}, delete $_->{target_value} ) ];
     }
 
     return  sha1_hex(to_json($struct, {utf8 => 1, canonical => 1}));

Modified: Prophet/branches/dispatcher/lib/Prophet/Record.pm
==============================================================================
--- Prophet/branches/dispatcher/lib/Prophet/Record.pm	(original)
+++ Prophet/branches/dispatcher/lib/Prophet/Record.pm	Wed Aug 27 11:19:23 2008
@@ -330,7 +330,7 @@
     return $self->handle->get_record_props(
         uuid => $self->uuid,
         type => $self->type
-    );
+    ) || {};
 }
 
 =head2 prop $name

Modified: Prophet/branches/dispatcher/lib/Prophet/Resolver/IdenticalChanges.pm
==============================================================================
--- Prophet/branches/dispatcher/lib/Prophet/Resolver/IdenticalChanges.pm	(original)
+++ Prophet/branches/dispatcher/lib/Prophet/Resolver/IdenticalChanges.pm	Wed Aug 27 11:19:23 2008
@@ -45,7 +45,11 @@
     my $resolution = Prophet::Change->new_from_conflict($conflicting_change);
 
     for my $prop_change ( @{ $conflicting_change->prop_conflicts } ) {
-        return 0 unless $prop_change->target_value eq $prop_change->source_new_value;
+        next if ((!defined $prop_change->target_value || $prop_change->target_value  eq '')
+                
+                && ( !defined $prop_change->source_new_value || $prop_change->source_new_value eq ''));
+        next if $prop_change->target_value eq $prop_change->source_new_value;
+        return 0; 
     }
 
     $conflict->autoresolved(1);



More information about the Bps-public-commit mailing list