[Bps-public-commit] r11357 - in SVN-PropDB: . bin lib/Prophet lib/Prophet/Resolver

jesse at bestpractical.com jesse at bestpractical.com
Tue Apr 1 21:36:43 EDT 2008


Author: jesse
Date: Tue Apr  1 21:36:42 2008
New Revision: 11357

Added:
   SVN-PropDB/lib/Prophet/Resolver/Failed.pm
   SVN-PropDB/lib/Prophet/Resolver/FromResolutionDB.pm
   SVN-PropDB/lib/Prophet/Resolver/IdenticalChanges.pm
Modified:
   SVN-PropDB/   (props changed)
   SVN-PropDB/bin/prophet-merge
   SVN-PropDB/lib/Prophet/Conflict.pm
   SVN-PropDB/lib/Prophet/Resolver/AlwaysSource.pm
   SVN-PropDB/lib/Prophet/Resolver/AlwaysTarget.pm
   SVN-PropDB/lib/Prophet/Resolver/Prompt.pm
   SVN-PropDB/lib/Prophet/Sync/Source.pm

Log:
 r28930 at 70-5-79-205:  jesse | 2008-04-01 15:35:57 -1000
  *extracted resolvers


Modified: SVN-PropDB/bin/prophet-merge
==============================================================================
--- SVN-PropDB/bin/prophet-merge	(original)
+++ SVN-PropDB/bin/prophet-merge	Tue Apr  1 21:36:42 2008
@@ -29,9 +29,12 @@
 
 $target->import_changesets( from => $source, 
                             use_resdb => 1,
-                            ($opts->{'prefer'} eq 'to' ? (resolver_class => 'Prophet::Resolver::AlwaysTarget') : ()),
-                            ($opts->{'prefer'} eq 'from' ? (resolver_class => 'Prophet::Resolver::AlwaysSource') : ())
-);
+                            $ENV{'PROPHET_RESOLVER'} ? 
+                            (resolver_class => 'Prophet::Resolver::'.$ENV{'PROPHET_RESOLVER'}) :
+	                            (
+	                            ($opts->{'prefer'} eq 'to' ? (resolver_class => 'Prophet::Resolver::AlwaysTarget') : ()),
+	                            ($opts->{'prefer'} eq 'from' ? (resolver_class => 'Prophet::Resolver::AlwaysSource') : ()))
+	);
 
 exit(0);
 

Modified: SVN-PropDB/lib/Prophet/Conflict.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Conflict.pm	(original)
+++ SVN-PropDB/lib/Prophet/Conflict.pm	Tue Apr  1 21:36:42 2008
@@ -30,42 +30,23 @@
     return 1;
 }
 
