[svk-commit] r2532 - in branches/mirror-boostrap: lib/SVK/Command t/mirror

nobody at bestpractical.com nobody at bestpractical.com
Wed Aug 8 11:48:30 EDT 2007


Author: clsung
Date: Wed Aug  8 11:48:28 2007
New Revision: 2532

Modified:
   branches/mirror-boostrap/lib/SVK/Command/Mirror.pm
   branches/mirror-boostrap/lib/SVK/Mirror.pm
   branches/mirror-boostrap/t/mirror/sync-bootstrap.t

Log:
- try to add bootstrap() in SVK::Mirror
- 3rd test pass, 4th test failed, so far.

Modified: branches/mirror-boostrap/lib/SVK/Command/Mirror.pm
==============================================================================
--- branches/mirror-boostrap/lib/SVK/Command/Mirror.pm	(original)
+++ branches/mirror-boostrap/lib/SVK/Command/Mirror.pm	Wed Aug  8 11:48:28 2007
@@ -61,6 +61,7 @@
 sub options {
     ('l|list'  => 'list',
      'd|delete|detach'=> 'detach',
+     'b|bootstrap' => 'bootstrap',
      'upgrade' => 'upgrade',
      'relocate'=> 'relocate',
      'unlock'=> 'unlock',
@@ -143,6 +144,24 @@
     return;
 }
 
+package SVK::Command::Mirror::bootstrap;
+use base qw(SVK::Command::Mirror);
+use SVK::I18N;
+
+use constant narg => 2;
+
+sub run {
+    my ($self, $target, $dumpfile) = @_;
+    my ($m, $mpath) = $target->is_mirrored;
+
+    die loc("%1 is not a mirrored path.\n", $target->depotpath) if !$m;
+    die loc("%1 is inside a mirrored path.\n", $target->depotpath) if $mpath;
+
+    $m->bootstrap($dumpfile); # load from dumpfile
+    print loc("Mirror path '%1' synced from dumpfile.\n", $target->depotpath);
+    return;
+}
+
 package SVK::Command::Mirror::upgrade;
 use base qw(SVK::Command::Mirror);
 use SVK::I18N;

Modified: branches/mirror-boostrap/lib/SVK/Mirror.pm
==============================================================================
--- branches/mirror-boostrap/lib/SVK/Mirror.pm	(original)
+++ branches/mirror-boostrap/lib/SVK/Mirror.pm	Wed Aug  8 11:48:28 2007
@@ -230,6 +230,69 @@
     $editor->close_edit;
 }
 
+=item bootstrap
+
+=cut
+
+sub bootstrap {
+    my ($self, $dumpfile) = @_;
+    use SVN::Dump;
+
+    my $dump = SVN::Dump->new( { file => $dumpfile } );
+    my $prefix = $self->path.'/';
+
+    my $prev = undef;
+    my $rev = 0;
+    my $buf;
+    my $header;
+    while ( my $record = $dump->next_record() ) {
+	if ($record->type eq 'format' || $record->type eq 'uuid') {
+	    $header = $header.$record->as_string;
+	    next;
+	}
+
+	my $translate = sub {
+	    my $rec = shift;
+
+	    if (my $path = $rec->get_header('Node-copyfrom-path')) {
+		$path = $prefix.$path;
+		$rec->set_header('Node-copyfrom-path' => $path );
+	    }
+	    if (my $rev = $rec->get_header('Node-copyfrom-rev')) {
+		$rec->set_header('Node-copyfrom-rev' =>
+		    scalar $self->find_local_rev( $rev, $self->source_uuid ) );
+	    }
+	    
+	    if ($rec->get_header('Revision-number')) {
+		$rev = $rec->get_header('Revision-number');
+		$prev = $rev if !$prev;
+		$rec->set_property('svm:headrev',$self->source_uuid.':'.$rec->get_header('Revision-number'));
+	    }
+
+
+	    if ( my $path = $rec->get_header('Node-path') ) {
+		$path = $prefix.$path;
+		$rec->set_header('Node-path' => $path);
+	    }
+
+	};
+	$translate->( $record );
+	my $inc = $record->get_included_record;
+	$translate->( $inc ) if $inc;
+
+	if ($rev and $prev != $rev) {
+	    $buf = $header.$buf;
+	    open my $fh, '<', \$buf;
+	    my $ret = SVN::Repos::load_fs2( $self->repos, $fh, \*STDERR, $SVN::Repos::load_uuid_default, undef, 0, 0, undef, undef );
+	    # (repos,dumpstream,feedback_stream,uuid_action,parent_dir,use_pre_commit_hook,use_post_commit_hook,cancel_func,cancel_baton,pool);
+	    $buf = "";
+	    $prev = $rev;
+	}
+
+	$buf = $buf.$record->as_string;
+    }
+}
+
 =item relocate($newurl)
 
 =item with_lock($code)

Modified: branches/mirror-boostrap/t/mirror/sync-bootstrap.t
==============================================================================
--- branches/mirror-boostrap/t/mirror/sync-bootstrap.t	(original)
+++ branches/mirror-boostrap/t/mirror/sync-bootstrap.t	Wed Aug  8 11:48:28 2007
@@ -26,18 +26,19 @@
           ["Mirror initialized.  Run svk sync /m2/m to start mirroring."]);
 $svk->sync('/m2/m');
 
-TODO: {
-
-local $TODO = 'not yet';
 is_output($svk, mirror => ['--bootstrap', '//m', $dump],
-	  []);
+	  ['Mirror path \'//m\' synced from dumpfile.']);
 
+TODO: {
+local $TODO = 'not yet';
 # compare normal mirror result and bootstrap mirror result
 my ($exp_mirror, $boot_mirror);
 open my $exp, '>', \$exp_mirror;
 open my $boot, '>', \$boot_mirror;
 dump_all($xd->find_depot('') => $exp);
 dump_all($xd->find_depot('m2') => $boot);
+$exp_mirror =~ s/UUID: .*//;
+$boot_mirror =~ s/UUID: .*//;
 
 is($exp_mirror, $boot_mirror); # do something with UUID, they should be different
 


More information about the svk-commit mailing list