From 0d90aee9f3c031f050a8a21f325108f875d0c0f6 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 26 Aug 2025 19:50:51 +0000 Subject: [PATCH] avoid redundant $creat_opt hashref in some places We can use the Getopt::Long hashref directly in some of these places to reduce cognitive overhead for understanding our internal data structures. --- script/public-inbox-convert | 6 ++---- script/public-inbox-init | 13 ++++--------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/script/public-inbox-convert b/script/public-inbox-convert index 4ca8ecf28..78defa935 100755 --- a/script/public-inbox-convert +++ b/script/public-inbox-convert @@ -82,10 +82,8 @@ local %ENV = (%$env, %ENV) if $env; my $new = { %$old }; $new->{inboxdir} = PublicInbox::Config::rel2abs_collapsed($new_dir); $new->{version} = 2; -my $creat_opt = { nproc => $opt->{jobs} }; -$creat_opt->{wal} = 1 if $opt->{wal}; -$creat_opt->{fsync} = $opt->{fsync}; -$new = PublicInbox::InboxWritable->new($new, $creat_opt); +$opt->{nproc} = $opt->{jobs}; # FIXME validate +$new = PublicInbox::InboxWritable->new($new, $opt); my $v2w; sub link_or_copy ($$) { diff --git a/script/public-inbox-init b/script/public-inbox-init index 489bb995f..f2291b05c 100755 --- a/script/public-inbox-init +++ b/script/public-inbox-init @@ -34,7 +34,6 @@ EOF require PublicInbox::Admin; PublicInbox::Admin::require_or_die('-base'); -my $creat_opt = {}; my $usage_cb = sub { print STDERR $help; exit 1; @@ -46,14 +45,10 @@ GetOptions(my $opt = {}, qw(version|V=i skip-docdata help|h c=s@ C=s@ )) or $usage_cb->(); -for (qw(wal skip-epoch skip-artnum)) { - $creat_opt->{$_} = $opt->{$_} if exists $opt->{$_}; -} if ($opt->{help}) { print $help; exit 0 }; my $ng = $opt->{newsgroup} // ''; my $version = $opt->{version} if defined $opt->{version}; my $indexlevel = $opt->{indexlevel} if defined $opt->{indexlevel}; -my $jobs = $opt->{jobs} if defined $opt->{jobs}; my $name = shift @ARGV or $usage_cb->(); my $inboxdir = shift @ARGV or $usage_cb->(); my $http_url = shift @ARGV or $usage_cb->(); @@ -182,7 +177,7 @@ if (-f "$inboxdir/inbox.lock") { $version = 1 unless defined $version; -if ($version == 1 && defined $creat_opt->{'skip-epoch'}) { +if ($version == 1 && defined $opt->{'skip-epoch'}) { die "--skip-epoch is only supported for -V2 inboxes\n"; } @@ -194,14 +189,14 @@ my $ibx = PublicInbox::Inbox->new({ indexlevel => $indexlevel, }); -if (defined $jobs) { +if (defined(my $jobs = $opt->{jobs})) { die "--jobs is only supported for -V2 inboxes\n" if $version == 1; die "--jobs=$jobs must be >= 1\n" if $jobs <= 0; - $creat_opt->{nproc} = $jobs; + $opt->{nproc} = $jobs; } require PublicInbox::InboxWritable; -$ibx = PublicInbox::InboxWritable->new($ibx, $creat_opt); +$ibx = PublicInbox::InboxWritable->new($ibx, $opt); if ($opt->{'skip-docdata'}) { $ibx->{indexlevel} //= 'full'; # ensure init_inbox writes xdb $ibx->{indexlevel} eq 'basic' and -- 2.47.3