user/dev discussion of public-inbox itself
 help / color / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Subject: [PATCH 1/3] v1writable: new wrapper which is closer to v2writable
Date: Tue, 14 May 2019 02:04:41 +0000
Message-ID: <20190514020443.7200-2-e@80x24.org> (raw)
In-Reply-To: <20190514020443.7200-1-e@80x24.org>

Import initialization is a little strange from history, but we
also can't change it too much because it's technically a public
API which external code may rely on...

And we may need to support v1 repos indefinitely.  This should
make it easier to write tests for both formats.
---
 MANIFEST                      |  1 +
 lib/PublicInbox/Import.pm     | 15 ++++++++++++++-
 lib/PublicInbox/V1Writable.pm | 34 ++++++++++++++++++++++++++++++++++
 lib/PublicInbox/V2Writable.pm |  6 +-----
 script/public-inbox-init      | 23 ++++++++++-------------
 5 files changed, 60 insertions(+), 19 deletions(-)
 create mode 100644 lib/PublicInbox/V1Writable.pm

diff --git a/MANIFEST b/MANIFEST
index 29cea10..28300e0 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -125,6 +125,7 @@ lib/PublicInbox/SpawnPP.pm
 lib/PublicInbox/Syscall.pm
 lib/PublicInbox/Unsubscribe.pm
 lib/PublicInbox/UserContent.pm
+lib/PublicInbox/V1Writable.pm
 lib/PublicInbox/V2Writable.pm
 lib/PublicInbox/View.pm
 lib/PublicInbox/ViewDiff.pm
diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index c775575..12abf39 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -18,12 +18,15 @@ use PublicInbox::MDA;
 use POSIX qw(strftime);
 
 sub new {
+	# we can't change arg order, this is documented in POD
+	# and external projects may rely on it:
 	my ($class, $git, $name, $email, $ibx) = @_;
 	my $ref = 'refs/heads/master';
 	if ($ibx) {
 		$ref = $ibx->{ref_head} || 'refs/heads/master';
 		$name ||= $ibx->{name};
 		$email ||= $ibx->{-primary_address};
+		$git ||= $ibx->git;
 	}
 	bless {
 		git => $git,
@@ -433,6 +436,16 @@ sub run_die ($;$$) {
 	$? == 0 or die join(' ', @$cmd) . " failed: $?\n";
 }
 
+sub init_bare {
+	my ($dir) = @_;
+	my @cmd = (qw(git init --bare -q), $dir);
+	run_die(\@cmd);
+	# set a reasonable default:
+	@cmd = (qw/git config/, "--file=$dir/config",
+		'repack.writeBitmaps', 'true');
+	run_die(\@cmd);
+}
+
 sub done {
 	my ($self) = @_;
 	my $w = delete $self->{out} or return;
@@ -586,7 +599,7 @@ __END__
 
 =head1 NAME
 
-PublicInbox::Import - message importer for public-inbox
+PublicInbox::Import - message importer for public-inbox v1 inboxes
 
 =head1 VERSION
 
diff --git a/lib/PublicInbox/V1Writable.pm b/lib/PublicInbox/V1Writable.pm
new file mode 100644
index 0000000..6ca5db4
--- /dev/null
+++ b/lib/PublicInbox/V1Writable.pm
@@ -0,0 +1,34 @@
+# Copyright (C) 2019 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# This interface wraps PublicInbox::Import and makes it closer
+# to V2Writable
+# Used to write to V1 inboxes (see L<public-inbox-v1-format(5)>).
+package PublicInbox::V1Writable;
+use strict;
+use warnings;
+use base qw(PublicInbox::Import);
+use PublicInbox::InboxWritable;
+
+sub new {
+	my ($class, $ibx, $creat) = @_;
+	my $dir = $ibx->{mainrepo} or die "no mainrepo in inbox\n";
+	unless (-d $dir) {
+		if ($creat) {
+			PublicInbox::Import::init_bare($dir);
+		} else {
+			die "$dir does not exist\n";
+		}
+	}
+	$ibx = PublicInbox::InboxWritable->new($ibx);
+	$class->SUPER::new(undef, undef, undef, $ibx);
+}
+
+sub init_inbox {
+	my ($self, $partitions, $skip_epoch, $skip_artnum) = @_;
+	# TODO: honor skip_artnum
+	my $dir = $self->{-inbox}->{mainrepo} or die "no mainrepo in inbox\n";
+	PublicInbox::Import::init_bare($dir);
+}
+
+1;
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 87e8f3e..b92d8d2 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -517,11 +517,7 @@ sub fill_alternates ($$) {
 	my $all = "$self->{-inbox}->{mainrepo}/all.git";
 	my @cmd;
 	unless (-d $all) {
-		@cmd = (qw(git init --bare -q), $all);
-		PublicInbox::Import::run_die(\@cmd);
-		@cmd = (qw/git config/, "--file=$all/config",
-				'repack.writeBitmaps', 'true');
-		PublicInbox::Import::run_die(\@cmd);
+		PublicInbox::Import::init_bare($all);
 	}
 	@cmd = (qw/git config/, "--file=$pfx/$epoch.git/config",
 			'include.path', '../../all.git/config');
diff --git a/script/public-inbox-init b/script/public-inbox-init
index 39f7497..8bb7845 100755
--- a/script/public-inbox-init
+++ b/script/public-inbox-init
@@ -8,6 +8,7 @@ use warnings;
 my $usage = "public-inbox-init NAME REPO_DIR HTTP_URL ADDRESS [ADDRESS..]";
 use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
 use PublicInbox::Config;
+use PublicInbox::Inbox;
 use File::Temp qw/tempfile/;
 use File::Basename qw/dirname/;
 use File::Path qw/mkpath/;
@@ -103,23 +104,19 @@ if ($version == 1 && defined $skip) {
 	die "--skip is only supported for -V2 repos\n";
 }
 
+my $ibx = PublicInbox::Inbox->new({
+	mainrepo => $mainrepo,
+	name => $name,
+	version => $version,
+	-primary_address => $address[0],
+});
+
 if ($version >= 2) {
 	require PublicInbox::V2Writable;
-	require PublicInbox::Inbox;
-	my $ibx = {
-		mainrepo => $mainrepo,
-		name => $name,
-		version => $version,
-		-primary_address => $address[0],
-	};
-	$ibx = PublicInbox::Inbox->new($ibx);
 	PublicInbox::V2Writable->new($ibx, 1)->init_inbox(0, $skip);
 } elsif ($version == 1) {
-	x(qw(git init -q --bare), $mainrepo);
-
-	# set a reasonable default:
-	x(qw/git config/, "--file=$mainrepo/config",
-		'repack.writeBitmaps', 'true');
+	require PublicInbox::V1Writable;
+	PublicInbox::V1Writable->new($ibx, 1)->init_inbox(0, $skip);
 } else {
 	die "Unsupported -V/--version: $version\n";
 }
-- 
EW


  reply index

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-01 16:41 [PATCH 00/13]: Incremental index fixes ebiederm
2018-08-01 16:43 ` [PATCH 01/13] Import.pm: Don't assume {in} and {out} always exist Eric W. Biederman
2018-08-01 16:43 ` [PATCH 02/13] t/v1reindex.t: Isolate the test cases Eric W. Biederman
2018-08-01 16:43 ` [PATCH 03/13] t/v2reindex.t: Isolate the test cases more Eric W. Biederman
2018-08-01 16:43 ` [PATCH 04/13] t/v[12]reindex.t: Place expected second in Xapian tests Eric W. Biederman
2018-08-01 16:43 ` [PATCH 05/13] t/v[12]reindex.t: Test that the resulting msgmap is as expected Eric W. Biederman
2018-08-01 16:43 ` [PATCH 06/13] t/v[12]reindex.t: Test incremental indexing works Eric W. Biederman
2018-08-01 16:43 ` [PATCH 07/13] SearchIdx.pm: Always assign numbers backwards during incremental indexing Eric W. Biederman
2018-08-01 16:43 ` [PATCH 08/13] Msgmap.pm: Track the largest value of num ever assigned Eric W. Biederman
2018-08-02  3:00   ` Eric Wong
2018-08-02  3:44     ` [WIP] searchidx: support incremental indexing on indexlevel=basic Eric Wong
2018-08-02 12:25       ` ebiederm
2018-08-02 17:12         ` ebiederm
2018-08-02 18:15           ` ebiederm
2019-05-14  2:04       ` [PATCH 0/3] incremental index fixes for indexlevel=basic Eric Wong
2019-05-14  2:04         ` Eric Wong [this message]
2019-05-14  2:04         ` [PATCH 2/3] v2writable: allow setting nproc via creat options Eric Wong
2019-05-14  2:04         ` [PATCH 3/3] searchidx: fix incremental index with indexlevel=basic on v1 Eric Wong
2018-08-02 12:08     ` [PATCH 08/13] Msgmap.pm: Track the largest value of num ever assigned ebiederm
2018-08-01 16:43 ` [PATCH 09/13] t/v[12]reindex.t Verify num_highwater Eric W. Biederman
2018-08-01 16:43 ` [PATCH 10/13] t/v[12]reindex.t: Verify the num highwater is as expected Eric W. Biederman
2018-08-01 16:43 ` [PATCH 11/13] SearchIdx,V2Writeable: Update num_highwater on optimized deletes Eric W. Biederman
2018-08-01 16:43 ` [PATCH 12/13] V2Writeable.pm: Ensure that a found message number is in the msgmap Eric W. Biederman
2018-08-01 16:43 ` [PATCH 13/13] V2Writeable.pm: In unindex_oid delete the message from msgmap Eric W. Biederman

Reply instructions:

You may reply publically 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=20190514020443.7200-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=ebiederm@xmission.com \
    --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

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox