]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/SearchIdx.pm
search: support "patchid:" prefix (git patch-id --stable)
[public-inbox.git] / lib / PublicInbox / SearchIdx.pm
index 50e260508a2935dc5ed5bd1e6489cf7fb5be763d..53ec23a5c50c4facfcf1977ea04f2fa4498d8805 100644 (file)
@@ -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