about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/Search.pm5
-rw-r--r--lib/PublicInbox/SearchIdx.pm15
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index 523003b3..6f9fdde1 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -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 or flags
 #
@@ -118,9 +118,10 @@ my %bool_pfx_external = (
         dfpre => 'XDFPRE',
         dfpost => 'XDFPOST',
         dfblob => 'XDFPRE XDFPOST',
+        patchid => 'XDFID',
 );
 
-my $non_quoted_body = 'XNQ XDFN XDFA XDFB XDFHH XDFCTX XDFPRE XDFPOST';
+my $non_quoted_body = 'XNQ XDFN XDFA XDFB XDFHH XDFCTX XDFPRE XDFPOST XDFID';
 my %prob_prefix = (
         # for mairix compatibility
         s => 'S',
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 50e26050..53ec23a5 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -18,6 +18,7 @@ use PublicInbox::MsgIter;
 use PublicInbox::IdxStack;
 use Carp qw(croak carp);
 use POSIX qw(strftime);
+use Fcntl qw(SEEK_SET);
 use Time::Local qw(timegm);
 use PublicInbox::OverIdx;
 use PublicInbox::Spawn qw(spawn);
@@ -349,6 +350,20 @@ sub index_xapian { # msg_iter callback
         defined $s or return;
         $_[0]->[0] = $part = undef; # free memory
 
+        if ($s =~ /^(?:diff|---|\+\+\+) /ms) {
+                open(my $fh, '+>:utf8', undef) or die "open: $!";
+                open(my $eh, '+>', undef) or die "open: $!";
+                $fh->autoflush(1);
+                print $fh $s or die "print: $!";
+                sysseek($fh, 0, SEEK_SET) or die "sysseek: $!";
+                my $id = ($self->{ibx} // $self->{eidx})->git->qx(
+                                                [qw(patch-id --stable)],
+                                                {}, { 0 => $fh, 2 => $eh });
+                $id =~ /\A([a-f0-9]{40,})/ and $doc->add_term('XDFID'.$1);
+                seek($eh, 0, SEEK_SET) or die "seek: $!";
+                while (<$eh>) { warn $_ }
+        }
+
         # split off quoted and unquoted blocks:
         my @sections = PublicInbox::MsgIter::split_quotes($s);
         undef $s; # free memory