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

nobody at bestpractical.com nobody at bestpractical.com
Thu Mar 8 11:42:35 EST 2007


Author: clkao
Date: Thu Mar  8 11:42:34 2007
New Revision: 2318

Added:
   trunk/t/mirror/sync-revhole.t
Modified:
   trunk/MANIFEST
   trunk/lib/SVK/Mirror/Backend/SVNRa.pm

Log:
When mirroring partial repository with copies, the from revision
number might not be exactly the ones we have mirrored.  We should
seek back to use appropriate revision.


Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST	(original)
+++ trunk/MANIFEST	Thu Mar  8 11:42:34 2007
@@ -286,6 +286,7 @@
 t/mirror/sync-replaced-nocopy.t
 t/mirror/sync-replaced.t
 t/mirror/sync-replicate.t
+t/mirror/sync-revhole.t
 t/update-gone.t
 t/svk-sec.gpg
 t/svk.gpg

Modified: trunk/lib/SVK/Mirror/Backend/SVNRa.pm
==============================================================================
--- trunk/lib/SVK/Mirror/Backend/SVNRa.pm	(original)
+++ trunk/lib/SVK/Mirror/Backend/SVNRa.pm	Thu Mar  8 11:42:34 2007
@@ -374,18 +374,38 @@
 =cut
 
 sub find_rev_from_changeset {
-    my ($self, $changeset) = @_;
+    my ($self, $changeset, $seekback) = @_;
     my $t = $self->mirror->get_svkpath;
 
     no warnings 'uninitialized'; # $s_changeset below may be undef
 
-    return $t->search_revision
+    my $r = $t->search_revision
 	( cmp => sub {
 	      my $rev = shift;
-	      my $search = $t->mclone(revision => $rev);
               my $s_changeset = scalar $self->find_changeset($rev);
               return $s_changeset <=> $changeset;
           } );
+
+    return $r if $r || !$seekback;
+
+    my $result;
+    $r = $t->search_revision
+	( cmp => sub {
+	      my $rev = shift;
+
+              my $s_changeset = scalar $self->find_changeset($rev);
+
+	      if ($s_changeset > $changeset) {
+		  my $prev = $t->mclone(revision => $rev)->prev;
+		  $result = $prev
+		      if scalar $self->find_changeset($prev->revision) < $changeset;
+	      }
+	      return $s_changeset <=> $changeset;
+          } );
+
+    return unless $result;
+
+    return $result->revision;
 }
 
 =item find_changeset( $local_rev )
@@ -507,7 +527,7 @@
             return $target->as_url(
                 1,
                 $self->mirror->path . $path,
-                $self->find_rev_from_changeset($rev)
+                $self->find_rev_from_changeset($rev, 1)
             );
         }
     );

Added: trunk/t/mirror/sync-revhole.t
==============================================================================
--- (empty file)
+++ trunk/t/mirror/sync-revhole.t	Thu Mar  8 11:42:34 2007
@@ -0,0 +1,53 @@
+#!/usr/bin/perl -w
+use strict;
+use Test::More tests => 4;
+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/A', 1);
+my $tree = create_basic_tree($xd, '/test/');
+
+my $uri = uri($srepospath.($spath eq '/' ? '' : $spath));
+
+is_output($svk, mirror => ['//A', $uri],
+          ["Mirror initialized.  Run svk sync //A to start mirroring."]);
+waste_rev($svk, '/test/useless');
+
+$svk->co('/test/', $copath);
+
+append_file("$copath/A/Q/qu", "edited");
+$svk->ci(-m => 'change A qu', $copath);
+
+is_output($svk, sync => ['//A'],
+          ['Syncing '.$uri,
+	   'Retrieving log information from 1 to 5',
+	   'Committed revision 2 from revision 1.',
+	   'Committed revision 3 from revision 2.',
+	   'Committed revision 4 from revision 5.']);
+
+
+my $path = SVK::Path->real_new( { depot => $depot, path => '/A'})->refresh_revision;
+{
+    my $pool = SVN::Pool->new;
+    my ($editor) =
+	$path->get_editor( callback => sub { ok(1, 'committed with api') },
+			   author => 'svktest', message => 'creating copy with revhole');
+    my $rb = $editor->open_root($path->revision);
+    $editor->close_file( $editor->add_file('qu-from-a', $rb, uri($srepospath."/A/Q/qu"), 4), undef);
+    $editor->close_directory($rb);
+    $editor->close_edit;
+}
+
+is_output($svk, sync => ['//A'],
+          ['Syncing '.$uri,
+	   'Retrieving log information from 6 to 6',
+	   'Committed revision 5 from revision 6.']);
+
+


More information about the svk-commit mailing list