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";
30 '--reindex' => \$reindex,
31 '--jobs|j=i' => \$jobs,
34 GetOptions(%opts) or die "bad command-line args\n$usage";
35 die "--jobs must be positive\n" if defined $jobs && $jobs < 0;
40 @dirs = map { resolve_repo_dir($_) } @ARGV;
42 @dirs = (resolve_repo_dir());
45 sub usage { print STDERR "Usage: $usage\n"; exit 1 }
48 defined($config) and $config->each_inbox(sub {
51 for my $i (0..$#dirs) {
52 next if $dirs[$i] ne $ibx->{mainrepo};
57 foreach my $dir (@dirs) {
58 if (!ref($dir) && -f "$dir/inbox.lock") { # v2
59 my $ibx = { mainrepo => $dir, name => 'unnamed' };
60 $dir = PublicInbox::Inbox->new($ibx);
67 if (!ref $repo && ! -d $repo) {
68 die "$repo does not appear to be an inbox repository\n";
70 if (ref($repo) && ($repo->{version} || 1) == 2) {
71 eval { require PublicInbox::V2Writable };
72 die "v2 requirements not met: $@\n" if $@;
74 PublicInbox::V2Writable->new($repo, {nproc=>$jobs});
80 my $n = $v2w->{partitions};
81 if ($jobs != ($n + 1)) {
83 "Unable to respect --jobs=$jobs, inbox was created with $n partitions\n";
87 local $SIG{__WARN__} = sub {
88 print STDERR $v2w->{current_info}, ': ', @_;
90 $v2w->index_sync({ reindex => $reindex, prune => $prune });
92 my $s = PublicInbox::SearchIdx->new($repo, 1);
93 $s->index_sync({ reindex => $reindex });