From: Eric Wong Date: Sun, 16 Jun 2024 23:35:31 +0000 (+0000) Subject: view: share query generation code for related patches X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59b702abc0b0fd9a4456570f3cd44b3663e72cba;p=thirdparty%2Fpublic-inbox.git view: share query generation code for related patches ViewVCS (git commits) and View (mail) can share the same code, and the next change will add subject searches as well. --- diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 7d83d0b46..ecbbc67f1 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -819,25 +819,28 @@ sub thread_skel ($$$) { $ctx->{parent_msg} = $parent; } +sub dfqry_text ($) { + my ($ctx) = @_; + my $qry_dfblob = delete $ctx->{-qry_dfblob} or return (undef); + my $q = join ' ', map { + chop if length > 7; # include 1 abbrev "older" patches + "dfblob:$_"; + } @$qry_dfblob; + local $Text::Wrap::columns = COLS; + local $Text::Wrap::huge = 'overflow'; + $q = wrap('', '', $q); + my $rows = ($q =~ tr/\n/\n/) + 1; + ($rows, ascii_html($q)); +} + # writes to zbuf sub html_footer { my ($ctx, $hdr) = @_; my $upfx = '../'; my (@related, @skel); my $foot = '
';
-	my $qry_dfblob = delete $ctx->{-qry_dfblob};
-	if ($qry_dfblob && $ctx->{ibx}->isrch) {
-		my $q = ''; # search for either ancestor or descendent patches
-		for (@$qry_dfblob) {
-			chop if length > 7; # include 1 abbrev "older" patches
-			$q .= "dfblob:$_ ";
-		}
-		chop $q; # omit trailing SP
-		local $Text::Wrap::columns = COLS;
-		local $Text::Wrap::huge = 'overflow';
-		$q = wrap('', '', $q);
-		my $rows = ($q =~ tr/\n/\n/) + 1;
-		$q = ascii_html($q);
+	my ($rows, $q) = dfqry_text $ctx;
+	if ($rows && $ctx->{ibx}->isrch) {
 		$related[0] = <{-qry_dfblob}) {
-			my $q = '';
-			for (@$qry_dfblob) {
-				# keep blobs as short as reasonable, emails
-				# are going to be older than what's in git
-				substr($_, 7, 64, '');
-				$q .= "dfblob:$_ ";
-			}
-			chop $q; # no trailing SP
-			local $Text::Wrap::columns = PublicInbox::View::COLS;
-			local $Text::Wrap::huge = 'overflow';
-			$q = wrap('', '', $q);
-			my $rows = ($q =~ tr/\n/\n/) + 1;
-			$q = ascii_html($q);
+		my ($rows, $q) = PublicInbox::View::dfqry_text $ctx;
+		if ($rows) {
 			my $ibx_url = ibx_url_for($ctx);
 			my $alt;
 			if (defined $ibx_url) {