use PublicInbox::OverIdx;
use PublicInbox::Spawn qw(spawn);
use PublicInbox::Git qw(git_unquote);
-
+my $X = \%PublicInbox::Search::X;
+my ($DB_CREATE_OR_OPEN, $DB_OPEN);
use constant {
BATCH_BYTES => defined($ENV{XAPIAN_FLUSH_THRESHOLD}) ?
0x7fffffff : 1_000_000,
undef;
}
+sub load_xapian_writable () {
+ return 1 if $X->{WritableDatabase};
+ PublicInbox::Search::load_xapian() or return;
+ my $xap = $PublicInbox::Search::Xap;
+ for (qw(Document TermGenerator WritableDatabase)) {
+ $X->{$_} = $xap.'::'.$_;
+ }
+ eval 'require '.$X->{WritableDatabase} or die;
+ *sortable_serialise = $xap.'::sortable_serialise';
+ $DB_CREATE_OR_OPEN = eval($xap.'::DB_CREATE_OR_OPEN()');
+ $DB_OPEN = eval($xap.'::DB_OPEN()');
+ 1;
+}
+
sub _xdb_acquire {
my ($self) = @_;
my $flag;
my $dir = $self->xdir;
if (need_xapian($self)) {
croak 'already acquired' if $self->{xdb};
- PublicInbox::Search::load_xapian();
- require Search::Xapian::WritableDatabase;
- $flag = $self->{creat} ?
- Search::Xapian::DB_CREATE_OR_OPEN() :
- Search::Xapian::DB_OPEN();
+ load_xapian_writable();
+ $flag = $self->{creat} ? $DB_CREATE_OR_OPEN : $DB_OPEN;
}
if ($self->{creat}) {
require File::Path;
}
}
return unless defined $flag;
- my $xdb = eval { Search::Xapian::WritableDatabase->new($dir, $flag) };
+ my $xdb = eval { ($X->{WritableDatabase})->new($dir, $flag) };
if ($@) {
die "Failed opening $dir: ", $@;
}
sub add_val ($$$) {
my ($doc, $col, $num) = @_;
- $num = Search::Xapian::sortable_serialise($num);
+ $num = sortable_serialise($num);
$doc->add_value($col, $num);
}
$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+)/) {
/^Binary files .* differ/) {
push @xnq, $_;
} elsif ($_ eq '') {
- $in_diff = undef;
+ # possible to be in diff context, some mail may be
+ # stripped by MUA or even GNU diff(1). "git apply"
+ # treats a bare "\n" as diff context, too
} else {
push @xnq, $_;
warn "non-diff line: $_\n" if DEBUG && $_ ne '';
sub add_xapian ($$$$$) {
my ($self, $mime, $num, $oid, $mids, $mid0) = @_;
my $smsg = PublicInbox::SearchMsg->new($mime);
- my $doc = Search::Xapian::Document->new;
+ my $doc = $X->{Document}->new;
my $subj = $smsg->subject;
add_val($doc, PublicInbox::Search::TS(), $smsg->ts);
my @ds = gmtime($smsg->ds);
my ($head, $tail) = $self->find_doc_ids($termval);
return if $head == $tail;
my @ids;
- for (; $head != $tail && @ids < $batch_size; $head->inc) {
+ for (; $head != $tail && @ids < $batch_size; $head++) {
push @ids, $head->get_docid;
}
$cb->(\@ids);
# there is only ONE element in @delete unless we
# have bugs in our v2writable deduplication check
my @delete;
- for (; $head != $tail; $head->inc) {
+ for (; $head != $tail; $head++) {
my $docid = $head->get_docid;
my $doc = $db->get_document($docid);
my $smsg = PublicInbox::SearchMsg->wrap($mid);
my $tg = $self->{term_generator};
return $tg if $tg;
- $tg = Search::Xapian::TermGenerator->new;
+ $tg = $X->{TermGenerator}->new;
$tg->set_stemmer($self->stemmer);
$self->{term_generator} = $tg;
$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;
--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;
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);