From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/3] www: search patch subject in #related query
Date: Sun, 16 Jun 2024 23:35:32 +0000 [thread overview]
Message-ID: <20240616233532.574646-4-e@80x24.org> (raw)
In-Reply-To: <20240616233532.574646-1-e@80x24.org>
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 | 19 +++++++++++++++----
lib/PublicInbox/ViewDiff.pm | 3 ++-
lib/PublicInbox/ViewVCS.pm | 6 +++---
3 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index eef92a79..d1c954d0 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -701,6 +701,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');
@@ -815,16 +816,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));
}
@@ -835,7 +845,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
diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm
index 9e85699b..7a6d9a2b 100644
--- a/lib/PublicInbox/ViewDiff.pm
+++ b/lib/PublicInbox/ViewDiff.pm
@@ -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;
diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index 6be870c0..b69214bc 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -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;
prev parent reply other threads:[~2024-06-16 23:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-16 23:35 [PATCH 0/3] www: #related patch search improvements Eric Wong
2024-06-16 23:35 ` [PATCH 1/3] www: merge dfblob query data Eric Wong
2024-06-16 23:35 ` [PATCH 2/3] view: share query generation code for related patches Eric Wong
2024-06-16 23:35 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240616233532.574646-4-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).