]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/V2Writable.pm
treewide: "require" + "use" cleanup and docs
[public-inbox.git] / lib / PublicInbox / V2Writable.pm
index ad2e8e62309ab18d3a1979435d8ed539ffa7fe78..6021de4496a5e08b2504bbf5498a0d0d112427c6 100644 (file)
@@ -18,7 +18,7 @@ use PublicInbox::OverIdx;
 use PublicInbox::Msgmap;
 use PublicInbox::Spawn qw(spawn);
 use PublicInbox::SearchIdx;
-use IO::Handle;
+use IO::Handle; # ->autoflush
 use File::Temp qw(tempfile);
 
 # an estimate of the post-packed size to the raw uncompressed size
@@ -62,10 +62,13 @@ sub count_shards ($) {
        # Also, shard count may change while -watch is running
        # due to "xcpdb --reshard"
        if (-d $xpfx) {
+               require PublicInbox::Search;
+               PublicInbox::Search::load_xapian();
+               my $XapianDatabase = $PublicInbox::Search::X{Database};
                foreach my $shard (<$xpfx/*>) {
                        -d $shard && $shard =~ m!/[0-9]+\z! or next;
                        eval {
-                               Search::Xapian::Database->new($shard)->close;
+                               $XapianDatabase->new($shard)->close;
                                $n++;
                        };
                }
@@ -77,7 +80,8 @@ sub new {
        # $creat may be any true value, or 0/undef.  A hashref is true,
        # and $creat->{nproc} may be set to an integer
        my ($class, $v2ibx, $creat) = @_;
-       my $dir = $v2ibx->{inboxdir} or die "no inboxdir in inbox\n";
+       $v2ibx = PublicInbox::InboxWritable->new($v2ibx);
+       my $dir = $v2ibx->assert_usable_dir;
        unless (-d $dir) {
                if ($creat) {
                        require File::Path;
@@ -86,8 +90,6 @@ sub new {
                        die "$dir does not exist\n";
                }
        }
-
-       $v2ibx = PublicInbox::InboxWritable->new($v2ibx);
        $v2ibx->umask_prepare;
 
        my $xpfx = "$dir/xap" . PublicInbox::Search::SCHEMA_VERSION;
@@ -471,7 +473,7 @@ sub git_hash_raw ($$) {
 
        my ($r, $w);
        pipe($r, $w) or die "failed to create pipe: $!";
-       my $rdr = { 0 => fileno($tmp_fh), 1 => fileno($w) };
+       my $rdr = { 0 => $tmp_fh, 1 => $w };
        my $git_dir = $self->{-inbox}->git->{git_dir};
        my $cmd = ['git', "--git-dir=$git_dir", qw(hash-object --stdin)];
        my $pid = spawn($cmd, undef, $rdr);
@@ -1129,6 +1131,7 @@ sub sync_prepare ($$$) {
                                --no-notes --no-color --no-renames
                                --diff-filter=AM), $range, '--', 'm');
                ++$n while <$fh>;
+               close $fh or die "git log failed: \$?=$?";
                $pr->("$n\n") if $pr;
                $regen_max += $n;
        }
@@ -1196,7 +1199,7 @@ sub unindex ($$$$) {
                unindex_oid($self, $git, $1, $unindexed);
        }
        delete $self->{reindex_pipe};
-       $fh = undef;
+       close $fh or die "git log failed: \$?=$?";
 
        return unless $sync->{-opt}->{prune};
        my $after = scalar keys %$unindexed;
@@ -1204,7 +1207,7 @@ sub unindex ($$$$) {
 
        # ensure any blob can not longer be accessed via dumb HTTP
        PublicInbox::Import::run_die(['git', "--git-dir=$git->{git_dir}",
-               qw(-c gc.reflogExpire=now gc --prune=all)]);
+               qw(-c gc.reflogExpire=now gc --prune=all --quiet)]);
 }
 
 sub sync_ranges ($$$) {
@@ -1252,7 +1255,7 @@ sub index_epoch ($$$) {
                        mark_deleted($self, $sync, $git, $1);
                }
        }
-       $fh = undef;
+       close $fh or die "git log failed: \$?=$?";
        delete $self->{reindex_pipe};
        update_last_commit($self, $git, $i, $cmt) if defined $cmt;
 }