[Bps-public-commit] r10924 - in SVN-PropDB: lib/SVN/PropDB

jesse at bestpractical.com jesse at bestpractical.com
Fri Feb 22 18:17:10 EST 2008


Author: jesse
Date: Fri Feb 22 18:17:09 2008
New Revision: 10924

Added:
   SVN-PropDB/lib/SVN/PropDB/HistoryEntry.pm
Modified:
   SVN-PropDB/lib/SVN/PropDB/Handle.pm
   SVN-PropDB/lib/SVN/PropDB/Record.pm
   SVN-PropDB/t/create.t

Log:
* Added author metadata for txns


Modified: SVN-PropDB/lib/SVN/PropDB/Handle.pm
==============================================================================
--- SVN-PropDB/lib/SVN/PropDB/Handle.pm	(original)
+++ SVN-PropDB/lib/SVN/PropDB/Handle.pm	Fri Feb 22 18:17:09 2008
@@ -63,6 +63,7 @@
 sub commit_edit {
     my $self = shift;
     my $txn = shift;
+    $txn->change_prop('svn:author',$ENV{'USER'});
     $txn->commit;
 
 }
@@ -119,8 +120,9 @@
 
 sub get_node_props {
     my $self = shift;
-    my %args = validate( @_, { uuid => 1, type => 1 } );
-    return $self->current_root->node_proplist($self->file_for(uuid => $args{'uuid'}, type => $args{'type'}));
+    my %args = validate( @_, { uuid => 1, type => 1, root => undef } );
+    my $root = $args{'root'} || $self->current_root;
+    return $root->node_proplist($self->file_for(uuid => $args{'uuid'}, type => $args{'type'}));
 }
 
 

Added: SVN-PropDB/lib/SVN/PropDB/HistoryEntry.pm
==============================================================================
--- (empty file)
+++ SVN-PropDB/lib/SVN/PropDB/HistoryEntry.pm	Fri Feb 22 18:17:09 2008
@@ -0,0 +1,25 @@
+use warnings;
+use strict;
+
+package SVN::PropDB::HistoryEntry;
+
+use base qw/Class::Accessor/;
+use Params::Validate;
+
+
+__PACKAGE__->mk_accessors(qw/handle rev date author msg action props prop_changes copy_from copy_from_rev/);
+
+
+sub new {
+   my $class = shift;
+   my $self = {};
+   bless $self, $class;
+
+
+    my   %args = validate( @_, {handle => 1});
+    $self->handle($args{'handle'});
+    $self->prop_changes({});
+   return $self;
+
+}
+1;

Modified: SVN-PropDB/lib/SVN/PropDB/Record.pm
==============================================================================
--- SVN-PropDB/lib/SVN/PropDB/Record.pm	(original)
+++ SVN-PropDB/lib/SVN/PropDB/Record.pm	Fri Feb 22 18:17:09 2008
@@ -3,6 +3,7 @@
 use strict;
 package SVN::PropDB::Record;
 use Params::Validate;
+use SVN::PropDB::HistoryEntry;
 use base qw'Class::Accessor';
 __PACKAGE__->mk_accessors(qw'handle props uuid type');
 my $UUIDGEN = Data::UUID->new();
@@ -117,4 +118,81 @@
     return $self->handle->file_for(type => $self->type, uuid => $self->uuid);
 }
 
+
+
+sub history {
+    my $self       = shift;
+    my $oldest_rev = 0;
+    my @history;
+    $self->handle->repo_handle->get_logs(
+        [ $self->storage_node ],
+        $self->handle->repo_handle->fs->youngest_rev,
+        $oldest_rev,
+        1,
+        0,
+        sub { $self->_history_entry_callback( \@history, @_ ) }
+    );
+    $self->_compute_history_deltas(\@history);
+    return \@history;
+}
+
+
+sub _history_entry_callback {
+    my $self = shift;
+    my ( $accumulator, $paths, $rev, $author, $date, $msg ) = @_;
+    my @nodes = keys %$paths;
+    die "We should only have one node!" unless ( $#nodes == 0 );
+
+    my $node = $paths->{ $nodes[0] };
+    my $data = SVN::PropDB::HistoryEntry->new( handle => $self->handle );
+
+    $data->rev($rev);
+    $data->author($author);
+    $data->date($date);
+    $data->msg($msg);
+    $data->action( $node->action() );
+    $data->copy_from( $node->copyfrom_path() );
+    $data->copy_from_rev( $node->copyfrom_rev() );
+    $data->props( $self->handle->repo_handle->fs()->revision_root($rev)->node_proplist( $nodes[0] ) );
+
+    push @$accumulator, $data;
+}
+
+sub _compute_history_deltas {
+    my $self    = shift;
+    my $log_ref = shift;
+    warn $self, $log_ref;
+    @$log_ref = reverse @$log_ref;
+    my $last_props = {};
+    for my $i ( 0 .. $#{$log_ref} ) {
+
+        warn "Node $i - rev " . $log_ref->[$i]->rev;
+
+        my $props = $log_ref->[$i]->props;
+
+        for my $key ( keys %$props ) {
+
+            if ( !exists $last_props->{$key} ) {
+                $log_ref->[$i]->prop_changes->{$key}->{'add'}
+                    = $props->{$key};
+            } elsif ( $last_props->{$key} ne $props->{$key} ) {
+                $log_ref->[$i]->prop_changes->{$key}->{'add'}
+                    = $props->{$key};
+                $log_ref->[$i]->prop_changes->{$key}->{'del'}
+                    = $last_props->{$key};
+            }
+        }
+        foreach my $key ( keys %$last_props ) {
+            if ( !exists $props->{$key} ) {
+                $log_ref->[$i]->prop_changes->{$key}->{'del'}
+                    = $last_props->{$key};
+            }
+        }
+
+        $last_props = $props;
+    }
+
+    return $log_ref;
+
+}
 1;

Modified: SVN-PropDB/t/create.t
==============================================================================
--- SVN-PropDB/t/create.t	(original)
+++ SVN-PropDB/t/create.t	Fri Feb 22 18:17:09 2008
@@ -6,6 +6,7 @@
 use_ok('SVN::PropDB::Handle');
 my $REPO= tempdir(CLEANUP => 0).'/repo-'.$$;
 ok(! -d $REPO);
+diag ($REPO);
 `svnadmin create $REPO`;
 ok(-d $REPO, "The repo exists ater svnadmin create");
 my $cxn = SVN::PropDB::Handle->new( repository => "$REPO", db_root => '/_propdb-test');



More information about the Bps-public-commit mailing list