[svk-commit] r2392 - in trunk: lib/SVK/Editor lib/SVK/Mirror/Backend t/mirror

nobody at bestpractical.com nobody at bestpractical.com
Mon May 7 11:11:44 EDT 2007


Author: clkao
Date: Mon May  7 11:11:40 2007
New Revision: 2392

Added:
   trunk/t/mirror/sync-snapshot.t
Modified:
   trunk/MANIFEST
   trunk/lib/SVK/Editor/CopyHandler.pm
   trunk/lib/SVK/Mirror/Backend/SVNRa.pm
   trunk/lib/SVK/Mirror/Backend/SVNSync.pm

Log:
Fix svk sync where a copy is made from revisions condensed with
snapshot made by previous sync --skipto.


Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST	(original)
+++ trunk/MANIFEST	Mon May  7 11:11:40 2007
@@ -294,6 +294,7 @@
 t/mirror/sync-replaced.t
 t/mirror/sync-replicate.t
 t/mirror/sync-revhole.t
+t/mirror/sync-snapshot.t
 t/update-gone.t
 t/svk-sec.gpg
 t/svk.gpg

Modified: trunk/lib/SVK/Editor/CopyHandler.pm
==============================================================================
--- trunk/lib/SVK/Editor/CopyHandler.pm	(original)
+++ trunk/lib/SVK/Editor/CopyHandler.pm	Mon May  7 11:11:40 2007
@@ -64,18 +64,25 @@
 
 =cut
 
