-sub index_inbox {
- my ($repo) = @_;
- if (ref($repo) && ($repo->{version} || 1) == 2) {
- eval { require PublicInbox::V2Writable };
- die "v2 requirements not met: $@\n" if $@;
- my $v2w = eval {
- PublicInbox::V2Writable->new($repo, {nproc=>$jobs});
- };
- if (defined $jobs) {
- if ($jobs == 0) {
- $v2w->{parallel} = 0;
- } else {
- my $n = $v2w->{partitions};
- if ($jobs != ($n + 1)) {
- warn
-"Unable to respect --jobs=$jobs, inbox was created with $n partitions\n";
- }
- }
- }
- local $SIG{__WARN__} = sub {
- print STDERR $v2w->{current_info}, ': ', @_;
- };
- $v2w->index_sync({ reindex => $reindex, prune => $prune });
- } else {
- my $s = PublicInbox::SearchIdx->new($repo, 1);
- $s->index_sync({ reindex => $reindex });
+# "Search::Xapian" includes SWIG "Xapian", too:
+$opt->{compact} = 0 if !$mods->{'Search::Xapian'};
+
+PublicInbox::Admin::require_or_die(keys %$mods);
+my $env = PublicInbox::Admin::index_prepare($opt, $cfg);
+local %ENV = (%ENV, %$env) if $env;
+require PublicInbox::InboxWritable;
+PublicInbox::Xapcmd::check_compact() if $opt->{compact};
+PublicInbox::Admin::progress_prepare($opt);
+for my $ibx (@ibxs) {
+ $ibx = PublicInbox::InboxWritable->new($ibx);
+ if ($opt->{compact} >= 2) {
+ PublicInbox::Xapcmd::run($ibx, 'compact', $opt->{compact_opt});
+ }
+ $ibx->{-no_fsync} = 1 if !$opt->{fsync};
+ $ibx->{-dangerous} = 1 if $opt->{dangerous};
+ $ibx->{-skip_docdata} //= $opt->{'skip-docdata'};
+
+ my $ibx_opt = $opt;
+ if (defined(my $s = $ibx->{lc('indexSequentialShard')})) {
+ defined(my $v = $cfg->git_bool($s)) or die <<EOL;
+publicInbox.$ibx->{name}.indexSequentialShard not boolean
+EOL
+ $ibx_opt = { %$opt, 'sequential-shard' => $v };
+ }
+ my $nidx = PublicInbox::Admin::index_inbox($ibx, undef, $ibx_opt);
+ last if $ibx_opt->{quit};
+ if (my $copt = $opt->{compact_opt}) {
+ local $copt->{jobs} = 0 if $ibx_opt->{'sequential-shard'};
+ PublicInbox::Xapcmd::run($ibx, 'compact', $copt);