]> Sergey Matveev's repositories - public-inbox.git/blobdiff - script/public-inbox-index
import: cleanup git cat-file processes when ->done
[public-inbox.git] / script / public-inbox-index
index cea357381307fe35b09e628fd185ccd7f1f0c219..db7ebbab6421ec2cc1b849e4259b2ac82d6d745b 100755 (executable)
@@ -23,8 +23,15 @@ if ($@) {
 }
 
 my $reindex;
-my %opts = ( '--reindex' => \$reindex );
+my $prune;
+my $jobs = undef;
+my %opts = (
+       '--reindex' => \$reindex,
+       '--jobs|j=i' => \$jobs,
+       '--prune' => \$prune,
+);
 GetOptions(%opts) or die "bad command-line args\n$usage";
+die "--jobs must be positive\n" if defined $jobs && $jobs < 0;
 
 my @dirs;
 
@@ -93,9 +100,22 @@ sub index_dir {
        if (ref($repo) && ($repo->{version} || 1) == 2) {
                eval { require PublicInbox::V2Writable };
                die "v2 requirements not met: $@\n" if $@;
-               my $v2w = PublicInbox::V2Writable->new($repo);
-               $v2w->reindex;
-               $v2w->done;
+               my $v2w = eval {
+                       local $ENV{NPROC} = $jobs if $jobs;
+                       PublicInbox::V2Writable->new($repo);
+               };
+               if (defined $jobs) {
+                       if ($jobs == 0) {
+                               $v2w->{parallel} = 0;
+                       } else {
+                               my $n = $v2w->{partitions};
+                               if ($jobs != $n) {
+                                       warn
+"Unable to respect --jobs=$jobs, inbox was created with $n partitions\n";
+                               }
+                       }
+               }
+               $v2w->index_sync({ reindex => $reindex, prune => $prune });
        } else {
                my $s = PublicInbox::SearchIdx->new($repo, 1);
                $s->index_sync({ reindex => $reindex });