[Bps-public-commit] r11526 - in SVN-PropDB: bin lib/Prophet lib/Prophet/Resolver lib/Prophet/Sync lib/Prophet/Sync/Source t
jesse at bestpractical.com
jesse at bestpractical.com
Sat Apr 5 00:40:31 EDT 2008
Author: jesse
Date: Sat Apr 5 00:40:28 2008
New Revision: 11526
Modified:
SVN-PropDB/ (props changed)
SVN-PropDB/bin/prophet-merge
SVN-PropDB/lib/Prophet/CLI.pm
SVN-PropDB/lib/Prophet/Handle.pm
SVN-PropDB/lib/Prophet/Resolver/FromResolutionDB.pm
SVN-PropDB/lib/Prophet/Sync/Source.pm
SVN-PropDB/lib/Prophet/Sync/Source/RT.pm
SVN-PropDB/lib/Prophet/Sync/Source/SVN.pm
SVN-PropDB/t/real-conflicting-merge.t
Log:
r29225 at 68-246-40-124: jesse | 2008-04-04 18:40:15 -1000
* back to passing tests with refactored and extracted resdb handling
Modified: SVN-PropDB/bin/prophet-merge
==============================================================================
--- SVN-PropDB/bin/prophet-merge (original)
+++ SVN-PropDB/bin/prophet-merge Sat Apr 5 00:40:28 2008
@@ -27,8 +27,8 @@
fatal_error( $target->url . " does not accept changesets. Perhaps it's unwritable or something" );
}
+$target->import_resolutions_from_remote_replica( from => $source );
$target->import_changesets( from => $source,
- use_resdb => 1,
$ENV{'PROPHET_RESOLVER'} ?
(resolver_class => 'Prophet::Resolver::'.$ENV{'PROPHET_RESOLVER'}) :
(
Modified: SVN-PropDB/lib/Prophet/CLI.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/CLI.pm (original)
+++ SVN-PropDB/lib/Prophet/CLI.pm Sat Apr 5 00:40:28 2008
@@ -173,24 +173,24 @@
}
sub do_create {
- my $cli = shift;
- my $record = $cli->_get_record;
+ my $self = shift;
+ my $record = $self->_get_record;
- $record->create( props => $cli->args );
+ $record->create( props => $self->args );
print "Created " . $record->record_type . " " . $record->uuid . "\n";
}
sub do_search {
- my $cli = shift;
+ my $self = shift;
my $regex;
- unless ( $regex = $cli->args->{regex} ) {
+ unless ( $regex = $self->args->{regex} ) {
die "Specify a regular expression and we'll search for records matching that regex";
}
- my $record = $cli->_get_record;
- my $records = $record->collection_class->new( handle => $cli->handle, type => $cli->type );
+ my $record = $self->_get_record;
+ my $records = $record->collection_class->new( handle => $self->handle, type => $self->type );
$records->matching(
sub {
my $item = shift;
@@ -206,19 +206,19 @@
}
sub do_update {
- my $cli = shift;
+ my $self = shift;
- my $record = $cli->_get_record;
- $record->load( uuid => $cli->uuid );
- $record->set_props( props => $cli->args );
+ my $record = $self->_get_record;
+ $record->load( uuid => $self->uuid );
+ $record->set_props( props => $self->args );
}
sub do_delete {
- my $cli = shift;
+ my $self = shift;
- my $record = $cli->_get_record;
- $record->load( uuid => $cli->uuid );
+ my $record = $self->_get_record;
+ $record->load( uuid => $self->uuid );
if ( $record->delete ) {
print $record->type . " " . $record->uuid . " deleted.\n";
} else {
@@ -228,10 +228,10 @@
}
sub do_show {
- my $cli = shift;
+ my $self = shift;
- my $record = $cli->_get_record;
- $record->load( uuid => $cli->uuid );
+ my $record = $self->_get_record;
+ $record->load( uuid => $self->uuid );
print "id: " . $record->uuid . "\n";
my $props = $record->get_props();
for ( keys %$props ) {
@@ -240,27 +240,60 @@
}
+sub do_push {
+ my $self = shift;
+ my $source_me = Prophet::Sync::Source->new( { url => "file://".$self->handle->repo_path } );
+ my $other = shift @ARGV;
+ my $source_other = Prophet::Sync::Source->new( { url => $other } );
+ my $resdb = $source_me->import_resolutions_from_remote_replica( from => $source_other );
+
+ $self->_do_merge( $source_me, $source_other );
+}
+
+sub do_pull {
+ my $self = shift;
+ my $source_me = Prophet::Sync::Source->new( { url => "file://".$self->handle->repo_path } );
+ my $other = shift @ARGV;
+ my $source_other = Prophet::Sync::Source->new( { url => $other } );
+ my $resdb = $source_me->import_resolutions_from_remote_replica( from => $source_other );
+
+ $self->_do_merge( $source_other, $source_me );
+
+}
+
+
sub do_merge {
- my $cli = shift;
+ my $self = shift;
- my $opts = $cli->args();
+ my $opts = $self->args();
my $source = Prophet::Sync::Source->new( { url => $opts->{'from'} } );
my $target = Prophet::Sync::Source->new( { url => $opts->{'to'} } );
+
+ $target->import_resolutions_from_remote_replica( from => $source );
+
+ $self->_do_merge( $source, $target);
+}
+
+sub _do_merge {
+ my ($self, $source, $target) = @_;
if ( $target->uuid eq $source->uuid ) {
fatal_error( "You appear to be trying to merge two identical replicas. "
. "Either you're trying to merge a replica to itself or "
. "someone did a bad job cloning your database" );
}
+ my $opts = $self->args();
+
+
if ( !$target->accepts_changesets ) {
fatal_error( $target->url . " does not accept changesets. Perhaps it's unwritable or something" );
}
$target->import_changesets(
from => $source,
- use_resdb => 1,
+ resdb => $self->resdb_handle,
$ENV{'PROPHET_RESOLVER'}
? ( resolver_class => 'Prophet::Resolver::' . $ENV{'PROPHET_RESOLVER'} )
: ( ( $opts->{'prefer'} eq 'to' ? ( resolver_class => 'Prophet::Resolver::AlwaysTarget' ) : () ),
Modified: SVN-PropDB/lib/Prophet/Handle.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Handle.pm (original)
+++ SVN-PropDB/lib/Prophet/Handle.pm Sat Apr 5 00:40:28 2008
@@ -434,6 +434,9 @@
}
+
+
+
use YAML::Syck;
package YAML;
Modified: SVN-PropDB/lib/Prophet/Resolver/FromResolutionDB.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Resolver/FromResolutionDB.pm (original)
+++ SVN-PropDB/lib/Prophet/Resolver/FromResolutionDB.pm Sat Apr 5 00:40:28 2008
@@ -13,7 +13,7 @@
my $resdb = shift; # XXX: we want diffrent collection actually now
my $res = Prophet::Collection->new(
- handle => $resdb->handle,
+ handle => $resdb,
type => '_prophet_resolution-' . $conflicting_change->cas_key
);
$res->matching( sub {1} );
Modified: SVN-PropDB/lib/Prophet/Sync/Source.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Sync/Source.pm (original)
+++ SVN-PropDB/lib/Prophet/Sync/Source.pm Sat Apr 5 00:40:28 2008
@@ -6,6 +6,8 @@
use Params::Validate qw(:all);
use UNIVERSAL::require;
+__PACKAGE__->mk_accessors(qw(state_handle));
+
=head1 NAME
Prophet::Sync::Source
@@ -61,7 +63,7 @@
my %args = validate(
@_,
{ from => { isa => 'Prophet::Sync::Source' },
- use_resdb => { optional => 1 },
+ resdb => { optional => 1 },
resolver => { optional => 1 },
resolver_class => { optional => 1 },
conflict_callback => { optional => 1 },
@@ -71,8 +73,6 @@
my $source = $args{'from'};
- my $resdb = $args{use_resdb} ? $self->fetch_resolutions( from => $source ) : undef;
-
my $changesets_to_integrate = $source->new_changesets_for($self);
for my $changeset (@$changesets_to_integrate) {
@@ -82,12 +82,38 @@
reporting_callback => $args{'reporting_callback'},
resolver => $args{resolver},
resolver_class => $args{'resolver_class'},
- resdb => $resdb
+ resdb => $args{'resdb'},
);
}
}
+sub import_resolutions_from_remote_replica {
+ my $self = shift;
+ my %args = validate(
+ @_,
+ { from => { isa => 'Prophet::Sync::Source' },
+ resolver => { optional => 1 },
+ resolver_class => { optional => 1 },
+ conflict_callback => { optional => 1 }
+ }
+ );
+ my $source = $args{'from'};
+
+ return unless $self->ressource;
+
+ $self->ressource->import_changesets(
+ from => $source->ressource,
+ resolver => sub { die "nono not yet" }
+
+ );
+}
+
+
+
+
+
+
=head2 integrate_changeset L<Prophet::ChangeSet>
If there are conflicts, generate a nullification change, figure out a conflict resolution and apply the nullification, original change and resolution all at once (as three separate changes).
@@ -266,29 +292,6 @@
];
}
-sub fetch_resolutions {
- my $self = shift;
- my %args = validate(
- @_,
- { from => { isa => 'Prophet::Sync::Source' },
- resolver => { optional => 1 },
- resolver_class => { optional => 1 },
- conflict_callback => { optional => 1 }
- }
- );
- my $source = $args{'from'};
-
- 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;
-}
=head2 news_changesets_for Prophet::Sync::Source
Modified: SVN-PropDB/lib/Prophet/Sync/Source/RT.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Sync/Source/RT.pm (original)
+++ SVN-PropDB/lib/Prophet/Sync/Source/RT.pm Sat Apr 5 00:40:28 2008
@@ -24,6 +24,8 @@
If the remote storage (RT) can not represent a whole changeset along with the prophet changeset uuid, then we need to
create a seperate locally(?) stored map of:
remote-subchangeset-identifier to changeset uuid.
+ remote id to prophet record uuid
+
For each sync of the same remote source (RT), we need a unique prophet database domain.
@@ -32,6 +34,10 @@
+
+
+
+
Push to rt algorithm
apply a single changeset that's part of the push:
@@ -185,9 +191,41 @@
sub uuid_for_remote_id {
my ( $self, $id ) = @_;
- return $TICKET_CACHE->get( $self->uuid . '-ticket-' . $id ) || $self->uuid_for_url( $self->rt_url . "/ticket/$id" );
+ warn "We are trying to look up a remote id for $id";
+ warn " The one we have stored in the state db is ". $self->_lookup_remote_id($id);
+ return $self->_lookup_remote_id($id)|| $self->uuid_for_url( $self->rt_url . "/ticket/$id" );
}
+our $REMOTE_ID_METATYPE = "_remote_id_map";
+
+sub _lookup_remote_id {
+ my $self = shift;
+ my ($id) = validate_pos(@_, 1);
+
+ my $remote_id = Prophet::Record->new( handle => $self->state_handle, type => $REMOTE_ID_METATYPE);
+ $remote_id->load(uuid => $self->uuid_for_url( $self->rt_url . "/ticket/$id" )); # FAILURE IS OK
+ return eval {$remote_id->prop('prophet-uuid')};
+}
+
+
+sub _set_remote_id {
+ my $self = shift;
+ my %args = validate(
+ @_,
+ { uuid => 1,
+ remote_id => 1
+ }
+ );
+ $self->state_handle->create_node( uuid => $self->uuid_for_url( $self->rt_url . "/ticket/".$args{'remote_id'} ),
+ type => $REMOTE_ID_METATYPE, props => {
+ 'prophet-uuid' => $args{'uuid'}
+
+
+ } )
+
+}
+
+
sub record_pushed_ticket {
my $self = shift;
my %args = validate(
@@ -196,8 +234,7 @@
remote_id => 1
}
);
-
- $TICKET_CACHE->set( $self->uuid . '-ticket-' . $args{remote_id} => $args{uuid} );
+ $self->_set_remote_id(%args);
}
sub _integrate_change {
@@ -208,7 +245,6 @@
if ( $change->node_type eq 'ticket' and $change->change_type eq 'add_file' )
{
$id = $self->integrate_ticket_create( $change, $changeset );
-
$self->record_pushed_ticket( uuid => $change->node_uuid, remote_id => $id );
} elsif ( $change->node_type eq 'comment' ) {
@@ -344,9 +380,14 @@
$self->{___Orz} = $orz;
SVN::Repos::create( $orz, undef, undef, undef, undef );
$self->ressource( __PACKAGE__->new( { url => "file://$orz", is_resdb => 1 } ) );
+
+ warn "WE NEED A STATE HANDLE FOR REAL";
+ my $cli = Prophet::CLI->new();
+ $self->state_handle($cli->_handle);
+
}
-sub fetch_resolutions { warn 'no resdb'; return }
+sub import_resolutions_from_remote_source { warn 'no resdb'; return }
=head2 uuid
@@ -397,7 +438,6 @@
};
}
- # warn YAML::Dump(\@changesets);
return [ sort { $a->original_sequence_no <=> $b->original_sequence_no } @changesets ];
}
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 Sat Apr 5 00:40:28 2008
@@ -44,6 +44,7 @@
$self->ra( $self->_get_ra );
if ( $self->url =~ /^file:\/\/(.*)$/ ) {
$self->prophet_handle( Prophet::Handle->new( { repository => $1 } ) );
+ $self->state_handle( $self->prophet_handle );
}
if ( $self->is_resdb ) {
@@ -176,6 +177,10 @@
$self->prophet_handle->record_changeset(@_);
}
+
+
+
+
sub record_resolutions {
my $self = shift;
$self->prophet_handle->record_resolutions( @_,
Modified: SVN-PropDB/t/real-conflicting-merge.t
==============================================================================
--- SVN-PropDB/t/real-conflicting-merge.t (original)
+++ SVN-PropDB/t/real-conflicting-merge.t Sat Apr 5 00:40:28 2008
@@ -103,9 +103,11 @@
}
qr/not resolved/;
+ $target->import_resolutions_from_remote_replica( from => $source );
+
$target->import_changesets(
from => $source,
- use_resdb => 1,
+ resdb => $target->ressource->prophet_handle,
);
lives_and {
More information about the Bps-public-commit
mailing list