From: Eric Wong Date: Sun, 16 Jun 2024 23:35:32 +0000 (+0000) Subject: www: search patch subject in #related query X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75f05d887fd08d1fd12af3acbce92b5d38118bb6;p=thirdparty%2Fpublic-inbox.git www: search patch subject in #related query 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. --- diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index ecbbc67f1..9a90f939a 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -705,6 +705,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');
@@ -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 = '
';
-	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 6be870c04..b69214bc8 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;