[Bps-public-commit] r11285 - in SVN-PropDB: . lib/Prophet lib/Prophet/Sync/Source t
jesse at bestpractical.com
jesse at bestpractical.com
Sun Mar 30 23:40:22 EDT 2008
Author: jesse
Date: Sun Mar 30 23:40:22 2008
New Revision: 11285
Modified:
SVN-PropDB/ (props changed)
SVN-PropDB/lib/Prophet/Conflict.pm
SVN-PropDB/lib/Prophet/Sync/Source.pm
SVN-PropDB/lib/Prophet/Sync/Source/SVN.pm
SVN-PropDB/lib/Prophet/Test.pm
SVN-PropDB/t/simple-conflicting-merge.t
Log:
r28823 at 99-201-75-80: jesse | 2008-03-30 17:39:32 -1000
* more work on conflicts
Modified: SVN-PropDB/lib/Prophet/Conflict.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Conflict.pm (original)
+++ SVN-PropDB/lib/Prophet/Conflict.pm Sun Mar 30 23:40:22 2008
@@ -167,7 +167,7 @@
my $s = {
name => $prop_change->name,
source_old_value => $prop_change->old_value,
- target_old_value => $current_state->{ $prop_change->name },
+ target_value => $current_state->{ $prop_change->name },
source_new_value => $prop_change->new_value
};
Modified: SVN-PropDB/lib/Prophet/Sync/Source.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Sync/Source.pm (original)
+++ SVN-PropDB/lib/Prophet/Sync/Source.pm Sun Mar 30 23:40:22 2008
@@ -3,7 +3,7 @@
package Prophet::Sync::Source;
use base qw/Class::Accessor/;
-use Params::Validate;
+use Params::Validate qw(:all);
=head1 NAME
@@ -11,7 +11,7 @@
Prophet::Sync::Source
=head1 DESCRIPTION
-
+
A base class for all Prophet sync sources
=cut
@@ -50,27 +50,17 @@
sub import_changesets {
my $self = shift;
- my %args = validate( @_, { from => 1 } );
+ my %args = validate( @_, { from => { isa => 'Prophet::Sync::Source'},
+ conflict_callback => { optional => 1 } } );
my $source = $args{'from'};
my $changesets_to_integrate
= $source->fetch_changesets( after => $self->last_changeset_from_source( $source->uuid ) );
for my $changeset (@$changesets_to_integrate) {
-# use Data::Dumper;warn Dumper($changeset) if ($DEBUG);
-
+
next if ( $self->has_seen_changeset($changeset) );
- if ( $self->changeset_will_conflict($changeset) ) {
-
- my $conflicts = $self->conflicts_from_changeset($changeset);
-
- # write out a nullification changeset beforehand,
- # - that way, the source update will apply cleanly
- # Then write out the source changeset
- # Then write out a new changeset which reverts the parts of the source changeset which target should win
- } else {
- $self->integrate_changeset($changeset);
- }
+ $self->integrate_changeset( changeset => $changeset, conflict_callback =>$args{conflict_callback});
}
}
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 Sun Mar 30 23:40:22 2008
@@ -218,7 +218,14 @@
sub integrate_changeset {
my $self = shift;
- my ($changeset) = validate_pos(@_, { isa => 'Prophet::ChangeSet'});
+ my %args = validate( @_, { changeset => {isa => 'Prophet::ChangeSet'},
+ conflict_callback => { optional => 1 }
+ }
+ );
+
+
+ my $changeset = $args{'changeset'};
+
=begin comment
@@ -234,22 +241,27 @@
# we'll want to skip or remove those changesets
-=cut
+=cut
+
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 ) ) {
+
+ $args{conflict_callback}->($conflict) if $args{'conflict_callback'};
+ Carp::cluck;
#figure out our conflict resolution
- # generate a nullification change
- # IMPORTANT: these should be an atomic unit. dying here would be poor.
- # BUT WE WANT THEM AS THREEDIFFERENT SVN REVS
+
+
+
+ # IMPORTANT: these should be an atomic unit. dying here would be poor. BUT WE WANT THEM AS THREEDIFFERENT SVN REVS
#integrate the nullification change
# integrate the original change
# integrate the conflict resolution change
} else {
- $self->prophet_handle->integrate_changeset(@_);
+ $self->prophet_handle->integrate_changeset($changeset);
}
}
Modified: SVN-PropDB/lib/Prophet/Test.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Test.pm (original)
+++ SVN-PropDB/lib/Prophet/Test.pm Sun Mar 30 23:40:22 2008
@@ -54,6 +54,7 @@
my @cmd = _get_perl_cmd($script);
my $ret = run3 [@cmd, @$args], undef, \$stdout, \$stderr;
Carp::croak $stderr if $?;
+ Test::More::diag $stderr;
return($ret, $stdout, $stderr);
}
Modified: SVN-PropDB/t/simple-conflicting-merge.t
==============================================================================
--- SVN-PropDB/t/simple-conflicting-merge.t (original)
+++ SVN-PropDB/t/simple-conflicting-merge.t Sun Mar 30 23:40:22 2008
@@ -3,7 +3,7 @@
use warnings;
use strict;
-use Prophet::Test tests => 9;
+use Prophet::Test tests => 20;
as_alice {
run_ok('prophet-node-create', [qw(--type Bug --status new --from alice )], "Created a record as alice");
@@ -35,15 +35,58 @@
};
as_alice {
- run_ok('prophet-node-update', ['--type','Bug','--uuid',$record_id, '--status' => 'closed']);
- my ($ret,$out,$err)= run_script('prophet-node-show', ['--type','Bug','--uuid',$record_id]);
- diag($out);
+ run_ok('prophet-node-update', ['--type','Bug','--uuid',$record_id, '--status' => 'stalled']);
+ run_output_matches('prophet-node-show', ['--type', 'Bug', '--uuid', $record_id],
+ ['id: '.$record_id, 'status: stalled', 'from: alice'],
+ 'content is correct');
};
+# This conflict, we can autoresolve
+
as_bob {
# XXX TODO: this should actually fail right now.
- run_ok('prophet-merge', ['--to', repo_uri_for('bob'), '--from', repo_uri_for('alice')], "Sync ran ok!");
+ # in perl code, we're going to run the merge (just as prophet-merge does)
+
+ use_ok('Prophet::Sync::Source::SVN' );
+
+ my $source = Prophet::Sync::Source->new( { url => repo_uri_for('alice') } );
+ my $target = Prophet::Sync::Source->new( { url => repo_uri_for('bob')} );
+
+ eval {
+ $target->import_changesets( from => $source , conflict_callback=> sub {
+
+ my $conflict_obj = shift;
+ isa_ok($conflict_obj, 'Prophet::Conflict');
+
+ my @conflicting_changes = @{$conflict_obj->conflicting_changes};
+ is($#conflicting_changes, 0, "Only one conflicting change");
+ my $change = shift @conflicting_changes;
+ isa_ok($change, 'Prophet::ConflictingChange');
+ is($change->change_type, 'update_file');
+ my @prop_conflicts = @{$change->prop_conflicts};
+ is($#prop_conflicts, 0, "Found one prop conflict");
+ my $c = shift @prop_conflicts;
+ isa_ok($c, 'Prophet::ConflictingPropChange');
+ is($c->name, 'status');
+ is($c->source_old_value, 'new');
+ is($c->source_new_value,'stalled');
+ is($c->target_value,'stalled');
+ die;
+
+ });
+ };
+ # Throw away the return. we wanted to inspect the conflict but not apply anything
+
+
+
+
+
+ # at the first sign of conflict, we're going to call back to a routine we inject to see if the conflict object is as we expect it
+ # Then we'll inject a hard-coded resolution into the conflict object
+ # then we'll let the code finish applying it.
+ # Then we'll check that bob's current state is right and that bob has a merge-ticket from alice
+
};
More information about the Bps-public-commit
mailing list