From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 398EA1FB13 for ; Sun, 16 Jun 2024 23:35:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1718580934; bh=P3ezh/SVhJgTlTNxTQYByj4VPY2jvRoMT0nk5IQsnfQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VyRpEsp8xJbTYP7QUmW9e8pWF21eR+J4oMUkfWooSfj3s8nb0dTESGV3uzER0JeCb 1+R/Zh8LD8kBMPzABKMFlOkK1oBwsQvFxrPPFPNm3bNQwwbi51CasRLjvVf5/5i9P6 eIqzVPbCnX4JXxlt7obgk1bOE1/CpBUVb9IV0198= From: Eric Wong 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 Message-ID: <20240616233532.574646-4-e@80x24.org> In-Reply-To: <20240616233532.574646-1-e@80x24.org> References: <20240616233532.574646-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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)
];
 		}
 	}
 	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 = '
';
-	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] = <{-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)
 		!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().shift(@$p).' '.shift(@$pt) for @$P;
 	if (@$P == 1) {
@@ -273,7 +273,7 @@ href="$f.patch">patch)\n   parent $P->[0]};
    author $au
 committer $co
 
-$s
+$title_html
 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;