]> Sergey Matveev's repositories - public-inbox.git/blobdiff - script/public-inbox-index
use PublicInbox::Config::each_inbox where appropriate
[public-inbox.git] / script / public-inbox-index
index db7ebbab6421ec2cc1b849e4259b2ac82d6d745b..73ad9bc4a1c08926f83ccfcde1857f863952e1ee 100755 (executable)
@@ -73,16 +73,14 @@ if (@ARGV) {
 sub usage { print STDERR "Usage: $usage\n"; exit 1 }
 usage() unless @dirs;
 
-foreach my $k (keys %$config) {
-       $k =~ /\Apublicinbox\.([^\.]+)\.mainrepo\z/ or next;
-       my $name = $1;
-       my $v = $config->{$k};
+$config->each_inbox(sub {
+       my ($ibx) = @_;
+
        for my $i (0..$#dirs) {
-               next if $dirs[$i] ne $v;
-               my $ibx = $config->lookup_name($name);
-               $dirs[$i] = $ibx if $ibx;
+               next if $dirs[$i] ne $ibx->{mainrepo};
+               $dirs[$i] = $ibx;
        }
-}
+});
 
 foreach my $dir (@dirs) {
        if (!ref($dir) && -f "$dir/inbox.lock") { # v2
@@ -101,7 +99,7 @@ sub index_dir {
                eval { require PublicInbox::V2Writable };
                die "v2 requirements not met: $@\n" if $@;
                my $v2w = eval {
-                       local $ENV{NPROC} = $jobs if $jobs;
+                       $jobs and local $ENV{NPROC} = $jobs;
                        PublicInbox::V2Writable->new($repo);
                };
                if (defined $jobs) {
@@ -109,7 +107,7 @@ sub index_dir {
                                $v2w->{parallel} = 0;
                        } else {
                                my $n = $v2w->{partitions};
-                               if ($jobs != $n) {
+                               if ($jobs != ($n + 1)) {
                                        warn
 "Unable to respect --jobs=$jobs, inbox was created with $n partitions\n";
                                }