]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
www: search patch subject in #related query
authorEric Wong <e@80x24.org>
Sun, 16 Jun 2024 23:35:32 +0000 (23:35 +0000)
committerEric Wong <e@80x24.org>
Mon, 17 Jun 2024 07:25:29 +0000 (07:25 +0000)
Blob OIDs would not be accurate for merges and fuzzy
applications, so include the commit title/Subject to
increase the likelyhood of finding related commits.

lib/PublicInbox/View.pm
lib/PublicInbox/ViewDiff.pm
lib/PublicInbox/ViewVCS.pm

index ecbbc67f1a8134df5ad333c4bedafb21744d1a32..9a90f939aea8bd6f4f671e9a2c6c1b06a48bbb95 100644 (file)
@@ -705,6 +705,7 @@ href="d/">diff</a>)</pre><pre>];
                }
        }
        my @subj = $eml->header('Subject');
+       $ctx->{subj_raw} = $subj[0];
        $hbuf .= "Subject: $_\n" for @subj;
        $title[0] = $subj[0] // '(no subject)';
        $hbuf .= "Date: $_\n" for $eml->header('Date');
@@ -819,16 +820,25 @@ sub thread_skel ($$$) {
        $ctx->{parent_msg} = $parent;
 }
 
-sub dfqry_text ($) {
-       my ($ctx) = @_;
+sub dfqry_text ($$) {
+       my ($ctx, $subj) = @_;
        my $qry_dfblob = delete $ctx->{-qry_dfblob} or return (undef);
-       my $q = join ' ', map {
+       my @bs = split /["\x{201c}\x{201d}]+/, $subj;
+       my $q = join ' ', (@bs ? ('(') : ()), map {
                chop if length > 7; # include 1 abbrev "older" patches
                "dfblob:$_";
        } @$qry_dfblob;
        local $Text::Wrap::columns = COLS;
        local $Text::Wrap::huge = 'overflow';
+       $subj //= '';
+       $subj =~ s/\A\s*(?:amend|fixup|squash)\!\s*//; # --autosquash commands
+       # split on double-quotes for phrases
        $q = wrap('', '', $q);
+       if (@bs) {
+               $q .= " )\n OR (";
+               $q .= qq[\nbs:"$_"] for @bs;
+               $q .= ' )';
+       }
        my $rows = ($q =~ tr/\n/\n/) + 1;
        ($rows, ascii_html($q));
 }
@@ -839,7 +849,8 @@ sub html_footer {
        my $upfx = '../';
        my (@related, @skel);
        my $foot = '<pre>';
-       my ($rows, $q) = dfqry_text $ctx;
+       my ($rows, $q) = dfqry_text $ctx,
+                       delete($ctx->{-qry_subj}) // $ctx->{subj_raw};
        if ($rows && $ctx->{ibx}->isrch) {
                $related[0] = <<EOM;
 <form id=related
index 9e85699b5dcf754b0852d319667ca8ce19ab222c..7a6d9a2b9cbb5469ecf10a187372d24d885d02ab 100644 (file)
@@ -182,9 +182,10 @@ sub diff_before_or_after ($$) {
 sub flush_diff ($$) {
        my ($ctx, $cur) = @_;
 
+       my ($subj) = ($$cur =~ /^Subject:\s*\[[^\]]+\]\s*(.+?)$/sm);
        my @top = split($EXTRACT_DIFFS, $$cur);
        undef $$cur; # free memory
-
+       $ctx->{-qry_subj} = $subj if $subj;
        my $lnk = $ctx->{-linkify};
        my $dctx; # {}, keys: Q, oid_a, oid_b
        my $zfh = $ctx->zfh;
index 6be870c043fa5f502107a748c3dec2082365c336..b69214bc8025468587764028015d09c4b4a0614e 100644 (file)
@@ -251,7 +251,7 @@ href="$ibx_url?t=$t"
 title="list contemporary emails">$2</a>)
                !e;
 
-       $ctx->{-title_html} = $s = $ctx->{-linkify}->to_html($s);
+       my $title_html = $ctx->{-title_html} = $ctx->{-linkify}->to_html($s);
        my ($P, $p, $pt) = delete @$ctx{qw(-cmt_P -cmt_p -cmt_pt)};
        $_ = qq(<a href="$upfx$_/s/">).shift(@$p).'</a> '.shift(@$pt) for @$P;
        if (@$P == 1) {
@@ -273,7 +273,7 @@ href="$f.patch">patch</a>)\n   <a href=#parent>parent</a> $P->[0]};
    author $au
 committer $co
 
-<b>$s</b>
+<b>$title_html</b>
 EOM
        print $zfh "\n", $ctx->{-linkify}->to_html($bdy) if length($bdy);
        undef $bdy; # free memory
@@ -291,7 +291,7 @@ EOM
                # TODO: should there be another textarea which attempts to
                # search for the exact email which was applied to make this
                # commit?
-               my ($rows, $q) = PublicInbox::View::dfqry_text $ctx;
+               my ($rows, $q) = PublicInbox::View::dfqry_text $ctx, $s;
                if ($rows) {
                        my $ibx_url = ibx_url_for($ctx);
                        my $alt;