[Bps-public-commit] r14797 - in Prophet/trunk: . lib/Prophet/CLI/Command lib/Prophet/Replica t

sartak at bestpractical.com sartak at bestpractical.com
Tue Aug 5 15:09:29 EDT 2008


Author: sartak
Date: Tue Aug  5 15:09:28 2008
New Revision: 14797

Modified:
   Prophet/trunk/   (props changed)
   Prophet/trunk/lib/Prophet/CLI/Command/History.pm
   Prophet/trunk/lib/Prophet/ChangeSet.pm
   Prophet/trunk/lib/Prophet/Conflict.pm
   Prophet/trunk/lib/Prophet/Replica.pm
   Prophet/trunk/lib/Prophet/Replica/Native.pm
   Prophet/trunk/lib/Prophet/Replica/SVN.pm
   Prophet/trunk/t/publish-pull.t
   Prophet/trunk/t/real-conflicting-merge.t
   Prophet/trunk/t/simple-conflicting-merge.t
   Prophet/trunk/t/simple-push.t

Log:
Merge creator branch to trunk

Modified: Prophet/trunk/lib/Prophet/CLI/Command/History.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/History.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/History.pm	Tue Aug  5 15:09:28 2008
@@ -20,6 +20,7 @@
 
         # separate each changeset
         print "Changeset ".$changeset->original_sequence_no .'@'.$changeset->original_source_uuid."\n";
