[Bps-public-commit] r11321 - in SVN-PropDB: lib/Prophet lib/Prophet/Sync/Source t

clkao at bestpractical.com clkao at bestpractical.com
Mon Mar 31 23:01:50 EDT 2008


Author: clkao
Date: Mon Mar 31 23:01:50 2008
New Revision: 11321

Modified:
   SVN-PropDB/lib/Prophet/Conflict.pm
   SVN-PropDB/lib/Prophet/Sync/Source.pm
   SVN-PropDB/lib/Prophet/Sync/Source/SVN.pm
   SVN-PropDB/t/real-conflicting-merge.t

Log:
make resolution_from_resdb a default resolver when we have
use_resdb passed in for import_changesets.


Modified: SVN-PropDB/lib/Prophet/Conflict.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Conflict.pm	(original)
+++ SVN-PropDB/lib/Prophet/Conflict.pm	Mon Mar 31 23:01:50 2008
@@ -35,17 +35,33 @@
     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;
+}
 
 sub generate_resolution {
-    my $self = shift;   
-    
+    my $self = shift;
+    my $resdb = shift;
     my @resolvers = (
-    
         sub { $self->attempt_automatic_conflict_resolution(@_) },
-         @{$self->resolvers || []},
-         $self->_resolution_failed);
-    
-    
+        $resdb ? sub { $self->resolution_from_resdb( $resdb, @_ ) } : (),
+        @{ $self->resolvers || [] },
+        $self->_resolution_failed
+    );
+
     my $resolutions = Prophet::ChangeSet->new( { is_resolution => 1 } );
     for my $conflict ( @{ $self->conflicting_changes } ) {
         for (@resolvers) {

Modified: SVN-PropDB/lib/Prophet/Sync/Source.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Sync/Source.pm	(original)
+++ SVN-PropDB/lib/Prophet/Sync/Source.pm	Mon Mar 31 23:01:50 2008
@@ -50,11 +50,16 @@
 
 sub import_changesets {
     my $self = shift;
-    my %args   = validate( @_, { from => { isa => 'Prophet::Sync::Source'},
-                                 resolver => { optional => 1},
-                                 conflict_callback => { optional => 1 } } );
+    my %args = validate( @_, { from => { isa => 'Prophet::Sync::Source' },
+            use_resdb => { optional => 1 },
+            resolver          => { optional => 1 },
+            conflict_callback => { optional => 1 } } );
+
     my $source = $args{'from'};
 
+    my $resdb = $args{use_resdb} ?
+        $self->fetch_resolutions( from => $source ) : undef;
+
     my $changesets_to_integrate
         = $source->fetch_changesets( after => $self->last_changeset_from_source( $source->uuid ) );
 
@@ -62,16 +67,17 @@
     
        next if ( $self->has_seen_changeset($changeset) );
        next if $changeset->is_nullification || $changeset->is_resolution;
-        $self->integrate_changeset( changeset => $changeset, conflict_callback => $args{conflict_callback}, resolver => $args{resolver});
+        $self->integrate_changeset( changeset => $changeset, conflict_callback => $args{conflict_callback}, resolver => $args{resolver}, resdb => $resdb);
 
     }
 }
 
 sub fetch_resolutions {
     my $self = shift;
-    my %args   = validate( @_, { from => { isa => 'Prophet::Sync::Source'},
-                                 resolver => { optional => 1},
-                                 conflict_callback => { optional => 1 } } );
+    my %args = validate( @_,
+        { from => { isa => 'Prophet::Sync::Source' },
+            resolver          => { optional => 1 },
+            conflict_callback => { optional => 1 } } );
     my $source = $args{'from'};
 
     return unless $self->ressource;

Modified: SVN-PropDB/lib/Prophet/Sync/Source/SVN.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Sync/Source/SVN.pm	(original)
+++ SVN-PropDB/lib/Prophet/Sync/Source/SVN.pm	Mon Mar 31 23:01:50 2008
@@ -228,12 +228,13 @@
 
 sub integrate_changeset {
     my $self = shift;
-    my %args = validate( @_, { changeset => {isa => 'Prophet::ChangeSet'}, 
-                               resolver => { optional => 1},
-                             conflict_callback => { optional => 1 } 
-                             } 
-                            );
-
+    my %args = validate( @_,
+        { changeset => { isa => 'Prophet::ChangeSet' },
+            resolver          => { optional => 1 },
+            resdb             => { optional => 1 },
+            conflict_callback => { optional => 1 }
+        }
+    );
 
     my $changeset = $args{'changeset'};
 
@@ -255,10 +256,9 @@
     return if ($changeset->is_empty or $changeset->is_nullification);
 
     if (my $conflict = $self->conflicts_from_changeset($changeset ) ) {
-
         $args{conflict_callback}->($conflict) if $args{'conflict_callback'};
         $conflict->resolvers([sub { $args{resolver}->(@_) }]) if $args{resolver};
-        my $resolutions = $conflict->generate_resolution;
+        my $resolutions = $conflict->generate_resolution($args{resdb});
         #figure out our conflict resolution
 
         # IMPORTANT: these should be an atomic unit. dying here would be poor.  BUT WE WANT THEM AS THREEDIFFERENT SVN REVS

Modified: SVN-PropDB/t/real-conflicting-merge.t
==============================================================================
--- SVN-PropDB/t/real-conflicting-merge.t	(original)
+++ SVN-PropDB/t/real-conflicting-merge.t	Mon Mar 31 23:01:50 2008
@@ -4,7 +4,7 @@
 use strict;
 use Test::Exception;
 
-use Prophet::Test tests => 16;
+use Prophet::Test tests => 17;
 
 as_alice {
     run_ok( 'prophet-node-create', [qw(--type Bug --status new --from alice )], "Created a record as alice" );
@@ -87,26 +87,15 @@
     my $source = Prophet::Sync::Source->new( { url => repo_uri_for('bob') } );
     my $target = Prophet::Sync::Source->new( { url => repo_uri_for('alice') } );
 
-    my $res = $target->fetch_resolutions( from => $source );
+    throws_ok {
+        $target->import_changesets(
+            from      => $source,
+        );
+    } qr/not resolved/;
 
     $target->import_changesets(
         from => $source,
-        resolver => sub {
-            my $conflict = shift;
-            # XXX: turn this into an explicit load?
-            $res->matching( sub { $_[0]->uuid eq $conflict->cas_key });
-            my $answer = $res->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_resdb => 1,
     );
 
     lives_and {



More information about the Bps-public-commit mailing list