]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchIdx.pm
rewrite Linux nodatacow use in pure Perl w/o system
[public-inbox.git] / lib / PublicInbox / SearchIdx.pm
index 928152ec4df4ee83e773db9af38ab0c293ab58f2..95b14c3a55de4c7adfa6bf58d700a98534850324 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) 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
 #
@@ -20,7 +20,7 @@ use Carp qw(croak carp);
 use POSIX qw(strftime);
 use Time::Local qw(timegm);
 use PublicInbox::OverIdx;
-use PublicInbox::Spawn qw(spawn nodatacow_dir);
+use PublicInbox::Spawn qw(spawn);
 use PublicInbox::Git qw(git_unquote);
 use PublicInbox::MsgTime qw(msg_timestamp msg_datestamp);
 use PublicInbox::Address;
@@ -139,7 +139,8 @@ sub idx_acquire {
                if (!-d $dir && (!$is_shard ||
                                ($is_shard && need_xapian($self)))) {
                        File::Path::mkpath($dir);
-                       nodatacow_dir($dir);
+                       require PublicInbox::Syscall;
+                       PublicInbox::Syscall::nodatacow_dir($dir);
                        $self->{-set_has_threadid_once} = 1;
                }
        }
@@ -259,6 +260,7 @@ sub index_diff ($$$) {
                } elsif (m!^diff --git "?[^/]+/.+ "?[^/]+/.+\z!) {
                        # wait until "---" and "+++" to capture filenames
                        $in_diff = 1;
+                       push @xnq, $_;
                # traditional diff:
                } elsif (m/^diff -(.+) (\S+) (\S+)$/) {
                        my ($opt, $fa, $fb) = ($1, $2, $3);
@@ -451,7 +453,7 @@ sub add_xapian ($$$$) {
 sub _msgmap_init ($) {
        my ($self) = @_;
        die "BUG: _msgmap_init is only for v1\n" if $self->{ibx}->version != 1;
-       $self->{mm} //= eval {
+       $self->{mm} //= do {
                require PublicInbox::Msgmap;
                PublicInbox::Msgmap->new_file($self->{ibx}, 1);
        };
@@ -517,6 +519,12 @@ sub add_eidx_info {
        $self->{xdb}->replace_document($docid, $doc);
 }
 
+sub get_terms {
+       my ($self, $pfx, $docid) = @_;
+       begin_txn_lazy($self);
+       xap_terms($pfx, $self->{xdb}, $docid);
+}
+
 sub remove_eidx_info {
        my ($self, $docid, $eidx_key, $eml) = @_;
        begin_txn_lazy($self);
@@ -889,20 +897,20 @@ sub log2stack ($$$) {
                push @cmd, "--$k=$v";
        }
        my $fh = $git->popen(@cmd, $range);
-       my ($at, $ct, $stk, $cmt);
-       while (<$fh>) {
+       my ($at, $ct, $stk, $cmt, $l);
+       while (defined($l = <$fh>)) {
                return if $sync->{quit};
-               if (/\A([0-9]+)-([0-9]+)-($OID)$/o) {
+               if ($l =~ /\A([0-9]+)-([0-9]+)-($OID)$/o) {
                        ($at, $ct, $cmt) = ($1 + 0, $2 + 0, $3);
                        $stk //= PublicInbox::IdxStack->new($cmt);
-               } elsif (/$del/) {
+               } elsif ($l =~ /$del/) {
                        my $oid = $1;
                        if ($D) { # reindex case
                                $D->{pack('H*', $oid)}++;
                        } else { # non-reindex case:
                                $stk->push_rec('d', $at, $ct, $oid, $cmt);
                        }
-               } elsif (/$add/) {
+               } elsif ($l =~ /$add/) {
                        my $oid = $1;
                        if ($D) {
                                my $oid_bin = pack('H*', $oid);