From: Eric Wong Date: Sat, 18 Jan 2025 01:26:04 +0000 (+0000) Subject: v2writable: simplify ->new by reducing arg flexibility X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=921185d45095104eb1cd5e17a2eb83b154347564;p=thirdparty%2Fpublic-inbox.git v2writable: simplify ->new by reducing arg flexibility We can update callers easily enough for internal-only APIs, so there's no need to deal with unwarranted flexibility for V2Writable->new. --- diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index 3f05d5a65..b5ed7c02a 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -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; } diff --git a/script/public-inbox-purge b/script/public-inbox-purge index 381f58cd3..0100cf48a 100755 --- a/script/public-inbox-purge +++ b/script/public-inbox-purge @@ -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) || []; diff --git a/scripts/import_vger_from_mbox b/scripts/import_vger_from_mbox index 40ccf50b4..bd086d9d2 100644 --- a/scripts/import_vger_from_mbox +++ b/scripts/import_vger_from_mbox @@ -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; } diff --git a/t/v2-add-remove-add.t b/t/v2-add-remove-add.t index ddf8d2480..070b1ac1e 100644 --- a/t/v2-add-remove-add.t +++ b/t/v2-add-remove-add.t @@ -26,7 +26,7 @@ Message-ID: 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'); diff --git a/t/v2mirror.t b/t/v2mirror.t index dd4d9a6ca..9d8ba6277 100644 --- a/t/v2mirror.t +++ b/t/v2mirror.t @@ -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(<<''); diff --git a/t/v2reindex.t b/t/v2reindex.t index 8c49e1540..0e018481e 100644 --- a/t/v2reindex.t +++ b/t/v2reindex.t @@ -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'); diff --git a/t/v2writable.t b/t/v2writable.t index 144ee6857..242088f96 100644 --- a/t/v2writable.t +++ b/t/v2writable.t @@ -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);