]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
v2writable: simplify ->new by reducing arg flexibility
authorEric Wong <e@80x24.org>
Sat, 18 Jan 2025 01:26:04 +0000 (01:26 +0000)
committerEric Wong <e@80x24.org>
Tue, 21 Jan 2025 22:36:55 +0000 (22:36 +0000)
We can update callers easily enough for internal-only APIs,
so there's no need to deal with unwarranted flexibility for
V2Writable->new.

lib/PublicInbox/V2Writable.pm
script/public-inbox-purge
scripts/import_vger_from_mbox
t/v2-add-remove-add.t
t/v2mirror.t
t/v2reindex.t
t/v2writable.t

index 3f05d5a65b20b4aece79696ede52ab101595b0ba..b5ed7c02ac72e1da6ac22a77f3882243801ec40a 100644 (file)
@@ -45,13 +45,11 @@ sub count_shards ($) {
 }
 
 sub new {
-       # $creat may be any true value, or 0/undef.  A hashref is true,
-       # and $creat->{nproc} may be set to an integer
-       my ($class, $v2ibx, $creat) = @_;
-       $v2ibx = PublicInbox::InboxWritable->new($v2ibx);
+       my ($class, $v2ibx, $creat_opt) = @_;
+       $v2ibx = PublicInbox::InboxWritable->new($v2ibx, $creat_opt);
        my $dir = $v2ibx->assert_usable_dir;
        unless (-d $dir) {
-               die "$dir does not exist\n" if !$creat;
+               die "$dir does not exist\n" if !$creat_opt;
                require File::Path;
                File::Path::mkpath($dir);
        }
@@ -72,7 +70,7 @@ sub new {
                last_commit => [], # git epoch -> commit
        };
        $self->{oidx}->{-no_fsync} = 1 if $v2ibx->{-no_fsync};
-       $self->{shards} = count_shards($self) || nproc_shards($creat);
+       $self->{shards} = count_shards($self) || nproc_shards($creat_opt);
        bless $self, $class;
 }
 
index 381f58cd3a48e4f2680d1e3ab2c5448b53f61f13..0100cf48afa9ed2502900703839fe9a7e62cb11e 100755 (executable)
@@ -39,7 +39,7 @@ my $n_purged = 0;
 
 foreach my $ibx (@ibxs) {
        my $eml = PublicInbox::Eml->new($data);
-       my $v2w = PublicInbox::V2Writable->new($ibx, 0);
+       my $v2w = PublicInbox::V2Writable->new($ibx);
 
        my $commits = $v2w->purge($eml) || [];
 
index 40ccf50b47ba1b764ec8695b2a656d0db44607f1..bd086d9d23fc4f17b98fd97f5fc25975f7f8463c 100644 (file)
@@ -34,7 +34,7 @@ $ibx = PublicInbox::Inbox->new($ibx);
 unless ($dry_run) {
        if ($version >= 2) {
                require PublicInbox::V2Writable;
-               PublicInbox::V2Writable->new($ibx, 1)->init_inbox(0);
+               PublicInbox::V2Writable->new($ibx, {})->init_inbox(0);
        } else {
                system(qw(git init --bare -q), $inboxdir) == 0 or die;
        }
index ddf8d24807dbdd0eb0d8448af2433298707145cb..070b1ac1e57a0094803ce505d5c181ef2195f0db 100644 (file)
@@ -26,7 +26,7 @@ Message-ID: <a-mid@b>
 
 hello world
 EOF
-my $im = PublicInbox::V2Writable->new($ibx, 1);
+my $im = PublicInbox::V2Writable->new($ibx, { nproc => 1 });
 $im->{parallel} = 0;
 ok($im->add($mime), 'message added');
 ok($im->remove($mime), 'message removed');
index dd4d9a6ca1a3d106d5fc0637e1e9f499fb71d5b9..9d8ba6277ae56a541c382a7184a7e4e1fb1ab2c6 100644 (file)
@@ -38,7 +38,7 @@ my $ibx = $cfg->lookup('test@example.com');
 ok($ibx, 'inbox found');
 $ibx->{version} = 2;
 $ibx->{-no_fsync} = 1;
-my $v2w = PublicInbox::V2Writable->new($ibx, 1);
+my $v2w = PublicInbox::V2Writable->new($ibx, { nproc => 1 });
 ok $v2w, 'v2w loaded';
 $v2w->{parallel} = 0;
 my $mime = PublicInbox::Eml->new(<<'');
index 8c49e15409b4de0e6604e1c105f05d5d8d07e05e..0e018481e4128bc1cc84c862067393305223951e 100644 (file)
@@ -78,7 +78,7 @@ my ($mark1, $mark2, $mark3, $mark4);
 {
        my %config = %$ibx_config;
        my $ibx = PublicInbox::Inbox->new(\%config);
-       my $im = PublicInbox::V2Writable->new($ibx, 1);
+       my $im = PublicInbox::V2Writable->new($ibx);
        eval { $im->index_sync({reindex => 1}) };
        is($@, '', 'no error from reindexing');
        $im->done;
@@ -97,7 +97,7 @@ ok(!-d $xap, 'Xapian directories removed');
 {
        my %config = %$ibx_config;
        my $ibx = PublicInbox::Inbox->new(\%config);
-       my $im = PublicInbox::V2Writable->new($ibx, 1);
+       my $im = PublicInbox::V2Writable->new($ibx);
        eval { $im->index_sync({reindex => 1}) };
        is($@, '', 'no error from reindexing');
        $im->done;
@@ -119,7 +119,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        local $SIG{__WARN__} = sub { push @warn, @_ };
        my %config = %$ibx_config;
        my $ibx = PublicInbox::Inbox->new(\%config);
-       my $im = PublicInbox::V2Writable->new($ibx, 1);
+       my $im = PublicInbox::V2Writable->new($ibx);
        eval { $im->index_sync({reindex => 1}) };
        is($@, '', 'no error from reindexing without msgmap');
        is(scalar(@warn), 0, 'no warnings from reindexing');
@@ -142,7 +142,7 @@ ok(!-d $xap, 'Xapian directories removed again');
        local $SIG{__WARN__} = sub { push @warn, @_ };
        my %config = %$ibx_config;
        my $ibx = PublicInbox::Inbox->new(\%config);
-       my $im = PublicInbox::V2Writable->new($ibx, 1);
+       my $im = PublicInbox::V2Writable->new($ibx);
        eval { $im->index_sync({reindex => 1}) };
        is($@, '', 'no error from reindexing without msgmap');
        is_deeply(\@warn, [], 'no warnings');
index 144ee68579eb73849baf65c4b76439a012c53c4f..242088f9601895d4b8f581b9c2a3a84ebab5ad24 100644 (file)
@@ -313,7 +313,7 @@ eval {
 ok($@, 'V2Writable fails on non-existent dir');
 
 {
-       my $v2w = PublicInbox::V2Writable->new($tmp, 1);
+       my $v2w = PublicInbox::V2Writable->new($tmp, { nproc => 1 });
        ok($v2w, 'creat flag works');
        $v2w->{parallel} = 0;
        $v2w->init_inbox(0);