]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
view: share query generation code for related patches
authorEric Wong <e@80x24.org>
Sun, 16 Jun 2024 23:35:31 +0000 (23:35 +0000)
committerEric Wong <e@80x24.org>
Mon, 17 Jun 2024 07:25:29 +0000 (07:25 +0000)
ViewVCS (git commits) and View (mail) can share the same code,
and the next change will add subject searches as well.

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

index 7d83d0b466a9b70f344848e644846e984b1481b1..ecbbc67f1a8134df5ad333c4bedafb21744d1a32 100644 (file)
@@ -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 = '<pre>';
-       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] = <<EOM;
 <form id=related
 action=$upfx
index b8ff671766a93a041abfd88164ddc58c5a2622c5..6be870c043fa5f502107a748c3dec2082365c336 100644 (file)
@@ -291,20 +291,8 @@ EOM
                # TODO: should there be another textarea which attempts to
                # search for the exact email which was applied to make this
                # commit?
-               if (my $qry_dfblob = delete $ctx->{-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) {