]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchIdx.pm
nntp: hdr_msg_id: use named sub for long_response
[public-inbox.git] / lib / PublicInbox / SearchIdx.pm
index 665f673a88d9832be185d80d684467775fc1a200..926fac803264288cf3a298b68c08cba62a59dfec 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2015-2019 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 # based on notmuch, but with no concept of folders, files or flags
 #
@@ -12,7 +12,7 @@ use warnings;
 use base qw(PublicInbox::Search PublicInbox::Lock);
 use PublicInbox::MIME;
 use PublicInbox::InboxWritable;
-use PublicInbox::MID qw/mid_clean id_compress mid_mime mids/;
+use PublicInbox::MID qw/mid_clean id_compress mid_mime mids_for_index/;
 use PublicInbox::MsgIter;
 use Carp qw(croak);
 use POSIX qw(strftime);
@@ -32,7 +32,7 @@ sub new {
        my ($class, $ibx, $creat, $shard) = @_;
        ref $ibx or die "BUG: expected PublicInbox::Inbox object: $ibx";
        my $levels = qr/\A(?:full|medium|basic)\z/;
-       my $mainrepo = $ibx->{mainrepo};
+       my $inboxdir = $ibx->{inboxdir};
        my $version = $ibx->{version} || 1;
        my $indexlevel = 'full';
        my $altid = $ibx->{altid};
@@ -49,7 +49,7 @@ sub new {
        }
        $ibx = PublicInbox::InboxWritable->new($ibx);
        my $self = bless {
-               mainrepo => $mainrepo,
+               inboxdir => $inboxdir,
                -inbox => $ibx,
                git => $ibx->git,
                -altid => $altid,
@@ -58,7 +58,7 @@ sub new {
        }, $class;
        $ibx->umask_prepare;
        if ($version == 1) {
-               $self->{lock_path} = "$mainrepo/ssoma.lock";
+               $self->{lock_path} = "$inboxdir/ssoma.lock";
                my $dir = $self->xdir;
                $self->{over} = PublicInbox::OverIdx->new("$dir/over.sqlite3");
        } elsif ($version == 2) {
@@ -204,11 +204,13 @@ sub index_diff ($$$) {
                        $in_diff = $self->index_old_diff_fn(\%seen, $fa, $fb,
                                                        $xnq);
                } elsif (m!^--- ("?a/.+)!) {
-                       my $fn = (split('/', git_unquote($1), 2))[1];
+                       my $fn = $1;
+                       $fn = (split('/', git_unquote($fn), 2))[1];
                        $seen{$fn}++ or $self->index_diff_inc($fn, 'XDFN', $xnq);
                        $in_diff = 1;
                } elsif (m!^\+\+\+ ("?b/.+)!)  {
-                       my $fn = (split('/', git_unquote($1), 2))[1];
+                       my $fn = $1;
+                       $fn = (split('/', git_unquote($fn), 2))[1];
                        $seen{$fn}++ or $self->index_diff_inc($fn, 'XDFN', $xnq);
                        $in_diff = 1;
                } elsif (/^--- (\S+)/) {
@@ -344,7 +346,7 @@ sub add_xapian ($$$$$) {
 sub add_message {
        # mime = Email::MIME object
        my ($self, $mime, $bytes, $num, $oid, $mid0) = @_;
-       my $mids = mids($mime->header_obj);
+       my $mids = mids_for_index($mime->header_obj);
        $mid0 = $mids->[0] unless defined $mid0; # v1 compatibility
        unless (defined $num) { # v1
                $self->_msgmap_init;
@@ -590,6 +592,7 @@ sub read_log {
                        $newest ||= $latest;
                }
        }
+       close($log) or die "git log failed: \$?=$?";
        # get the leftovers
        foreach my $blob (keys %D) {
                my $mime = do_cat_mail($git, $blob, \$bytes) or next;
@@ -603,7 +606,7 @@ sub _msgmap_init {
        die "BUG: _msgmap_init is only for v1\n" if $self->{version} != 1;
        $self->{mm} ||= eval {
                require PublicInbox::Msgmap;
-               PublicInbox::Msgmap->new($self->{mainrepo}, 1);
+               PublicInbox::Msgmap->new($self->{inboxdir}, 1);
        };
 }
 
@@ -632,7 +635,7 @@ sub _git_log {
                             --no-notes --no-color --no-renames
                             --diff-filter=AM), $range);
        ++$fcount while <$fh>;
-       close $fh;
+       close $fh or die "git log failed: \$?=$?";
        my $high = $self->{mm}->num_highwater;
        $pr->("$fcount\n") if $pr; # continue previous line
        $self->{ntodo} = $fcount;
@@ -713,7 +716,10 @@ sub _index_sync {
        my $xdb = $self->begin_txn_lazy;
        my $mm = _msgmap_init($self);
        do {
-               $xlog = undef;
+               if ($xlog) {
+                       close($xlog) or die "git log failed: \$?=$?";
+                       $xlog = undef;
+               }
                $last_commit = _last_x_commit($self, $mm);
                $lx = reindex_from($opts->{reindex}, $last_commit);