]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
inbox_writable: match v1 and v2 init semantics
authorEric Wong <e@80x24.org>
Sat, 18 Jan 2025 01:26:05 +0000 (01:26 +0000)
committerEric Wong <e@80x24.org>
Tue, 21 Jan 2025 22:36:56 +0000 (22:36 +0000)
More consistent code between v1 and v2 will make maintenance
easier going forward.

lib/PublicInbox/InboxWritable.pm

index f391d7ee2f430b93e5c5f2764ae873c8e699107a..1982ac05a89437eda72f29bbb64a691ae7dce80c 100644 (file)
@@ -16,14 +16,8 @@ use Fcntl qw(O_RDONLY O_NONBLOCK);
 
 sub new {
        my ($class, $ibx, $creat_opt) = @_;
-       return $ibx if ref($ibx) eq $class;
-       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;
-       }
+       my $self = bless $ibx, $class; # idempotent
+       $self->{-creat_opt} = $creat_opt if $creat_opt; # for { nproc => $N }
        $self;
 }
 
@@ -77,8 +71,8 @@ sub importer {
                $v2w->{parallel} = $parallel if defined $parallel;
                $v2w;
        } elsif ($v == 1) {
-               my @arg = (undef, undef, undef, $self);
-               PublicInbox::Import->new(@arg);
+               init_inbox($self) if $self->{-creat_opt};
+               PublicInbox::Import->new(undef, undef, undef, $self);
        } else {
                $! = 78; # EX_CONFIG 5.3.5 local configuration error
                die "unsupported inbox version: $v\n";