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
};
sub new {
- my ($class, $ibx) = @_;
- bless $ibx, $class;
+ my ($class, $ibx, $creat_opt) = @_;
+ my $self = bless $ibx, $class;
+
+ # TODO: maybe stop supporting this
+ if ($creat_opt) { # for { nproc => $N }
+ $self->{-creat_opt} = $creat_opt;
+ init_inbox($self) if ($self->{version} || 1) == 1;
+ }
+ $self;
+}
+
+sub init_inbox {
+ my ($self, $partitions, $skip_epoch, $skip_artnum) = @_;
+ # TODO: honor skip_artnum
+ my $v = $self->{version} || 1;
+ if ($v == 1) {
+ my $dir = $self->{mainrepo} or die "no mainrepo in inbox\n";
+ PublicInbox::Import::init_bare($dir);
+ } else {
+ my $v2w = importer($self);
+ $v2w->init_inbox($partitions, $skip_epoch, $skip_artnum);
+ }
}
sub importer {
my ($self, $parallel) = @_;
- $self->{-importer} ||= eval {
+ $self->{-importer} ||= do {
my $v = $self->{version} || 1;
if ($v == 2) {
eval { require PublicInbox::V2Writable };
die "v2 not supported: $@\n" if $@;
- my $v2w = PublicInbox::V2Writable->new($self);
+ my $opt = $self->{-creat_opt};
+ my $v2w = PublicInbox::V2Writable->new($self, $opt);
$v2w->{parallel} = $parallel;
$v2w;
} elsif ($v == 1) {
- my $git = $self->git;
- my $name = $self->{name};
- my $addr = $self->{-primary_address};
- PublicInbox::Import->new($git, $name, $addr, $self);
+ my @arg = (undef, undef, undef, $self);
+ PublicInbox::Import->new(@arg);
} else {
$! = 78; # EX_CONFIG 5.3.5 local configuration error
die "unsupported inbox version: $v\n";
+++ /dev/null
-# 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;
}
sub init_inbox {
- my ($self, $parallel, $skip) = @_;
+ my ($self, $parallel, $skip_epoch) = @_;
$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;
+ if (defined $skip_epoch && $epoch_max == -1) {
+ $epoch_max = $skip_epoch;
}
$self->git_init($epoch_max >= 0 ? $epoch_max : 0);
$self->done;
use PublicInbox::Admin;
PublicInbox::Admin::require_or_die('-base');
require PublicInbox::Config;
-require PublicInbox::Inbox;
+require PublicInbox::InboxWritable;
use File::Temp qw/tempfile/;
use File::Basename qw/dirname/;
use File::Path qw/mkpath/;
indexlevel => $indexlevel,
});
-if ($version >= 2) {
- require PublicInbox::V2Writable;
- PublicInbox::V2Writable->new($ibx, 1)->init_inbox(0, $skip);
-} elsif ($version == 1) {
- require PublicInbox::V1Writable;
- PublicInbox::V1Writable->new($ibx, 1)->init_inbox(0, $skip);
-} else {
- die "Unsupported -V/--version: $version\n";
-}
+my $creat_opt = {};
+PublicInbox::InboxWritable->new($ibx, $creat_opt)->init_inbox(0, $skip);
# needed for git prior to v2.1.0
umask(0077) if defined $perm;
use_ok 'PublicInbox::Git';
use_ok 'PublicInbox::Import';
use_ok 'PublicInbox::Inbox';
-use_ok 'PublicInbox::V1Writable';
+use_ok 'PublicInbox::InboxWritable';
use_ok 'PublicInbox::Config';
my $cfg = PublicInbox::Config->new($pi_config);
my $ibx = $cfg->lookup_name('test');
-my $im = PublicInbox::V1Writable->new($ibx);
+my $im = PublicInbox::InboxWritable->new($ibx)->importer;
{
local $ENV{HOME} = $home;
use Test::More;
use PublicInbox::MIME;
use PublicInbox::Inbox;
+use PublicInbox::InboxWritable;
use File::Temp qw/tempdir/;
require './t/common.perl';
require_git(2.6);
-primary_address => 'test@example.com',
indexlevel => $level,
});
- my $cls = "PublicInbox::V${v}Writable";
- use_ok $cls;
- my $im = $cls->new($ibx, {nproc=>1});
+ my $im = PublicInbox::InboxWritable->new($ibx, {nproc=>1})->importer;
$mime->header_set('Message-ID', '<m@1>');
ok($im->add($mime), 'first message added');
$im->done;
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');
+ is_deeply($gits, ["$tmpdir/skip1/git/1.git"], 'skip OK');
}
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');
+ is_deeply($gits, ["$tmpdir/skip2/git/2.git"], 'skipping 2 works, too');
}
done_testing();
}
require PublicInbox::SearchIdx;
require PublicInbox::Msgmap;
+require PublicInbox::InboxWritable;
use Email::Simple;
use IO::Socket;
use Socket qw(IPPROTO_TCP TCP_NODELAY);
my $addr = $group . '@example.com';
my $nntpd = 'blib/script/public-inbox-nntpd';
my $init = 'blib/script/public-inbox-init';
-use_ok 'PublicInbox::Import';
-use_ok 'PublicInbox::Inbox';
-use_ok 'PublicInbox::Git';
SKIP: {
skip "git 2.6+ required for V2Writable", 1 if $version == 1;
use_ok 'PublicInbox::V2Writable';
0, 'enabled newsgroup');
my $len;
- my $im;
- if ($version == 2) {
- $im = PublicInbox::V2Writable->new($ibx);
- } elsif ($version == 1) {
- use_ok 'PublicInbox::V1Writable';
- $im = PublicInbox::V1Writable->new($ibx);
- } else {
- die "unsupported version: $version";
- }
+ $ibx = PublicInbox::InboxWritable->new($ibx);
+ my $im = $ibx->importer;
# ensure successful message delivery
{
use IO::Socket;
use POSIX qw(dup2);
use_ok 'PublicInbox::V2Writable';
+use PublicInbox::InboxWritable;
use PublicInbox::MIME;
use PublicInbox::Config;
# FIXME: too much setup