[Bps-public-commit] r11276 - in SVN-PropDB: . bin lib/Prophet t
jesse at bestpractical.com
jesse at bestpractical.com
Sun Mar 30 18:06:35 EDT 2008
Author: jesse
Date: Sun Mar 30 18:06:35 2008
New Revision: 11276
Modified:
SVN-PropDB/ (props changed)
SVN-PropDB/bin/prophet-merge
SVN-PropDB/lib/Prophet/Conflict.pm
SVN-PropDB/lib/Prophet/ConflictingChange.pm
SVN-PropDB/lib/Prophet/Handle.pm
SVN-PropDB/lib/Prophet/Sync/Source/SVN.pm
SVN-PropDB/lib/Prophet/Test.pm
SVN-PropDB/t/cli.t
Log:
r28805 at 68-246-21-112: jesse | 2008-03-30 11:31:18 -1000
* import of a non-conflicting change no longer generates error. but does it import?
Modified: SVN-PropDB/bin/prophet-merge
==============================================================================
--- SVN-PropDB/bin/prophet-merge (original)
+++ SVN-PropDB/bin/prophet-merge Sun Mar 30 18:06:35 2008
@@ -9,11 +9,11 @@
my $opts = {};
-GetOptions( $opts, 'target=s', 'source=s' );
+GetOptions( $opts, 'from=s', 'to=s' );
validate_options($opts);
-my $target = Prophet::Sync::Source->new( { url => $opts->{'target'} } );
-my $source = Prophet::Sync::Source->new( { url => $opts->{'source'} } );
+my $target = Prophet::Sync::Source->new( { url => $opts->{'from'} } );
+my $source = Prophet::Sync::Source->new( { url => $opts->{'to'} } );
if ( $target->uuid eq $source->uuid ) {
fatal_error( "You appear to be trying to merge two identical replicas. "
@@ -31,7 +31,7 @@
sub validate_options {
my $opts = shift;
- for (qw(source target)) {
+ for (qw(from to)) {
die "You need to specify a --$_ url" unless ( $opts->{$_} );
}
}
Modified: SVN-PropDB/lib/Prophet/Conflict.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Conflict.pm (original)
+++ SVN-PropDB/lib/Prophet/Conflict.pm Sun Mar 30 18:06:35 2008
@@ -1,8 +1,9 @@
+
use warnings;
use strict;
package Prophet::Conflict;
-
+use Params::Validate;
use base qw/Class::Accessor/;
use Prophet::ConflictingPropChange;
use Prophet::ConflictingChange;
@@ -22,6 +23,10 @@
my ($changeset) = validate_pos( @_, { isa => 'Prophet::ChangeSet' } );
$self->generate_changeset_conflicts($changeset);
+ return unless (@{$self->conflicting_changes});
+
+ use Data::Dumper;
+ warn Dumper($self->conflicting_changes) if @{$self->conflicting_changes};
$self->generate_nullification_changeset;
$self->attempt_automatic_conflict_resolution;
@@ -66,7 +71,7 @@
# for everything from the changeset that is the same as the old value of the target replica
# we can skip applying
- die "have not implemented automatic conflict resolution yet";
+ Carp::cluck "have not implemented automatic conflict resolution yet";
$self->autoresolved(1);
@@ -102,32 +107,42 @@
sub _generate_change_conflicts {
my $self = shift;
my ($change) = validate_pos( @_, { isa => "Prophet::Change" } );
- my $current_state = $self->prophet_handle->get_node_props( uuid => $change->node_uuid, type => $change->node_type );
my $file_op_conflict = '';
-
+
+ my $file_exists = $self->prophet_handle->node_exists(uuid => $change->node_uuid, type => $change->node_type);
+
# It's ok to delete a node that exists
- if ( $change->change_type eq 'delete' && !keys %$current_state ) {
+ if ( $change->change_type eq 'delete' && !$file_exists ) {
$file_op_conflict = "delete_missing_file";
- } elsif ( $change->change_type eq 'update' && !keys %$current_state ) {
+ } elsif ( $change->change_type eq 'update' && !$file_exists) {
$file_op_conflict = "update_missing_file";
- } elsif ( $change->change_type eq 'add_file' && keys %$current_state ) {
+ } elsif ( $change->change_type eq 'add_file' && $file_exists) {
$file_op_conflict = "create_existing_file";
- } elsif ( $change->change_type eq 'add_dir' && keys %$current_state ) {
+ } elsif ( $change->change_type eq 'add_dir' && $file_exists) {
+ # XXX TODO: this isn't right
$file_op_conflict = "create_existing_dir";
}
+
+
+
+
my $change_conflict = Prophet::ConflictingChange->new(
{ node_type => $change->node_type,
node_uuid => $change->node_uuid,
- target_node_exists => ( keys %$current_state ? 1 : 0 ),
+ target_node_exists => $file_exists,
change_type => $change->change_type,
file_op_conflict => $file_op_conflict
}
);
- push @{ $change_conflict->prop_conflicts }, $self->_generate_prop_change_conflicts( $change, $current_state );
+ if ($file_exists) {
+ my $current_state = $self->prophet_handle->get_node_props( uuid => $change->node_uuid, type => $change->node_type );
- return ( $#{ $change_conflict->prop_conflicts } || $file_op_conflict ) ? $change_conflict : undef;
+ push @{ $change_conflict->prop_conflicts }, $self->_generate_prop_change_conflicts( $change, $current_state );
+ }
+
+ return ( @{ $change_conflict->prop_conflicts } || $file_op_conflict ) ? $change_conflict : undef;
}
@@ -176,7 +191,7 @@
sub conflicting_changes {
my $self = shift;
- $self->{'conflicting_changes'} ||= ();
+ $self->{'conflicting_changes'} ||= [];
return $self->{'conflicting_changes'};
}
Modified: SVN-PropDB/lib/Prophet/ConflictingChange.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/ConflictingChange.pm (original)
+++ SVN-PropDB/lib/Prophet/ConflictingChange.pm Sun Mar 30 18:06:35 2008
@@ -19,7 +19,7 @@
sub prop_conflicts {
my $self = shift;
- $self->{'prop_conflicts'} ||= ();
+ $self->{'prop_conflicts'} ||= [];
return $self->{prop_conflicts};
}
Modified: SVN-PropDB/lib/Prophet/Handle.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Handle.pm (original)
+++ SVN-PropDB/lib/Prophet/Handle.pm Sun Mar 30 18:06:35 2008
@@ -265,6 +265,7 @@
my $self = shift;
my %args = validate( @_, { uuid => 1, type => 1, root => undef } );
my $root = $args{'root'} || $self->current_root;
+ Carp::cluck unless $self->node_exists(%args);
return $root->node_proplist( $self->file_for( uuid => $args{'uuid'}, type => $args{'type'} ) );
}
@@ -282,6 +283,21 @@
}
+=head2 node_exists {uuid => $uuid, type => $type, root => $root }
+
+Returns true if the node in question exists. False otherwise
+
+=cut
+
+sub node_exists{
+ my $self = shift;
+ my %args = validate( @_, { uuid => 1, type => 1, root => undef } );
+
+ my $root = $args{'root'} || $self->current_root;
+ return $root->check_path( $self->file_for( uuid => $args{'uuid'}, type => $args{'type'} ) );
+
+}
+
our $MERGETICKET_METATYPE = '_merge_tickets';
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 18:06:35 2008
@@ -13,6 +13,7 @@
use Prophet::Sync::Source::SVN::ReplayEditor;
use Prophet::Sync::Source::SVN::Util;
use Prophet::ChangeSet;
+use Prophet::Conflict;
__PACKAGE__->mk_accessors(qw/url ra prophet_handle/);
Modified: SVN-PropDB/lib/Prophet/Test.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Test.pm (original)
+++ SVN-PropDB/lib/Prophet/Test.pm Sun Mar 30 18:06:35 2008
@@ -1,8 +1,10 @@
-package Prophet::Test;
use strict;
+use warnings;
+package Prophet::Test;
use base qw/Test::More Exporter/;
-our @EXPORT = qw/as_alice as_bob as_charlie as_david run_ok run_output_matches/;
+our @EXPORT = qw/as_alice as_bob as_charlie as_david run_ok run_script run_output_matches/;
+use File::Path 'rmtree';
use File::Temp qw/tempdir/;
use Path::Class 'dir';
use Test::Exception;
@@ -175,7 +177,6 @@
sub as_charlie(&) { as_user( charlie => shift) }
sub as_david(&) { as_user( david => shift) }
-use File::Path 'rmtree';
END {
for (qw(alice bob charlie david)) {
as_user( $_, sub { rmtree [ $ENV{'PROPHET_REPO'} ] } );
Modified: SVN-PropDB/t/cli.t
==============================================================================
--- SVN-PropDB/t/cli.t (original)
+++ SVN-PropDB/t/cli.t Sun Mar 30 18:06:35 2008
@@ -3,24 +3,39 @@
use warnings;
use strict;
-use Prophet::Test tests => 4;
+use Prophet::Test tests => 7;
as_alice {
- run_ok('prophet-node-create', [qw(--type Bug --status new)], "Created a record as alice");
+ run_ok('prophet-node-create', [qw(--type Bug --status new --from alice )], "Created a record as alice");
run_output_matches('prophet-node-search', [qw(--type Bug --regex .)], [qr/new/], " Found our record");
+ # update the node
+ # show the node history
+ # show the node
+
};
as_bob {
- run_ok('prophet-node-create', [qw(--type Bug --status open)], "Created a record as bob" );
+ run_ok('prophet-node-create', [qw(--type Bug --status open --from bob )], "Created a record as bob" );
run_output_matches('prophet-node-search', [qw(--type Bug --regex .)], [qr/open/], " Found our record");
+ # update the node
+ # show the node history
+ # show the node
+};
+
+as_alice {
+ # sync from bob
+ run_ok('prophet-merge', ['--from', Prophet::Test::repo_uri_for('bob'), '--to', Prophet::Test::repo_uri_for('alice')], "Sync ran ok!");
+ # check our local replica
+ my ($out, $err) = run_script('prophet-node-search', [qw(--type Bug --regex .)]);
+ like_ok($out, qr/open/) ;
+ like_ok($out, qr/new/) ;
+
};
+
# create 1 node
-# update the node
# search for the node
-# show the node history
-# show the node
#
# clone the replica to a second replica
# compare the second replica to the first replica
More information about the Bps-public-commit
mailing list