-sub _resolution_failed {
-
-    return sub { die "conflict not resolved.\n" };
-}
-
-sub resolution_from_resdb {
-    my ($self, $resdb, $conflict) = @_;
-    # XXX: turn this into an explicit load?
-    $resdb->matching( sub { $_[0]->uuid eq $conflict->cas_key });
-    my $answer = $resdb->as_array_ref->[0] or return;
-
-    my $resolution = Prophet::Change->new_from_conflict($conflict);
-    for my $prop_conflict ( @{ $conflict->prop_conflicts } ) {
-        $resolution->add_prop_change(
-            name => $prop_conflict->name,
-            old  => $prop_conflict->source_old_value,
-            new  => $answer->prop( $prop_conflict->name ),
-        );
-    }
-    return $resolution;
-}
+use Prophet::Resolver::IdenticalChanges;
+use Prophet::Resolver::FromResolutionDB;
+use Prophet::Resolver::Failed;
 
 sub generate_resolution {
     my $self = shift;
     my $resdb = shift;
     my @resolvers = (
-        sub { $self->attempt_automatic_conflict_resolution(@_) },
-        $resdb ? sub { $self->resolution_from_resdb( $resdb, @_ ) } : (),
+        sub { Prophet::Resolver::IdenticalChanges->new->run(@_); },
+        $resdb ? sub { Prophet::Resolver::FromResolutionDB->new->run(@_) } : (),
         @{ $self->resolvers || [] },
-        $self->_resolution_failed
+        sub { Prophet::Resolver::Failed->new->run(@_) },
     );
-
     my $resolutions = Prophet::ChangeSet->new( { is_resolution => 1 } );
-    for my $conflict ( @{ $self->conflicting_changes } ) {
+    for my $conflicting_change ( @{ $self->conflicting_changes } ) {
         for (@resolvers) {
-            if (my $resolution = $_->($conflict)) {
+            if (my $resolution = $_->($conflicting_change, $self, $resdb)) {
                 $resolutions->add_change(change => $resolution) if $resolution->prop_changes;
                 last;
             }
@@ -76,60 +57,6 @@
     return 1;
 }
 
-=head2 attempt_automatic_conflict_resolution
-
-Given a L<Prophet::Conflict> which can not be cleanly applied to a
-replica, it is sometimes possible to automatically determine a sane
-resolution to the conflict.
-
-=over
-
-=item When the new-state of the conflicting change matches the
-previous head of the replica.
-
-=item When someone else has previously done the resolution and we
-have a copy of that hanging aroun
-
-** This bit seems hard
-
-=back
-
-
-In those cases, this routine will generate a L<Prophet::ChangeSet> which resolves 
-as many conflicts as possible.
-
-It will then update $self->conflicting_changes to mark which
-L<Prophet::ConflictingChange>s and L<Prophet::ConflictingPropChanges>
-have been automatically resolved.
-
-
-=cut
-
-
-sub attempt_automatic_conflict_resolution {
-    my $self = shift;
-    my ($conflicting_change) = validate_pos(@_, { isa => 'Prophet::ConflictingChange'});
-  # for everything from the changeset that is the same as the old value of the target replica
-    # we can skip applying 
-    return 0 if $conflicting_change->file_op_conflict;
-
-    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
-    }
-
-    $self->autoresolved(1);
-
-    return $resolution;
-
-
-
-
-
-
-}
-
 
 =head2 generate_changeset_conflicts 
 

Modified: SVN-PropDB/lib/Prophet/Resolver/AlwaysSource.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Resolver/AlwaysSource.pm	(original)
+++ SVN-PropDB/lib/Prophet/Resolver/AlwaysSource.pm	Tue Apr  1 21:36:42 2008
@@ -7,10 +7,10 @@
 
 sub run {
     my $self = shift;
-    my $conflict = shift;
-    return 0 if $conflict->file_op_conflict;
-
-    my $resolution = Prophet::Change->new_from_conflict($conflict);
+	    my $conflict = shift;
+	    return 0 if $conflict->file_op_conflict;
+	
+    my $resolution = Prophet::Change->new_from_conflict($conflicting_change);
     return $resolution;
 }
 

Modified: SVN-PropDB/lib/Prophet/Resolver/AlwaysTarget.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Resolver/AlwaysTarget.pm	(original)
+++ SVN-PropDB/lib/Prophet/Resolver/AlwaysTarget.pm	Tue Apr  1 21:36:42 2008
@@ -7,16 +7,16 @@
 
 sub  run {
     my $self = shift;
- my $conflict = shift;
-            return 0 if $conflict->file_op_conflict;
+ my $conflicting_change = shift;
+            return 0 if $conflicting_change->file_op_conflict;
 
-            my $resolution = Prophet::Change->new_from_conflict( $conflict );
+            my $resolution = Prophet::Change->new_from_conflict( $conflicting_change );
 
-            for my $prop_conflict ( @{ $conflict->prop_conflicts } ) {
+            for my $prop_change ( @{ $conflicting_change->prop_conflicts } ) {
                 $resolution->add_prop_change(
-                    name => $prop_conflict->name,
-                    old  => $prop_conflict->source_new_value,
-                    new  => $prop_conflict->target_value
+                    name => $prop_change->name,
+                    old  => $prop_change->source_new_value,
+                    new  => $prop_change->target_value
                 );
             }
             return $resolution;

Added: SVN-PropDB/lib/Prophet/Resolver/Failed.pm
==============================================================================
--- (empty file)
+++ SVN-PropDB/lib/Prophet/Resolver/Failed.pm	Tue Apr  1 21:36:42 2008
@@ -0,0 +1,11 @@
+use warnings;
+use strict;
+
+package Prophet::Resolver::Failed;
+use base qw/Prophet::Resolver/;
+
+sub run {
+    die "The resolution was not resolved. Sorry dude. (Once Prophet works, you should NEVER see this message)";
+}
+
+1;

Added: SVN-PropDB/lib/Prophet/Resolver/FromResolutionDB.pm
==============================================================================
--- (empty file)
+++ SVN-PropDB/lib/Prophet/Resolver/FromResolutionDB.pm	Tue Apr  1 21:36:42 2008
@@ -0,0 +1,30 @@
+use warnings;
+use strict;
+
+package Prophet::Resolver::FromResolutionDB;
+use base qw/Prophet::Resolver/;
+use Prophet::Change;
+
+sub run {
+    my $self = shift;
+    my $conflicting_change = shift;
+    my $conflict = shift;
+    my $resdb = shift;
+
+    # XXX: turn this into an explicit load?
+    $resdb->matching( sub { $_[0]->uuid eq $conflicting_change->cas_key });
+    my $answer = $resdb->as_array_ref->[0] or return;
+    
+    my $resolution = Prophet::Change->new_from_conflict($conflicting_change);
+    for my $prop_conflict ( @{ $conflicting_change->prop_conflicts } ) {
+        $resolution->add_prop_change(
+            name => $prop_conflict->name,
+            old  => $prop_conflict->source_old_value,
+            new  => $answer->prop( $prop_conflict->name ),
+        );
+    }
+    return $resolution;
+
+}
+
+1;

Added: SVN-PropDB/lib/Prophet/Resolver/IdenticalChanges.pm
==============================================================================
--- (empty file)
+++ SVN-PropDB/lib/Prophet/Resolver/IdenticalChanges.pm	Tue Apr  1 21:36:42 2008
@@ -0,0 +1,61 @@
+use warnings;
+use strict;
+
+package Prophet::Resolver::IdenticalChanges;
+use base qw/Prophet::Resolver/;
+use Params::Validate qw(:all);
+use Prophet::Change;
+
+=head2 attempt_automatic_conflict_resolution
+
+Given a L<Prophet::Conflict> which can not be cleanly applied to a
+replica, it is sometimes possible to automatically determine a sane
+resolution to the conflict.
+
+=over
+
+=item When the new-state of the conflicting change matches the
+previous head of the replica.
+
+=item When someone else has previously done the resolution and we
+have a copy of that hanging aroun
+
+** This bit seems hard
+
+=back
+
+
+In those cases, this routine will generate a L<Prophet::ChangeSet> which resolves 
+as many conflicts as possible.
+
+It will then update $self->conflicting_changes to mark which
+L<Prophet::ConflictingChange>s and L<Prophet::ConflictingPropChanges>
+have been automatically resolved.
+
+
+=cut
+
+
+sub run {
+    my $self = shift;
+    my ($conflicting_change, $conflict, $resdb) = validate_pos(@_, { isa => 'Prophet::ConflictingChange'}, { isa => 'Prophet::Conflict'} , 0);
+  # for everything from the changeset that is the same as the old value of the target replica
+    # we can skip applying 
+    return 0 if $conflicting_change->file_op_conflict;
+
+    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
+    }
+
+    $conflict->autoresolved(1);
+
+    return $resolution;
+
+
+
+
+}
+
+1;

Modified: SVN-PropDB/lib/Prophet/Resolver/Prompt.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Resolver/Prompt.pm	(original)
+++ SVN-PropDB/lib/Prophet/Resolver/Prompt.pm	Tue Apr  1 21:36:42 2008
@@ -16,10 +16,10 @@
 
             for my $prop_conflict ( @{ $conflicting_change->prop_conflicts } ) {
 
-                print $prop_conflict->name.": "\n;
-                print "(T)ARGET     ".$prop_conflicts->target_value ."\n";
-                print "SOURCE (O)LD ".$prop_conflicts->source_old_value ."\n";
-                print "SOURCE (N)EW ".$prop_conflicts->source_new_value ."\n";
+                print $prop_conflict->name.": \n";
+                print "(T)ARGET     ".$prop_conflict->target_value ."\n";
+                print "SOURCE (O)LD ".$prop_conflict->source_old_value ."\n";
+                print "SOURCE (N)EW ".$prop_conflict->source_new_value ."\n";
    
 
               
@@ -45,7 +45,6 @@
 
                 } elsif ($choice eq 'n') {
                     last;
-                );
 
 
                 }

Modified: SVN-PropDB/lib/Prophet/Sync/Source.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Sync/Source.pm	(original)
+++ SVN-PropDB/lib/Prophet/Sync/Source.pm	Tue Apr  1 21:36:42 2008
@@ -85,7 +85,9 @@
     return unless $self->ressource;
 
     $self->ressource->import_changesets( from => $source->ressource,
-                                             resolver => sub { die "nono not yet" } );
+                                         resolver => sub { die "nono not yet" } 
+                                         
+                                         );
 
     my $records = Prophet::Collection->new(handle => $self->ressource->prophet_handle, type => '_prophet_resolution');
     return $records;



More information about the Bps-public-commit mailing list