+        print "by " . $changeset->creator . '@' . $changeset->original_source_uuid."\n";
         print "\n";
 
         for my $prop_change (@prop_changes) {

Modified: Prophet/trunk/lib/Prophet/ChangeSet.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/ChangeSet.pm	(original)
+++ Prophet/trunk/lib/Prophet/ChangeSet.pm	Tue Aug  5 15:09:28 2008
@@ -4,6 +4,24 @@
 use Prophet::Change;
 use Params::Validate;
 
+has creator => (
+    is  => 'rw',
+    isa => 'Maybe[Str]',
+);
+
+has created => (
+    is      => 'rw',
+    isa     => 'Maybe[Str]',
+    default => sub {
+        my ($sec, $min, $hour, $day, $month, $year) = gmtime;
+        $year += 1900;
+        $month--;
+        return sprintf '%04d-%02d-%02d %02d:%02d:%02d',
+            $year, $month, $day,
+            $hour, $min, $sec;
+    },
+);
+
 has source_uuid => (
     is  => 'rw',
     isa => 'Str',
@@ -118,7 +136,7 @@
 =cut
 
 our @SERIALIZE_PROPS
-    = (qw(sequence_no source_uuid original_source_uuid original_sequence_no is_nullification is_resolution));
+    = (qw(creator created sequence_no source_uuid original_source_uuid original_sequence_no is_nullification is_resolution));
 
 sub as_hash {
     my $self = shift;

Modified: Prophet/trunk/lib/Prophet/Conflict.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Conflict.pm	(original)
+++ Prophet/trunk/lib/Prophet/Conflict.pm	Tue Aug  5 15:09:28 2008
@@ -82,7 +82,10 @@
         $self->resolvers,
         sub { Prophet::Resolver::Failed->new->run(@_) },
     );
-    my $resolutions = Prophet::ChangeSet->new( { is_resolution => 1 } );
+    my $resolutions = Prophet::ChangeSet->new({
+        creator       => $self->prophet_handle->changeset_creator,
+        is_resolution => 1,
+    });
     for my $conflicting_change ( @{ $self->conflicting_changes } ) {
         for (@resolvers) {
             if ( my $resolution = $_->( $conflicting_change, $self, $resdb ) ) {
@@ -206,7 +209,11 @@
 
 sub generate_nullification_changeset {
     my $self = shift;
-    my $nullification = Prophet::ChangeSet->new( { is_nullification => 1 } );
+    my $nullification = Prophet::ChangeSet->new({
+        is_nullification => 1,
+        creator => undef,
+        created => undef,
+    });
 
     for my $conflict ( @{ $self->conflicting_changes } ) {
         my $nullify_conflict

Modified: Prophet/trunk/lib/Prophet/Replica.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Replica.pm	(original)
+++ Prophet/trunk/lib/Prophet/Replica.pm	Tue Aug  5 15:09:28 2008
@@ -296,13 +296,13 @@
     my $self      = shift;
     my $changeset = shift;
 
-    $self->begin_edit;
+    $self->begin_edit(source => $changeset);
     $self->record_changes($changeset);
 
     my $state_handle = $self->state_handle;
     my $inside_edit = $state_handle->current_edit ? 1 : 0;
 
-    $state_handle->begin_edit() unless ($inside_edit);
+    $state_handle->begin_edit(source => $changeset) unless ($inside_edit);
     $state_handle->record_integration_of_changeset($changeset);
     $state_handle->commit_edit() unless ($inside_edit);
     $self->_set_original_source_metadata_for_current_edit($changeset);
@@ -462,7 +462,7 @@
     );
 }
 
-=head2 news_changesets_for Prophet::Replica
+=head2 new_changesets_for Prophet::Replica
 
 DEPRECATED: use traverse_new_changesets instead
 
@@ -771,7 +771,7 @@
 
     return unless $changeset->has_changes;
 
-    $self->begin_edit();
+    $self->begin_edit(source => $changeset);
     $self->record_changes($changeset);
     $res_handle->_record_resolution($_) for $changeset->changes;
     $self->commit_edit();
@@ -813,7 +813,7 @@
     $self->_unimplemented ('record_changes') unless ($self->can_write_changesets);
     eval {
         my $inside_edit = $self->current_edit ? 1 : 0;
-        $self->begin_edit() unless ($inside_edit);
+        $self->begin_edit(source => $changeset) unless ($inside_edit);
         $self->integrate_changes($changeset);
         $self->_after_record_changes($changeset);
         $self->commit_edit() unless ($inside_edit);
@@ -1029,6 +1029,8 @@
     Carp::confess(@_);
 }
 
+sub changeset_creator { $ENV{PROPHET_USER} || $ENV{USER} }
+
 __PACKAGE__->meta->make_immutable;
 no Moose;
 

Modified: Prophet/trunk/lib/Prophet/Replica/Native.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Replica/Native.pm	(original)
+++ Prophet/trunk/lib/Prophet/Replica/Native.pm	Tue Aug  5 15:09:28 2008
@@ -659,8 +659,21 @@
 
 sub begin_edit {
     my $self = shift;
-    $self->current_edit(
-        Prophet::ChangeSet->new( { source_uuid => $self->uuid } ) );
+    my %args = validate(@_, {
+        source => 0, # the changeset that we're replaying, if applicable
+    });
+
+    my $source = $args{source};
+
+    my $creator = $source ? $source->creator : $self->changeset_creator;
+    my $created = $source && $source->created;
+
+    my $changeset = Prophet::ChangeSet->new({
+        source_uuid => $self->uuid,
+        creator     => $creator,
+        $created ? (created => $created) : (),
+    });
+    $self->current_edit($changeset);
     $self->current_edit_records([]);
 
 }

Modified: Prophet/trunk/lib/Prophet/Replica/SVN.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Replica/SVN.pm	(original)
+++ Prophet/trunk/lib/Prophet/Replica/SVN.pm	Tue Aug  5 15:09:28 2008
@@ -145,16 +145,15 @@
     my $self      = shift;
     my $entry     = shift;
     my $revprops  = shift;
-    my $changeset = Prophet::ChangeSet->new(
-        {   sequence_no          => $entry->{'revision'},
-            source_uuid          => $self->uuid,
-            original_source_uuid => $revprops->{'prophet:original-source'} || $self->uuid,
-            original_sequence_no => $revprops->{'prophet:original-sequence-no'} || $entry->{'revision'},
-            is_nullification     => ( ( $revprops->{'prophet:special-type'} || '' ) eq 'nullification' ) ? 1 : undef,
-            is_resolution        => ( ( $revprops->{'prophet:special-type'} || '' ) eq 'resolution' ) ? 1 : undef,
-
-        }
-    );
+    my $changeset = Prophet::ChangeSet->new({
+        creator              => $self->changeset_creator,
+        sequence_no          => $entry->{'revision'},
+        source_uuid          => $self->uuid,
+        original_source_uuid => $revprops->{'prophet:original-source'} || $self->uuid,
+        original_sequence_no => $revprops->{'prophet:original-sequence-no'} || $entry->{'revision'},
+        is_nullification     => ( ( $revprops->{'prophet:special-type'} || '' ) eq 'nullification' ) ? 1 : undef,
+        is_resolution        => ( ( $revprops->{'prophet:special-type'} || '' ) eq 'resolution' ) ? 1 : undef,
+    });
 
     # add each record's changes to the changeset
     for my $path ( keys %{ $entry->{'paths'} } ) {

Modified: Prophet/trunk/t/publish-pull.t
==============================================================================
--- Prophet/trunk/t/publish-pull.t	(original)
+++ Prophet/trunk/t/publish-pull.t	Tue Aug  5 15:09:28 2008
@@ -1,15 +1,22 @@
 #!/usr/bin/perl
 use warnings;
 use strict;
-use Prophet::Test tests => 13;
+use Prophet::Test tests => 28;
 use Test::Exception;
 use File::Temp 'tempdir';
 use Path::Class;
+use Params::Validate;
+
+my ($bug_uuid, $pullall_uuid);
 
 my $alice_published = tempdir(CLEANUP => 1);
 
 as_alice {
-    run_ok( 'prophet', [qw(create --type Bug -- --status new --from alice )], "Created a record as alice" );
+    run_output_matches( 'prophet',
+        [qw(create --type Bug -- --status new --from alice )],
+        [qr/Created Bug \d+ \((\S+)\)(?{ $bug_uuid = $1 })/],
+        "Created a Bug record as alice");
+    ok($bug_uuid, "got a uuid for the Bug record");
     run_output_matches( 'prophet', [qw(search --type Bug --regex .)], [qr/new/], " Found our record" );
 
     run_ok( 'prophet', [qw(publish --to), $alice_published] );
@@ -24,16 +31,18 @@
 };
 
 as_alice {
-    run_ok( 'prophet', [qw(create --type Pullall -- --status new --from alice )], "Created another record as alice" );
+    run_output_matches( 'prophet',
+        [qw(create --type Pullall -- --status new --from alice )],
+        [qr/Created Pullall \d+ \((\S+)\)(?{ $pullall_uuid = $1 })/],
+        "Created a Pullall record as alice");
+    ok($pullall_uuid, "got a uuid for the Pullall record");
+
+    run_ok( 'prophet', [qw(publish --to), $alice_published] );
 };
 
 as_bob {
     run_ok( 'prophet', ['pull', '--all', '--force'] );
-
-    TODO: {
-        local $TODO = "not working yet?";
-        run_output_matches( 'prophet', [qw(search --type Pullall --regex .)], [qr/new/], " Found our record" );
-    }
+    run_output_matches( 'prophet', [qw(search --type Pullall --regex .)], [qr/new/], " Found our record" );
 };
 
 # see if uuid intuition works
@@ -53,3 +62,96 @@
 
 is(database_uuid_for('alice'), database_uuid_for('david'), "pull propagated the database uuid properly");
 isnt(replica_uuid_for('alice'), replica_uuid_for('david'), "pull created a new replica uuid");
+
+for my $user ('alice', 'bob', 'charlie', 'david') {
+    my $replica = Prophet::Replica->new({ url => repo_uri_for($user) });
+    my $changesets = $replica->fetch_changesets(after => 0);
+
+    is(@$changesets, 2, "two changesets for $user");
+
+    changeset_ok(
+        changeset   => $changesets->[0],
+        user        => $user,
+        record_type => 'Bug',
+        record_uuid => $bug_uuid,
+        sequence_no => 1,
+        merge       => $user ne 'alice',
+        name        => "$user\'s first changeset",
+    );
+    changeset_ok(
+        changeset   => $changesets->[1],
+        user        => $user,
+        record_type => 'Pullall',
+        record_uuid => $pullall_uuid,
+        sequence_no => 2,
+        merge       => $user ne 'alice',
+        name        => "$user\'s second changeset",
+    );
+}
+
+sub changeset_ok {
+    local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+    my %args = validate(@_, {
+        changeset   => 1,
+        user        => 1,
+        sequence_no => 1,
+        record_type => 1,
+        record_uuid => 1,
+        merge       => 1,
+        name        => 0,
+    });
+
+    my $changeset = $args{changeset}->as_hash;
+
+    my $changes = {
+        $args{record_uuid} => {
+            change_type  => 'add_file',
+            record_type  => $args{record_type},
+            prop_changes => {
+                status => {
+                    old_value => undef,
+                    new_value => 'new',
+                },
+                from => {
+                    old_value => undef,
+                    new_value => 'alice',
+                },
+            },
+        },
+    };
+
+    if ($args{merge}) {
+        my $change_type = $args{sequence_no} > 1
+                        ? 'update_file'
+                        : 'add_file';
+
+        my $prev_changeset_num = $args{sequence_no} > 1
+                               ? $args{sequence_no} - 1
+                               : undef;
+
+        $changes->{ replica_uuid_for('alice') } = {
+            change_type  => $change_type,
+            record_type  => '_merge_tickets',
+            prop_changes => {
+                'last-changeset' => {
+                    old_value => $prev_changeset_num,
+                    new_value => $args{sequence_no},
+                }
+            }
+        };
+    }
+
+    is_deeply($changeset, {
+        creator              => 'alice',
+        created              => $changeset->{created},
+        is_resolution        => undef,
+        is_nullification     => undef,
+        sequence_no          => $args{sequence_no},
+        source_uuid          => replica_uuid_for($args{user}),
+        original_sequence_no => $args{sequence_no},
+        original_source_uuid => replica_uuid_for('alice'),
+        changes              => $changes,
+    }, $args{name});
+}
+

Modified: Prophet/trunk/t/real-conflicting-merge.t
==============================================================================
--- Prophet/trunk/t/real-conflicting-merge.t	(original)
+++ Prophet/trunk/t/real-conflicting-merge.t	Tue Aug  5 15:09:28 2008
@@ -172,6 +172,8 @@
                         }
                     }
                 },
+                creator              => undef,
+                created              => $changesets[0]->created,
                 is_nullification     => 1,
                 is_resolution        => undef,
                 sequence_no          => ( replica_last_rev() - 2 ),
@@ -180,6 +182,8 @@
                 original_source_uuid => replica_uuid(),
             },
             {
+                creator              => 'alice',
+                created              => $changesets[1]->created,
                 is_nullification     => undef,
                 is_resolution        => undef,
                 sequence_no          => ( replica_last_rev() - 1 ),
@@ -213,6 +217,8 @@
             },
 
             {
+                creator              => 'bob',
+                created              => $changesets[2]->created,
                 is_nullification     => undef,
                 is_resolution        => 1,
                 sequence_no          => replica_last_rev(),

Modified: Prophet/trunk/t/simple-conflicting-merge.t
==============================================================================
--- Prophet/trunk/t/simple-conflicting-merge.t	(original)
+++ Prophet/trunk/t/simple-conflicting-merge.t	Tue Aug  5 15:09:28 2008
@@ -113,7 +113,8 @@
     is_deeply(
         $null_as_hash,
         {
-
+            creator              => undef,
+            created              => undef,
             is_nullification     => 1,
             is_resolution        => undef,
             original_sequence_no => undef,
@@ -139,7 +140,7 @@
     my $applied_as_hash = $applied_null->as_hash;
 
     # these aren't available yet in the memory-version
-    $applied_as_hash->{$_} = undef for qw(sequence_no source_uuid original_source_uuid original_sequence_no);
+    $applied_as_hash->{$_} = undef for qw(sequence_no source_uuid original_source_uuid original_sequence_no created);
     is_deeply( $applied_as_hash, $null_as_hash );
 
 
@@ -148,10 +149,12 @@
 
     my $from_alice_as_hash = $from_alice->as_hash;
 
-    $from_alice_as_hash->{$_} = undef for qw(sequence_no source_uuid);
+    $from_alice_as_hash->{$_} = undef for qw(sequence_no source_uuid created);
     is_deeply(
         $from_alice_as_hash,
         {
+            creator              => 'alice',
+            created              => undef,
             is_nullification     => undef,
             is_resolution        => undef,
             source_uuid          => undef,

Modified: Prophet/trunk/t/simple-push.t
==============================================================================
--- Prophet/trunk/t/simple-push.t	(original)
+++ Prophet/trunk/t/simple-push.t	Tue Aug  5 15:09:28 2008
@@ -56,6 +56,8 @@
     [ 
         {   #'sequence_no'          => 3,
             #'original_sequence_no' => 3, # the number is different on different replica types
+            'creator'              => 'bob',
+            'created'              => $changesets->[0]->{created},
             'original_source_uuid' => replica_uuid_for('bob'),
             'is_resolution'        => undef,
             'source_uuid'          => replica_uuid_for('bob'),
@@ -113,6 +115,8 @@
         
         #     'sequence_no'          => 4,  # the number varies based on replica type
         #    'original_sequence_no' => 4,
+            'creator'              => 'bob',
+            'created'              => $changes[0]->{created},
             'original_source_uuid' => replica_uuid_for('bob'),
             'is_resolution'        => undef,
             'source_uuid'          => replica_uuid_for('bob'),



More information about the Bps-public-commit mailing list