]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/V2Writable.pm
update copyrights for 2021
[public-inbox.git] / lib / PublicInbox / V2Writable.pm
index ca52874b6abdc87dc1031dffa9c4e823d42506ec..724fa804356265c4449898f47737351cf624d088 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2018-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # This interface wraps and mimics PublicInbox::Import
@@ -16,7 +16,7 @@ use PublicInbox::ContentHash qw(content_hash content_digest);
 use PublicInbox::InboxWritable;
 use PublicInbox::OverIdx;
 use PublicInbox::Msgmap;
-use PublicInbox::Spawn qw(spawn popen_rd);
+use PublicInbox::Spawn qw(spawn popen_rd run_die);
 use PublicInbox::SearchIdx qw(log2stack crlf_adjust is_ancestor check_size
        is_bad_blob);
 use IO::Handle; # ->autoflush
@@ -24,7 +24,7 @@ use File::Temp ();
 
 my $OID = qr/[a-f0-9]{40,}/;
 # an estimate of the post-packed size to the raw uncompressed size
-my $PACKING_FACTOR = 0.4;
+our $PACKING_FACTOR = 0.4;
 
 # SATA storage lags behind what CPUs are capable of, so relying on
 # nproc(1) can be misleading and having extra Xapian shards is a
@@ -73,13 +73,7 @@ sub count_shards ($) {
                delete $ibx->{search};
                $srch->{nshard} // 0
        } else { # ExtSearchIdx
-               $self->{nshard} // do {
-                       if ($self->xdb_sharded) {
-                               $self->{nshard} // die 'BUG: {nshard} unset';
-                       } else {
-                               0;
-                       }
-               }
+               $self->{nshard} ||= scalar($self->xdb_shards_flat);
        }
 }
 
@@ -751,9 +745,8 @@ sub git_init {
        my ($self, $epoch) = @_;
        my $git_dir = "$self->{ibx}->{inboxdir}/git/$epoch.git";
        PublicInbox::Import::init_bare($git_dir);
-       my @cmd = (qw/git config/, "--file=$git_dir/config",
-                       'include.path', '../../all.git/config');
-       PublicInbox::Import::run_die(\@cmd);
+       run_die([qw(git config), "--file=$git_dir/config",
+               qw(include.path ../../all.git/config)]);
        fill_alternates($self, $epoch);
        $git_dir
 }
@@ -879,7 +872,7 @@ sub reindex_checkpoint ($$) {
                $self->done; # release lock
        }
 
-       if (my $pr = $sync->{-opt}->{-progress}) {
+       if (my $pr = $sync->{-regen_fmt} ? $sync->{-opt}->{-progress} : undef) {
                $pr->(sprintf($sync->{-regen_fmt}, ${$sync->{nr}}));
        }
 
@@ -1104,12 +1097,14 @@ sub sync_prepare ($$) {
                -d $git_dir or next; # missing epochs are fine
                my $git = PublicInbox::Git->new($git_dir);
                my $unit = { git => $git, epoch => $i };
+               my $tip;
                if ($reindex_heads) {
-                       $head = $reindex_heads->[$i] or next;
+                       $tip = $head = $reindex_heads->[$i] or next;
+               } else {
+                       $tip = $git->qx(qw(rev-parse -q --verify), $head);
+                       next if $?; # new repo
+                       chomp $tip;
                }
-               chomp(my $tip = $git->qx(qw(rev-parse -q --verify), $head));
-               next if $?; # new repo
-
                my $range = log_range($sync, $unit, $tip) or next;
                # can't use 'rev-list --count' if we use --diff-filter
                $pr->("$pfx $i.git counting $range ... ") if $pr;
@@ -1226,8 +1221,7 @@ sub unindex_todo ($$$) {
        return if $before == $after;
 
        # ensure any blob can not longer be accessed via dumb HTTP
-       PublicInbox::Import::run_die(['git',
-               "--git-dir=$unit->{git}->{git_dir}",
+       run_die(['git', "--git-dir=$unit->{git}->{git_dir}",
                qw(-c gc.reflogExpire=now gc --prune=all --quiet)]);
 }