]> Sergey Matveev's repositories - public-inbox.git/commitdiff
search: support "patchid:" prefix (git patch-id --stable)
authorEric Wong <e@80x24.org>
Mon, 20 Jun 2022 19:27:29 +0000 (19:27 +0000)
committerEric Wong <e@80x24.org>
Tue, 21 Jun 2022 10:39:10 +0000 (10:39 +0000)
This allows easy searching via patch-id from a git commit.

Currently, abbreviations are not supported, and it seems
needless to support them since AFAIK (git) doesn't generate
nor resolve abbreviated patch-ids anywhere.

TODO
lib/PublicInbox/Search.pm
lib/PublicInbox/SearchIdx.pm
t/extsearch.t
t/v2mda.t

diff --git a/TODO b/TODO
index 5be4b5e37289dbb2e2bd5d00a248194090c4b733..43eee0638f658aa1ce752b474461ba910c3fc53f 100644 (file)
--- a/TODO
+++ b/TODO
@@ -137,9 +137,6 @@ all need to be considered for everything we introduce)
 * make "git cat-file --batch" detect unlinked packfiles so we don't
   have to restart processes (very long-term)
 
-* support searching based on `git-patch-id --stable` to improve
-  bidirectional mapping of commits <=> emails
-
 * linter to check validity of config file
 
 * linter option and WWW endpoint to graph relationships and flows
index 523003b3c269ae42e9ee210e91415b2846735daa..6f9fdde1bc2276cbc0620c794731f179a00750b1 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 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',
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
index 09cbdabee6c4f0962936bcf39a6cf2fe5ea275a1..2d7375d63f9a6467f3b98b80da2715589ad4b573 100644 (file)
@@ -314,7 +314,12 @@ if ('reindex catches missed messages') {
        is($new->{subject}, $eml->header('Subject'), 'new message added');
 
        $es->{xdb}->reopen;
-       my $mset = $es->mset("mid:$new->{mid}");
+       # git patch-id --stable <t/data/0001.patch | awk '{print $1}'
+       my $patchid = '91ee6b761fc7f47cad9f2b09b10489f313eb5b71';
+       my $mset = $es->search->mset("patchid:$patchid");
+       is($mset->size, 1, 'patchid search works');
+
+       $mset = $es->mset("mid:$new->{mid}");
        is($mset->size, 1, 'previously unseen, now indexed in Xapian');
 
        ok($im->remove($eml), 'remove new message from v2 inbox');
index 3dfc569e1dc9b9e7c20a2eeddb6136d045f5c646..8f2f335d96b8d834cfe5ffd38df13dfc6599595a 100644 (file)
--- a/t/v2mda.t
+++ b/t/v2mda.t
@@ -1,7 +1,8 @@
-# Copyright (C) 2018-2021 all contributors <meta@public-inbox.org>
+#!perl -w
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use v5.10.1;
 use strict;
-use warnings;
 use Test::More;
 use Fcntl qw(SEEK_SET);
 use Cwd;
@@ -88,6 +89,11 @@ is($eml->as_string, $mime->as_string, 'injected message');
        $pre = $ibx->search->mset_to_smsg($ibx, $pre);
        $post = $ibx->search->mset_to_smsg($ibx, $post);
        is($post->[0]->{blob}, $pre->[0]->{blob}, 'same message in both cases');
+
+       # git patch-id --stable <t/data/0001.patch | awk '{print $1}'
+       my $patchid = '91ee6b761fc7f47cad9f2b09b10489f313eb5b71';
+       my $mset = $ibx->search->mset("patchid:$patchid");
+       is($mset->size, 1, 'patchid search works');
 }
 
 done_testing();