2 # Copyright (C) 2015-2018 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::Config;
14 use PublicInbox::Admin qw(resolve_repo_dir);
16 my $config = eval { PublicInbox::Config->new } || eval {
17 warn "public-inbox unconfigured for serving, indexing anyways...\n";
20 eval { require PublicInbox::SearchIdx };
22 print STDERR "Search::Xapian required for $0\n";
31 '--reindex' => \$reindex,
32 '--jobs|j=i' => \$jobs,
34 'L|indexlevel=s' => \$indexlevel,
36 GetOptions(%opts) or die "bad command-line args\n$usage";
37 die "--jobs must be positive\n" if defined $jobs && $jobs < 0;
42 @dirs = map { resolve_repo_dir($_) } @ARGV;
44 @dirs = (resolve_repo_dir());
47 sub usage { print STDERR "Usage: $usage\n"; exit 1 }
50 defined($config) and $config->each_inbox(sub {
53 for my $i (0..$#dirs) {
54 next if $dirs[$i] ne $ibx->{mainrepo};
59 foreach my $dir (@dirs) {
62 die "$dir does not appear to be an inbox repository\n";
67 indexlevel => $indexlevel,
68 version => -f "$dir/inbox.lock" ? 2 : 1,
70 $dir = PublicInbox::Inbox->new($ibx);
71 } elsif (defined $indexlevel && !defined($dir->{indexlevel})) {
72 # XXX: users can shoot themselves in the foot, with this...
73 $dir->{indexlevel} = $indexlevel;
81 if (ref($repo) && ($repo->{version} || 1) == 2) {
82 eval { require PublicInbox::V2Writable };
83 die "v2 requirements not met: $@\n" if $@;
85 PublicInbox::V2Writable->new($repo, {nproc=>$jobs});
91 my $n = $v2w->{partitions};
92 if ($jobs != ($n + 1)) {
94 "Unable to respect --jobs=$jobs, inbox was created with $n partitions\n";
98 local $SIG{__WARN__} = sub {
99 print STDERR $v2w->{current_info}, ': ', @_;
101 $v2w->index_sync({ reindex => $reindex, prune => $prune });
103 my $s = PublicInbox::SearchIdx->new($repo, 1);
104 $s->index_sync({ reindex => $reindex });