X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FSearchIdx.pm;h=8810fe76450dde64728d715e4e63f14b3c6bb741;hb=b0e5062d43a96372801713ef78a78d6a1bc852bc;hp=2532c8dfd10d5e73cc12801ad96f212279cefafd;hpb=5e6d44673ba5e9aaeb6d8e63f27adf542c2760a0;p=public-inbox.git diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index 2532c8df..8810fe76 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -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,24 +305,11 @@ 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); - my $body = $part->body; - my @lines = split(/\n/, $body); + my @lines = split(/\n/, $s); while (defined(my $l = shift @lines)) { if ($l =~ /^>/) { $self->index_body(\@orig, $doc) if @orig; @@ -452,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); } @@ -583,7 +570,8 @@ sub read_log { my $blob = $1; if (delete $D{$blob}) { if (defined $self->{regen_down}) { - $self->{regen_down}--; + my $num = $self->{regen_down}--; + $self->{mm}->num_highwater($num); } next; } @@ -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);