user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] init: allow --skip of old epochs for -V2 repos
Date: Fri, 28 Dec 2018 10:16:11 +0000	[thread overview]
Message-ID: <20181228101611.16702-1-e@80x24.org> (raw)

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 |  5 ++++-
 script/public-inbox-init      |  8 +++++++-
 t/init.t                      | 16 ++++++++++++++++
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 0396d9f..152d90a 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -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;
 }
diff --git a/script/public-inbox-init b/script/public-inbox-init
index 1aec799..39f7497 100755
--- a/script/public-inbox-init
+++ b/script/public-inbox-init
@@ -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);
 
diff --git a/t/init.t b/t/init.t
index 182d065..1551a30 100644
--- 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();
-- 
EW


                 reply	other threads:[~2018-12-28 10:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181228101611.16702-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).