about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-05-23 09:36:40 +0000
committerEric Wong <e@80x24.org>2019-05-23 17:43:50 +0000
commit96a27a0a073b61c465240bbbbb05a4c16f67c8d4 (patch)
tree6ab703c46757f61782e5d135ebc5ef29826fc868 /lib
parent646c15c17c323aa80a9a25ca8755720926564ef8 (diff)
downloadpublic-inbox-96a27a0a073b61c465240bbbbb05a4c16f67c8d4.tar.gz
In retrospect, introducing V1Writable was unnecessary and
InboxWritable->importer is in a better position to abstract
away differences between v1 and v2 writers.

So teach InboxWritable to initialize inboxes and get rid
of V1Writable.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/InboxWritable.pm35
-rw-r--r--lib/PublicInbox/V1Writable.pm34
-rw-r--r--lib/PublicInbox/V2Writable.pm6
3 files changed, 30 insertions, 45 deletions
diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm
index 2f1ca6f0..116f423b 100644
--- a/lib/PublicInbox/InboxWritable.pm
+++ b/lib/PublicInbox/InboxWritable.pm
@@ -19,25 +19,44 @@ use constant {
 };
 
 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";
diff --git a/lib/PublicInbox/V1Writable.pm b/lib/PublicInbox/V1Writable.pm
deleted file mode 100644
index 6ca5db4a..00000000
--- a/lib/PublicInbox/V1Writable.pm
+++ /dev/null
@@ -1,34 +0,0 @@
-# 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 afcac4d2..c476cb39 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -94,13 +94,13 @@ sub new {
 }
 
 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;