]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchIdx.pm
Merge commit 'mem'
[public-inbox.git] / lib / PublicInbox / SearchIdx.pm
index ca832ad39d9d2d8520f673d7311127ac66008c3a..8810fe76450dde64728d715e4e63f14b3c6bb741 100644 (file)
@@ -282,7 +282,7 @@ sub index_body ($$$) {
 sub add_xapian ($$$$$) {
        my ($self, $mime, $num, $oid, $mids, $mid0) = @_;
        my $smsg = PublicInbox::SearchMsg->new($mime);
-       my $doc = $smsg->{doc};
+       my $doc = Search::Xapian::Document->new;
        my $subj = $smsg->subject;
        add_val($doc, PublicInbox::Search::TS(), $smsg->ts);
        my @ds = gmtime($smsg->ds);
@@ -305,19 +305,7 @@ sub add_xapian ($$$$$) {
                        $self->index_text($fn, 1, 'XFN');
                }
 
-               return if $ct =~ m!\btext/x?html\b!i;
-
-               my $s = eval { $part->body_str };
-               if ($@) {
-                       if ($ct =~ m!\btext/plain\b!i) {
-                               # Try to assume UTF-8 because Alpine
-                               # seems to do wacky things and set
-                               # charset=X-UNKNOWN
-                               $part->charset_set('UTF-8');
-                               $s = eval { $part->body_str };
-                               $s = $part->body if $@;
-                       }
-               }
+               my ($s, undef) = msg_part_text($part, $ct);
                defined $s or return;
 
                my (@orig, @quot);
@@ -451,8 +439,8 @@ sub remove_by_oid {
        for (; $head != $tail; $head->inc) {
                my $docid = $head->get_docid;
                my $doc = $db->get_document($docid);
-               my $smsg = PublicInbox::SearchMsg->wrap($doc, $mid);
-               $smsg->load_expand;
+               my $smsg = PublicInbox::SearchMsg->wrap($mid);
+               $smsg->load_expand($doc);
                if ($smsg->{blob} eq $oid) {
                        push(@delete, $docid);
                }
@@ -619,6 +607,17 @@ sub _git_log {
        my ($self, $range) = @_;
        my $git = $self->{git};
 
+       if (index($range, '..') < 0) {
+               # don't show annoying git errrors to users who run -index
+               # on empty inboxes
+               $git->qx(qw(rev-parse -q --verify), "$range^0");
+               if ($?) {
+                       open my $fh, '<', '/dev/null' or
+                               die "failed to open /dev/null: $!\n";
+                       return $fh;
+               }
+       }
+
        # Count the new files so they can be added newest to oldest
        # and still have numbers increasing from oldest to newest
        my $fcount = 0;
@@ -647,6 +646,7 @@ sub _git_log {
                                --raw -r --no-abbrev/, $range);
 }
 
+# --is-ancestor requires git 1.8.0+
 sub is_ancestor ($$$) {
        my ($git, $cur, $tip) = @_;
        return 0 unless $git->check($cur);