-sub add_directory {
-    my ($self, $path, $pbaton, $from_path, $from_rev, $pool) = @_;
+sub _mk_method {
+    my $method = shift;
 
-    ($from_path, $from_rev) = $self->{cb_copy}->($self, $from_path, $from_rev);
-    $self->SUPER::add_directory( $path, $pbaton, $from_path, $from_rev, $pool );
+    sub {
+        my ( $self, $path, $pbaton, $from_path, $from_rev, $pool ) = @_;
+        my $cb;
+
+        ( $from_path, $from_rev, $cb )
+            = $self->{cb_copy}
+            ->( $self, $from_path, $from_rev, $path, $pbaton );
+
+        my $func = "SUPER::".$method;
+        my $ret = $self->$func( $path, $pbaton, $from_path, $from_rev, $pool );
+        $cb->($method, $ret) if $cb;
+        return $ret;
+    }
 }
 
-sub add_file {
-    my ($self, $path, $pbaton, $from_path, $from_rev, $pool) = @_;
-
-    ($from_path, $from_rev) = $self->{cb_copy}->($self, $from_path, $from_rev);
-    $self->SUPER::add_file( $path, $pbaton, $from_path, $from_rev, $pool );
-}
+*add_directory = _mk_method("add_directory");
+*add_file      = _mk_method("add_file");
 
 1;

Modified: trunk/lib/SVK/Mirror/Backend/SVNRa.pm
==============================================================================
--- trunk/lib/SVK/Mirror/Backend/SVNRa.pm	(original)
+++ trunk/lib/SVK/Mirror/Backend/SVNRa.pm	Mon May  7 11:11:40 2007
@@ -60,7 +60,7 @@
 use SVK::Editor::MapRev;
 use SVK::Util 'IS_WIN32';
 
-use Class::Autouse qw(SVK::Editor::SubTree SVK::Editor::CopyHandler);
+use Class::Autouse qw(SVK::Editor::SubTree SVK::Editor::CopyHandler SVK::Editor::Translate);
 
 ## class SVK::Mirror::Backend::SVNRa;
 ## has $.mirror is weak;
@@ -378,6 +378,20 @@
 
 sub find_rev_from_changeset {
     my ($self, $changeset, $seekback) = @_;
+    my $r = $self->_find_rev_from_changeset($changeset, $seekback);
+    return unless defined $r;
+
+    my $fs = $self->mirror->depot->repos->fs;
+
+    return -1
+	if $self->find_changeset($r) == 0
+        || $fs->revision_prop($r, 'svm:incomplete');
+
+    return $r;
+}
+
+sub _find_rev_from_changeset {
+    my ($self, $changeset, $seekback) = @_;
     my $t = $self->mirror->get_svkpath;
 
     no warnings 'uninitialized'; # $s_changeset below may be undef
@@ -482,7 +496,7 @@
     }
     $self->_revmap_prop( $opt{txn}, $changeset );
 
-    $editor = $self->_get_sync_editor($editor, $t);
+    $editor = $self->_get_sync_editor($editor, $changeset);
     $ra->replay( $changeset, 0, 1, $editor );
     $self->_after_replay($ra, $editor);
 
@@ -510,17 +524,42 @@
 }
 
 sub _get_sync_editor {
-    my ($self, $editor, $target) = @_;
+    my ($self, $oeditor, $changeset) = @_;
 
-    $editor = SVK::Editor::CopyHandler->new(
-        _editor => $editor,
+    my $editor = SVK::Editor::CopyHandler->new(
+        _editor => $oeditor,
         cb_copy => sub {
-            my ( $editor, $path, $rev ) = @_;
+            my ( undef, $path, $rev, $current_path, $pb ) = @_;
             return ( $path, $rev ) if $rev == -1;
             my $source_path = $self->source_path;
             $path =~ s/^\Q$self->{source_path}//;
-            return ($self->mirror->path . $path,
-		    $self->find_rev_from_changeset($rev, 1) );
+	    my $lrev = $self->find_rev_from_changeset($rev, 1);
+	    if ($lrev == -1) {
+		# vivify the copy that we don't have
+		my $cb = sub {
+		    my $editor = $oeditor;
+		    my ($method, $baton) = @_;
+		    my $ra = $self->_new_ra;
+		    if ($method eq 'add_directory') {
+			# Here we use translate instead of composite
+			# to make it not care about target_baton
+			$editor = SVK::Editor::Translate->new
+			    ( { translate => sub { $_[0] = "$current_path/$_[0]"; },
+				_editor => $editor } );
+		    }
+		    $editor =
+			SVK::Editor::SubTree->new
+			( { master_editor => $editor,
+			    anchor        => $current_path,
+			    anchor_baton  => $baton,
+			  } );
+
+		    $ra->replay($changeset, $changeset, 1, $editor);
+		    $self->_ra_finished($ra);
+		};
+		return (undef, -1, $cb);
+	    }
+            return ( $self->mirror->path . $path, $lrev );
         }
     );
 

Modified: trunk/lib/SVK/Mirror/Backend/SVNSync.pm
==============================================================================
--- trunk/lib/SVK/Mirror/Backend/SVNSync.pm	(original)
+++ trunk/lib/SVK/Mirror/Backend/SVNSync.pm	Mon May  7 11:11:40 2007
@@ -108,7 +108,7 @@
 sub _revmap_prop { }
 
 sub _get_sync_editor {
-    my ($self, $editor, $target) = @_;
+    my ($self, $editor, $changeset) = @_;
 
     return SVK::Editor::CopyHandler->new(
         _editor => $editor,

Added: trunk/t/mirror/sync-snapshot.t
==============================================================================
--- (empty file)
+++ trunk/t/mirror/sync-snapshot.t	Mon May  7 11:11:40 2007
@@ -0,0 +1,56 @@
+#!/usr/bin/perl -w
+use strict;
+use Test::More tests => 6;
+use SVK::Test;
+use SVN::Ra;
+use SVK::Mirror::Backend::SVNSync;
+
+my ($xd, $svk) = build_test('test');
+my $depot = $xd->find_depot('test');
+
+my ($copath, $corpath) = get_copath('sync-revhole');
+our $output;
+
+my ($srepospath, $spath, $srepos) = $xd->find_repos ('/test/', 1);
+my $tree = create_basic_tree($xd, '/test/');
+$svk->rm(-m => 'kill B', '/test/B');
+
+my $uri = uri($srepospath.($spath eq '/' ? '' : $spath));
+
+is_output($svk, mirror => ['//trunk', $uri],
+          ["Mirror initialized.  Run svk sync //trunk to start mirroring."]);
+
+# XXX: test -s greater than 3
+
+is_output($svk, sync => ['-s' => 3, '//trunk'],
+          [(map { qr'.*'} (1..8)),
+	   'Syncing '.$uri,
+	   'Retrieving log information from 3 to 3',
+	   'Committed revision 2 from revision 3.',
+	   'Syncing '.$uri]);
+
+$svk->mkdir(-m => 'xxx', '/test/XX');
+$svk->cp(-m => 'get A/P/pe from r1', '/test/A/P/pe at 1', '/test/pe');
+$svk->cp(-m => 'get B/S/P from r2', '/test/B/S/P at 2', '/test/P');
+is_output($svk, sync => [-t5 => '//trunk'],
+	  ['Syncing '.$uri,
+	   'Retrieving log information from 4 to 5',
+	   'Committed revision 3 from revision 4.',
+	   'Committed revision 4 from revision 5.']);
+is_output($svk, 'cat', ['//trunk/pe'],
+	  ['first line in pe',
+	   '2nd line in pe']);
+
+is_output($svk, sync => [-t6 => '//trunk'],
+	  ['Syncing '.$uri,
+	   'Retrieving log information from 6 to 6',
+	   'Committed revision 5 from revision 6.']);
+
+is_output($svk, 'cat', ['//trunk/P/pe'],
+	  ['first line in pe',
+	   '2nd line in pe']);
+
+# XXX: exam properties for recorded copies.
+
+
+# XXX: test with snapshot mirroring of subdir


More information about the svk-commit mailing list