]> Sergey Matveev's repositories - public-inbox.git/commitdiff
init: allow --skip of old epochs for -V2 repos
authorEric Wong <e@80x24.org>
Fri, 28 Dec 2018 10:16:11 +0000 (10:16 +0000)
committerEric Wong <e@80x24.org>
Fri, 28 Dec 2018 19:17:47 +0000 (19:17 +0000)
This allows archivists to publish incomplete archives with newer
mail while allowing "0.git" (or "1.git" and so on) epochs to be
added-after-the-fact (without affecting "git clone" followers).

A reindex will be necessary for Xapian and SQLite to catch up
once the old epochs are added; but the reindexing code is also
capable of tolerating missing epochs.

lib/PublicInbox/V2Writable.pm
script/public-inbox-init
t/init.t

index 0396d9f58e55931d5cea622556be34135251cecc..152d90ab3ea595fd56c8b7643831fd28fbecbdbb 100644 (file)
@@ -83,11 +83,14 @@ sub new {
 }
 
 sub init_inbox {
-       my ($self, $parallel) = @_;
+       my ($self, $parallel, $skip) = @_;
        $self->{parallel} = $parallel;
        $self->idx_init;
        my $epoch_max = -1;
        git_dir_latest($self, \$epoch_max);
+       if (defined $skip && $epoch_max == -1) {
+               $epoch_max = $skip;
+       }
        $self->git_init($epoch_max >= 0 ? $epoch_max : 0);
        $self->done;
 }
index 1aec799c60cc2a24dcf2bb3b8597e54d2e677e9b..39f7497f3bf1fe6d239e7b2ad5a0067ea8d756ef 100755 (executable)
@@ -17,8 +17,10 @@ sub x { system(@_) and die join(' ', @_). " failed: $?\n" }
 sub usage { print STDERR "Usage: $usage\n"; exit 1 }
 my $version = undef;
 my $indexlevel = undef;
+my $skip;
 my %opts = ( 'V|version=i' => \$version,
             'L|indexlevel=s' => \$indexlevel,
+            'S|skip=i' => \$skip,
 );
 GetOptions(%opts) or usage();
 my $name = shift @ARGV or usage();
@@ -97,6 +99,10 @@ if (-f "$mainrepo/inbox.lock") {
 
 $version = 1 unless defined $version;
 
+if ($version == 1 && defined $skip) {
+       die "--skip is only supported for -V2 repos\n";
+}
+
 if ($version >= 2) {
        require PublicInbox::V2Writable;
        require PublicInbox::Inbox;
@@ -107,7 +113,7 @@ if ($version >= 2) {
                -primary_address => $address[0],
        };
        $ibx = PublicInbox::Inbox->new($ibx);
-       PublicInbox::V2Writable->new($ibx, 1)->init_inbox(0);
+       PublicInbox::V2Writable->new($ibx, 1)->init_inbox(0, $skip);
 } elsif ($version == 1) {
        x(qw(git init -q --bare), $mainrepo);
 
index 182d065cb66461e9037c4fdb832834fb153e2456..1551a304e6b7c7b28bb3b9e8b935f9a231f745cb 100644 (file)
--- a/t/init.t
+++ b/t/init.t
@@ -79,6 +79,22 @@ SKIP: {
                is(system(@cmd), 0, "-init -L $lvl");
                is(read_indexlevel("v2$lvl"), $lvl, "indexlevel set to '$lvl'");
        }
+
+       # loop for idempotency
+       for (1..2) {
+               @cmd = (pi_init, '-V2', '-S1', 'skip1', "$tmpdir/skip1",
+                          qw(http://example.com/skip1 skip1@example.com));
+               is(system(@cmd), 0, "--skip 1");
+               my $gits = [ glob("$tmpdir/skip1/git/*.git") ];
+               is_deeply(["$tmpdir/skip1/git/1.git"], $gits, 'skip OK');
+       }
+
+
+       @cmd = (pi_init, '-V2', '--skip=2', 'skip2', "$tmpdir/skip2",
+                  qw(http://example.com/skip2 skip2@example.com));
+       is(system(@cmd), 0, "--skip 2");
+       my $gits = [ glob("$tmpdir/skip2/git/*.git") ];
+       is_deeply(["$tmpdir/skip2/git/2.git"], $gits, 'skipping 2 works, too');
 }
 
 done_testing();