]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
avoid redundant $creat_opt hashref in some places
authorEric Wong <e@80x24.org>
Tue, 26 Aug 2025 19:50:51 +0000 (19:50 +0000)
committerEric Wong <e@80x24.org>
Thu, 28 Aug 2025 18:48:22 +0000 (18:48 +0000)
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
script/public-inbox-init

index 4ca8ecf2856ae4c11aa2fcc13b998a526f2a2925..78defa93548e850a9336577acb6d891ec629f954 100755 (executable)
@@ -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 ($$) {
index 489bb995fe076da0f23874567bf3dd69cc5f9ce6..f2291b05c21b22d1da287eb51db516dfe37254c7 100755 (executable)
@@ -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