2 # Copyright (C) 2015-2019 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # Basic tool to create a Xapian search index for a git repository
5 # configured for public-inbox.
6 # Usage with libeatmydata <https://www.flamingspork.com/projects/libeatmydata/>
7 # highly recommended: eatmydata public-inbox-index REPO_DIR
11 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
12 my $usage = "public-inbox-index REPO_DIR";
13 use PublicInbox::Admin;
14 PublicInbox::Admin::require_or_die('-index');
21 '--reindex' => \$reindex,
22 '--jobs|j=i' => \$jobs,
24 'L|indexlevel=s' => \$indexlevel,
26 GetOptions(%opts) or die "bad command-line args\n$usage";
27 die "--jobs must be positive\n" if defined $jobs && $jobs < 0;
29 sub usage { print STDERR "Usage: $usage\n"; exit 1 }
31 # do we really care about this message? It's annoying...
32 my $warn = 'public-inbox unconfigured for serving, indexing anyways...';
33 my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, $warn);
34 PublicInbox::Admin::require_or_die('-index');
37 foreach my $ibx (@ibxs) {
38 if (defined $indexlevel && !defined($ibx->{indexlevel})) {
39 # XXX: users can shoot themselves in the foot, with this...
40 $ibx->{indexlevel} = $indexlevel;
42 PublicInbox::Admin::scan_ibx_modules($mods, $ibx);
45 PublicInbox::Admin::require_or_die(keys %$mods);
47 require PublicInbox::SearchIdx;
48 index_inbox($_) for @ibxs;
52 if (ref($repo) && ($repo->{version} || 1) == 2) {
53 eval { require PublicInbox::V2Writable };
54 die "v2 requirements not met: $@\n" if $@;
56 PublicInbox::V2Writable->new($repo, {nproc=>$jobs});
62 my $n = $v2w->{partitions};
63 if ($jobs != ($n + 1)) {
65 "Unable to respect --jobs=$jobs, inbox was created with $n partitions\n";
69 local $SIG{__WARN__} = sub {
70 print STDERR $v2w->{current_info}, ': ', @_;
72 $v2w->index_sync({ reindex => $reindex, prune => $prune });
74 my $s = PublicInbox::SearchIdx->new($repo, 1);
75 $s->index_sync({ reindex => $reindex });