[Bps-public-commit] r11653 - in Prophet/trunk: . bin lib/Prophet/Replica t

jesse at bestpractical.com jesse at bestpractical.com
Tue Apr 8 19:10:00 EDT 2008


Author: jesse
Date: Tue Apr  8 19:09:58 2008
New Revision: 11653

Removed:
   Prophet/trunk/bin/prophet-merge
Modified:
   Prophet/trunk/   (props changed)
   Prophet/trunk/lib/Prophet/CLI.pm
   Prophet/trunk/lib/Prophet/Replica.pm
   Prophet/trunk/lib/Prophet/Replica/HTTP.pm
   Prophet/trunk/lib/Prophet/Replica/SVN.pm
   Prophet/trunk/lib/Prophet/Test.pm
   Prophet/trunk/t/non-conflicting-merge.t
   Prophet/trunk/t/simple-conflicting-merge.t
   Prophet/trunk/t/simple-push.t

Log:
 r29520 at 72-58-64-79:  jesse | 2008-04-08 19:07:43 -0400
 * Made prophet replica types configurable. (This required changing svn replica types to have a leading svn:)
 


Modified: Prophet/trunk/lib/Prophet/CLI.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI.pm	Tue Apr  8 19:09:58 2008
@@ -261,7 +261,7 @@
 
 sub do_push {
     my $self         = shift;
-    my $source_me    = Prophet::Replica->new( { url => "file://" . $self->handle->repo_path } );
+    my $source_me    = Prophet::Replica->new( { url => "svn:file://" . $self->handle->repo_path } );
     my $other        = shift @ARGV;
     my $source_other = Prophet::Replica->new( { url => $other } );
     my $resdb        = $source_me->import_resolutions_from_remote_replica( from => $source_other );
@@ -271,14 +271,14 @@
 
 sub do_export {
     my $self      = shift;
-    my $source_me = Prophet::Replica->new( { url => "file://" . $self->handle->repo_path } );
+    my $source_me = Prophet::Replica->new( { url => "svn:file://" . $self->handle->repo_path } );
     my $path      = $self->args->{'path'};
     $source_me->export_to( path => $path );
 }
 
 sub do_pull {
     my $self         = shift;
-    my $source_me    = Prophet::Replica->new( { url => "file://" . $self->handle->repo_path } );
+    my $source_me    = Prophet::Replica->new( { url => "svn:file://" . $self->handle->repo_path } );
     my $other        = shift @ARGV;
     my $source_other = Prophet::Replica->new( { url => $other } );
     my $resdb        = $source_me->import_resolutions_from_remote_replica( from => $source_other );

Modified: Prophet/trunk/lib/Prophet/Replica.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Replica.pm	(original)
+++ Prophet/trunk/lib/Prophet/Replica.pm	Tue Apr  8 19:09:58 2008
@@ -6,9 +6,14 @@
 use Params::Validate qw(:all);
 use UNIVERSAL::require;
 
-__PACKAGE__->mk_accessors(qw(state_handle ressource is_resdb));
+
+__PACKAGE__->mk_accessors(qw(state_handle ressource is_resdb url));
 
 use constant state_db_uuid => 'state';
+use Module::Pluggable search_path => 'Prophet::Replica', sub_name => 'core_replica_types', require => 1, except => qr/Prophet::Replica::(.*)::/;
+
+our $REPLICA_TYPE_MAP = {};
+ __PACKAGE__->register_replica_scheme(scheme => $_->scheme, class => $_) for ( __PACKAGE__->core_replica_types);
 
 =head1 NAME
 
@@ -16,7 +21,7 @@
 
 =head1 DESCRIPTION
                         
-A base class for all Prophet sync sources
+A base class for all Prophet replicas
 
 =cut
 
@@ -24,42 +29,54 @@
 
 =head2 new
 
-Instantiates a new sync source
+Instantiates a new replica
 
 =cut
 
 sub new {
     my $self = shift->SUPER::new(@_);
-    $self->rebless_to_replica_type(@_);
+    $self->_rebless_to_replica_type(@_);
     $self->setup();
     return $self;
 }
 
-=head2 rebless_to_replica_type
+=head2 register_replica_scheme { class=> Some::Perl::Class, scheme => 'scheme:' }
+
+B<Class Method>. Register a URI scheme C<scheme> to point to a replica object of type C<class>.
+
+=cut
+
+
+sub register_replica_scheme {
+    my $class = shift;
+    my %args = validate(@_, { class => 1, scheme => 1});
+
+    $Prophet::Replica::REPLICA_TYPE_MAP->{$args{'scheme'}} = $args{'class'};
+
+
+
+}
+
+
+=head2 _rebless_to_replica_type
 
-Reblesses this sync source into the right sort of sync source for whatever kind of replica $self->url points to
+Reblesses this replica into the right sort of replica for whatever kind of replica $self->url points to
 
 
 =cut
 
-sub rebless_to_replica_type {
+sub _rebless_to_replica_type {
     my $self = shift;
-    my $args = shift;
 
-    my $class;
 
-    # XXX TODO HACK NEED A PROPER WAY TO DETERMINE SYNC SOURCE
-    if ( $args->{url} =~ /^rt:/ ) {
-        $class = 'Prophet::Replica::RT';
-    } elsif ( $args->{url} =~ /^hm:/ ) {
-        $class = 'Prophet::Replica::Hiveminder';
-    } elsif ( $args->{url} =~ s/^prophet:// ) {
-        $class = 'Prophet::Replica::HTTP';
+    my ($scheme, $real_url) = split(/:/,$self->url,2);
+    $self->url($real_url);
+    if ( my $class = $Prophet::Replica::REPLICA_TYPE_MAP->{$scheme}) {
+    $class->require or die $@;
+    return bless $self, $class;
     } else {
-        $class = 'Prophet::Replica::SVN';
+        die "$scheme isn't a replica type I know how to handle";
     }
-    $class->require or die $@;
-    bless $self, $class;
 }
 
 sub import_changesets {

Modified: Prophet/trunk/lib/Prophet/Replica/HTTP.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Replica/HTTP.pm	(original)
+++ Prophet/trunk/lib/Prophet/Replica/HTTP.pm	Tue Apr  8 19:09:58 2008
@@ -14,6 +14,8 @@
 
 our $DEBUG = $Prophet::Handle::DEBUG;
 
+use constant scheme => 'prophet';
+
 =head2 setup
 
 Open a connection to the SVN source identified by C<$self->url>.

Modified: Prophet/trunk/lib/Prophet/Replica/SVN.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Replica/SVN.pm	(original)
+++ Prophet/trunk/lib/Prophet/Replica/SVN.pm	Tue Apr  8 19:09:58 2008
@@ -11,8 +11,9 @@
 use SVN::Delta;
 
 use Prophet::Handle;
-use Prophet::Replica::SVN::ReplayEditor;
-use Prophet::Replica::SVN::Util;
+# require rather than use to make them late-binding
+require Prophet::Replica::SVN::ReplayEditor;
+require Prophet::Replica::SVN::Util;
 use Prophet::ChangeSet;
 use Prophet::Conflict;
 
@@ -20,6 +21,9 @@
 
 our $DEBUG = $Prophet::Handle::DEBUG;
 
+use constant scheme => 'svn';
+
+
 =head2 setup
 
 Open a connection to the SVN source identified by C<$self->url>.
@@ -50,7 +54,7 @@
         return;
     }
 
-    my $res_url = $self->url;
+    my $res_url = "svn:".$self->url;
     $res_url =~ s/(\_res|)$/_res/;
     $self->ressource( __PACKAGE__->new( { url => $res_url, is_resdb => 1 } ) );
 }

Modified: Prophet/trunk/lib/Prophet/Test.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Test.pm	(original)
+++ Prophet/trunk/lib/Prophet/Test.pm	Tue Apr  8 19:09:58 2008
@@ -205,7 +205,7 @@
     my $path = repo_path_for($username);
     $path =~ s{^|\\}{/}g if IS_WIN32;
 
-    return 'file://' . $path;
+    return 'svn:file://' . $path;
 }
 
 sub replica_uuid {

Modified: Prophet/trunk/t/non-conflicting-merge.t
==============================================================================
--- Prophet/trunk/t/non-conflicting-merge.t	(original)
+++ Prophet/trunk/t/non-conflicting-merge.t	Tue Apr  8 19:09:58 2008
@@ -28,7 +28,7 @@
 
     # sync from bob
     diag('Alice syncs from bob');
-    run_ok( 'prophet-merge', [ '--from', repo_uri_for('bob'), '--to', repo_uri_for('alice') ], "Sync ran ok!" );
+    run_ok( 'prophet', [ 'merge',  '--from', repo_uri_for('bob'), '--to', repo_uri_for('alice') ], "Sync ran ok!" );
 
     # check our local replicas
     my ( $ret, $out, $err ) = run_script( 'prophet-node-search', [qw(--type Bug --regex .)] );
@@ -42,7 +42,7 @@
     diag('Alice syncs from bob again. There will be no new changes from bob');
 
     # sync from bob
-    run_ok( 'prophet-merge', [ '--from', repo_uri_for('bob'), '--to', repo_uri_for('alice') ], "Sync ran ok!" );
+    run_ok( 'prophet', [ 'merge',  '--from', repo_uri_for('bob'), '--to', repo_uri_for('alice') ], "Sync ran ok!" );
 
     # check our local replicas
     ( $ret, $out, $err ) = run_script( 'prophet-node-search', [qw(--type Bug --regex .)] );
@@ -66,7 +66,7 @@
 
     # sync from alice
 
-    run_ok( 'prophet-merge', [ '--to', repo_uri_for('bob'), '--from', repo_uri_for('alice') ], "Sync ran ok!" );
+    run_ok( 'prophet', [ 'merge',  '--to', repo_uri_for('bob'), '--from', repo_uri_for('alice') ], "Sync ran ok!" );
 
     # check our local replicas
     ( $ret, $out, $err ) = run_script( 'prophet-node-search', [qw(--type Bug --regex .)] );
@@ -79,7 +79,7 @@
     $last_rev = replica_last_rev();
 
     diag('Sync from alice to bob again');
-    run_ok( 'prophet-merge', [ '--to', repo_uri_for('bob'), '--from', repo_uri_for('alice') ], "Sync ran ok!" );
+    run_ok( 'prophet', [ 'merge',  '--to', repo_uri_for('bob'), '--from', repo_uri_for('alice') ], "Sync ran ok!" );
 
     is_deeply( replica_merge_tickets(), { replica_uuid_for('alice') => as_alice { replica_last_rev() - 1 } } );
     is( replica_last_rev(), $last_rev, "We have not recorded another transaction after a second sync" );
@@ -88,7 +88,7 @@
 
 as_alice {
     my $last_rev = replica_last_rev();
-    run_ok( 'prophet-merge', [ '--to', repo_uri_for('alice'), '--from', repo_uri_for('bob') ], "Sync ran ok!" );
+    run_ok( 'prophet', [ 'merge',  '--to', repo_uri_for('alice'), '--from', repo_uri_for('bob') ], "Sync ran ok!" );
     is( replica_last_rev(), $last_rev,
         "We have not recorded another transaction after bob had fully synced from alice" );
 

Modified: Prophet/trunk/t/simple-conflicting-merge.t
==============================================================================
--- Prophet/trunk/t/simple-conflicting-merge.t	(original)
+++ Prophet/trunk/t/simple-conflicting-merge.t	Tue Apr  8 19:09:58 2008
@@ -19,7 +19,7 @@
 
     run_ok( 'prophet-node-create', [qw(--type Dummy --ignore yes)], "Created a dummy record" );
 
-    run_ok( 'prophet-merge', [ '--to', repo_uri_for('bob'), '--from', repo_uri_for('alice') ], "Sync ran ok!" );
+    run_ok( 'prophet', [ 'merge',  '--to', repo_uri_for('bob'), '--from', repo_uri_for('alice') ], "Sync ran ok!" );
 
     # check our local replicas
     my ( $ret, $out, $err ) = run_script( 'prophet-node-search', [qw(--type Bug --regex .)] );

Modified: Prophet/trunk/t/simple-push.t
==============================================================================
--- Prophet/trunk/t/simple-push.t	(original)
+++ Prophet/trunk/t/simple-push.t	Tue Apr  8 19:09:58 2008
@@ -3,7 +3,7 @@
 use warnings;
 use strict;
 
-use Prophet::Test tests => 10;
+use Prophet::Test tests => 9;
 
 as_alice {
     run_ok( 'prophet-node-create', [qw(--type Bug --status new --from alice )], "Created a record as alice" );
@@ -24,7 +24,6 @@
 
 };
 
-use_ok('Prophet::Replica::SVN');
 
 my $alice = Prophet::Replica->new( { url => repo_uri_for('alice') } );
 my $bob   = Prophet::Replica->new( { url => repo_uri_for('bob') } );
@@ -95,7 +94,7 @@
 
     # sync from bob
     diag('Alice syncs from bob');
-    run_ok( 'prophet-merge', [ '--from', repo_uri_for('bob'), '--to', repo_uri_for('alice') ], "Sync ran ok!" );
+    run_ok( 'prophet', [ 'merge', '--from', repo_uri_for('bob'), '--to', repo_uri_for('alice') ], "Sync ran ok!" );
 };
 
 my $last_id;



More information about the Bps-public-commit mailing list