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

clkao at bestpractical.com clkao at bestpractical.com
Mon Mar 31 22:37:48 EDT 2008


Author: clkao
Date: Mon Mar 31 22:37:48 2008
New Revision: 11318

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

Log:
- now reuse the resolution from a separate resolution db.
- have fetch_resolutions sync the resdb first.

Modified: SVN-PropDB/lib/Prophet/Handle.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Handle.pm	(original)
+++ SVN-PropDB/lib/Prophet/Handle.pm	Mon Mar 31 22:37:48 2008
@@ -126,6 +126,7 @@
 sub record_resolutions {
     my $self      = shift;
     my $changeset = shift;
+    my $res_handle = shift;
 
     return unless $changeset->changes;
 
@@ -136,9 +137,7 @@
     my $changed = $self->current_edit->root->paths_changed;
     warn Dumper($changed) if ($DEBUG);
 
-use Data::Dumper;
-    warn Dumper($changeset);
-    $self->record_resolution($_) for $changeset->changes;
+    $res_handle->record_resolution($_) for $changeset->changes;
     $self->commit_edit();
 }
 

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 22:37:48 2008
@@ -62,7 +62,6 @@
     
        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});
 
     }
@@ -74,11 +73,14 @@
                                  resolver => { optional => 1},
                                  conflict_callback => { optional => 1 } } );
     my $source = $args{'from'};
-    
-    my $changesets
-        = $source->fetch_changesets( after => $self->last_changeset_from_source( $source->uuid ) );
 
-    return grep { $_->is_resolution && !$self->has_seen_changeset($_) } @$changesets;
+    return unless $self->ressource;
+
+    $self->ressource->import_changesets( from => $source->ressource,
+                                             resolver => sub { die "nono not yet" } );
+
+    my $records = Prophet::Collection->new(handle => $self->ressource->prophet_handle, type => '_prophet_resolution');
+    return $records;
 }
 
 

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 22:37:48 2008
@@ -15,7 +15,7 @@
 use Prophet::ChangeSet;
 use Prophet::Conflict;
 
-__PACKAGE__->mk_accessors(qw/url ra prophet_handle ressource/);
+__PACKAGE__->mk_accessors(qw/url ra prophet_handle ressource is_resdb/);
 
 our $DEBUG = $Prophet::Handle::DEBUG;
 
@@ -38,12 +38,13 @@
         $self->prophet_handle( Prophet::Handle->new( { repository => $1, db_root => '_prophet' }));
     }
     if ($self->url =~ m/_res$/) {
+        # XXX: should probably just point to self
         return;
     }
 
     my $res_url = $self->url;
     $res_url =~ s/(\_res|)$/_res/;
-    $self->ressource( __PACKAGE__->new( { url => $res_url } ) );
+    $self->ressource( __PACKAGE__->new( { url => $res_url, is_resdb => 1 } ) );
 }
 
 =head2 uuid
@@ -248,7 +249,9 @@
     # we'll want to skip or remove those changesets
 
     return if $changeset->original_source_uuid eq $self->prophet_handle->uuid;
+
     $self->remove_redundant_data($changeset); #Things we have already seen
+
     return if ($changeset->is_empty or $changeset->is_nullification);
 
     if (my $conflict = $self->conflicts_from_changeset($changeset ) ) {
@@ -265,7 +268,10 @@
         # integrate the original change
         $self->prophet_handle->integrate_changeset($changeset);
         # integrate the conflict resolution change
-        $self->prophet_handle->record_resolutions($conflict->resolution_changeset);
+        $self->prophet_handle->record_resolutions
+            ( $conflict->resolution_changeset,
+            $self->ressource ? $self->ressource->prophet_handle : $self->prophet_handle
+            );
     } else {
         $self->prophet_handle->integrate_changeset($changeset);
 
@@ -275,7 +281,7 @@
 sub remove_redundant_data {
     my ($self, $changeset) = @_;
     # XXX: encapsulation
-    $changeset->{changes} = [ grep { $_->node_type ne '_prophet_resolution' } grep {
+    $changeset->{changes} = [ grep { $self->is_resdb || $_->node_type ne '_prophet_resolution' } grep {
         !($_->node_type eq $Prophet::Handle::MERGETICKET_METATYPE &&
           $_->node_uuid eq $self->prophet_handle->uuid)
     } $changeset->changes ];

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 22:37:48 2008
@@ -87,29 +87,22 @@
     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 );
-
-    # asssuming reoslutions nodes are added
-    my @resolutions = grep { $_->node_type eq '_prophet_resolution' } map { $_->changes } @res;
-
-    # fake records
-    my @res_records = map { { conflict => $_->node_uuid,
-            resolutions => { map { $_->name => $_->new_value } $_->prop_changes } } }
-        @resolutions;
+    my $res = $target->fetch_resolutions( from => $source );
 
     $target->import_changesets(
         from => $source,
-        resolver => sub { my $conflict = shift;
-
-            # find the resolution for the matchign conflict
-            my ($res) = grep { $_->{conflict} eq $conflict->cas_key } @res_records or return;
+        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  => $res->{resolutions}{ $prop_conflict->name },
+                    new  => $answer->prop( $prop_conflict->name ),
                 );
             }
             return $resolution;



More information about the Bps-public-commit mailing list