]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
init: move --skip-artnum handling to {-creat_opt}
authorEric Wong <e@80x24.org>
Sat, 18 Jan 2025 01:26:06 +0000 (01:26 +0000)
committerEric Wong <e@80x24.org>
Tue, 21 Jan 2025 22:36:57 +0000 (22:36 +0000)
It makes more sense to have inbox creation options bundled
together and reduces the amount of potentially confusing
positional parameters we must pass around.

lib/PublicInbox/InboxWritable.pm
lib/PublicInbox/V2Writable.pm
script/public-inbox-init

index 1982ac05a89437eda72f29bbb64a691ae7dce80c..a8239f4919fd398150fdf5d8239b585e85dd2186 100644 (file)
@@ -29,7 +29,8 @@ sub assert_usable_dir {
 }
 
 sub _init_v1 {
-       my ($self, $skip_artnum) = @_;
+       my ($self) = @_;
+       my $skip_artnum = ($self->{-creat_opt} // {})->{'skip-artnum'};
        if (defined($self->{indexlevel}) || defined($skip_artnum)) {
                require PublicInbox::SearchIdx;
                require PublicInbox::Msgmap;
@@ -49,14 +50,13 @@ sub _init_v1 {
 }
 
 sub init_inbox {
-       my ($self, $shards, $skip_epoch, $skip_artnum) = @_;
+       my ($self, $shards, $skip_epoch) = @_;
        if ($self->version == 1) {
                my $dir = assert_usable_dir($self);
                PublicInbox::Import::init_bare($dir);
-               $self->with_umask(\&_init_v1, $self, $skip_artnum);
+               $self->with_umask(\&_init_v1, $self);
        } else {
-               my $v2w = importer($self);
-               $v2w->init_inbox($shards, $skip_epoch, $skip_artnum);
+               importer($self)->init_inbox($shards, $skip_epoch);
        }
 }
 
index b5ed7c02ac72e1da6ac22a77f3882243801ec40a..b62d0477efffb85488cd141fc1373a0f152153f5 100644 (file)
@@ -76,7 +76,7 @@ sub new {
 
 # public (for now?)
 sub init_inbox {
-       my ($self, $shards, $skip_epoch, $skip_artnum) = @_;
+       my ($self, $shards, $skip_epoch) = @_;
        if (defined $shards) {
                $self->{parallel} = 0 if $shards == 0;
                $self->{shards} = $shards if $shards > 0;
@@ -85,6 +85,7 @@ sub init_inbox {
        $max = $skip_epoch if (defined($skip_epoch) && !defined($max));
        $self->{mg}->add_epoch($max // 0);
        $self->idx_init;
+       my $skip_artnum = ($self->{ibx}->{-creat_opt} // {})->{'skip-artnum'};
        $self->{mm}->skip_artnum($skip_artnum) if defined $skip_artnum;
        $self->done;
 }
index cf6443f778e2d42f3960e493ac291d4d6e1d93b2..1e479a3ac597aef35e4a928d9e52887dda681415 100755 (executable)
@@ -34,15 +34,16 @@ EOF
 require PublicInbox::Admin;
 PublicInbox::Admin::require_or_die('-base');
 
-my ($version, $indexlevel, $skip_epoch, $skip_artnum, $jobs, $show_help);
+my ($version, $indexlevel, $skip_epoch, $jobs, $show_help);
 my $skip_docdata;
 my $ng = '';
 my (@c_extra, @chdir);
+my $creat_opt = {};
 my %opts = (
        'V|version=i' => \$version,
        'L|index-level|indexlevel=s' => \$indexlevel,
        'S|skip|skip-epoch=i' => \$skip_epoch,
-       'skip-artnum=i' => \$skip_artnum,
+       'skip-artnum=i' => \($creat_opt->{'skip-artnum'}),
        'j|jobs=i' => \$jobs,
        'ng|newsgroup=s' => \$ng,
        'skip-docdata' => \$skip_docdata,
@@ -195,7 +196,6 @@ my $ibx = PublicInbox::Inbox->new({
        indexlevel => $indexlevel,
 });
 
-my $creat_opt = {};
 if (defined $jobs) {
        die "--jobs is only supported for -V2 inboxes\n" if $version == 1;
        die "--jobs=$jobs must be >= 1\n" if $jobs <= 0;
@@ -210,7 +210,7 @@ if ($skip_docdata) {
                die "--skip-docdata ignored with --indexlevel=basic\n";
        $ibx->{-skip_docdata} = $skip_docdata;
 }
-$ibx->init_inbox(0, $skip_epoch, $skip_artnum);
+$ibx->init_inbox(0, $skip_epoch);
 
 my $f = "$inboxdir/description";
 if (sysopen $fh, $f, O_CREAT|O_EXCL|O_WRONLY) {