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 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 8F1A91F5D3 for ; Wed, 2 Oct 2024 22:39:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1727908743; bh=W2vy3osdAUKrbcAfJXmTVvPUJESlsdCJdc3uebcthYY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=PWXiwGf8Xc++q9h6u1vSHvxn1o4G/1PRAanN56yfyWryr1tGkVaZJ+4h7nT07GuXn T+D4Z52uiThYFtIDayx9w1EJZ1D1ZMrSucekLVrq49h4bhBkFYlDH58DUbd/EM0eBg 6WGSoLyeRjWHlQwAM7AIEbqlC0sWs5fBo5cPOujw= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH v2 3/3] viewvcs: generate search query for merge commits Date: Wed, 2 Oct 2024 22:39:02 +0000 Message-ID: <20241002223902.4139389-4-e@80x24.org> In-Reply-To: <20241002194448.4123393-1-e@80x24.org> References: <20241002194448.4123393-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Attempt to parse commit titles out of merge commit messages and generate search queries out of them to find the related emails for the individual patch(es). As with all search-related functionality, it's best-effort and inexact, but seems somewhat successful. --- lib/PublicInbox/ViewVCS.pm | 70 ++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm index 49477619..48a16c11 100644 --- a/lib/PublicInbox/ViewVCS.pm +++ b/lib/PublicInbox/ViewVCS.pm @@ -154,7 +154,7 @@ sub do_check_async { } } -sub cmt_hdr_prep { # psgi_qx cb +sub cmt_hdr_prep { # psgi_qx cb for "git show" commit output my ($fh, $ctx, $cmt_fin) = @_; return if $ctx->{-qsp_err_h}; # let cmt_fin handle it seek $fh, 0, SEEK_SET; @@ -221,7 +221,26 @@ sub ibx_url_for { wantarray ? (@ret) : $ret[0]; } -sub cmt_fin { # OnDestroy cb +sub prep_merge_titles ($) { + my ($in_titles, @s, $t, @lines); + chomp(@lines = split /^/ms, $_[0]); + for (@lines) { + if (/^\* /) { # * branch/name: + $in_titles = 1; + } elsif ($in_titles) { # commit titles + if (s/^ //) { # break up Xapian phrases + $t = join " AND\n ", map { qq{s:"$_"} } + split /["\x{201c}\x{201d}]+/; + push @s, $t if $t ne 's:"..."'; + } else { # trailing text or trailers? + undef $in_titles; + } + } # else: preamble text + } + @s ? \@s : undef; +} + +sub cmt_fin { # OnDestroy cb for `git show' commit output my ($ctx) = @_; my ($eh, $ep) = delete @$ctx{qw(-qsp_err_h -qsp_err_p)}; if ($eh || $ep) { @@ -242,7 +261,17 @@ sub cmt_fin { # OnDestroy cb $au =~ s/>/>$x/; } $_ = ascii_html($_) for ($au, $co); - my $ibx_url = ibx_url_for($ctx) // $upfx; + my ($merge_titles, $ibx_url, $ibx_url_html, $alt); + $ibx_url = ibx_url_for($ctx); + if (defined $ibx_url) { + $ibx_url =~ m!://! or + substr($ibx_url, 0, 0, '../../../'); + $ibx_url_html = ascii_html($ibx_url); + $alt = " `$ibx_url_html'"; + } else { + $ibx_url = $ibx_url_html = $upfx; + $alt = ''; + } $au =~ s!(> +)([0-9]{4,}-\S+ \S+)! my ($gt, $t) = ($1, $2); $t =~ tr/ :-//d; @@ -258,6 +287,7 @@ title="list contemporary emails">$2) $x = qq{ (patch)\n parent $P->[0]}; } elsif (@$P > 1) { + $merge_titles = 1; $x = qq(\n parents $P->[0]\n); shift @$P; $x .= qq( $_\n) for @$P; @@ -275,7 +305,10 @@ committer $co $title_html EOM - print $zfh "\n", $ctx->{-linkify}->to_html($bdy) if length($bdy); + if (length($bdy)) { + print $zfh "\n", $ctx->{-linkify}->to_html($bdy); + $merge_titles = prep_merge_titles $bdy if $merge_titles; + } undef $bdy; # free memory my $fh = delete $ctx->{patch_fh}; if (-s $fh > $MAX_SIZE) { @@ -293,26 +326,27 @@ EOM # commit? print $zfh ''; my ($rows, $q) = PublicInbox::View::dfqry_text $ctx, $s; - if ($rows) { - my $ibx_url = ibx_url_for($ctx); - my $alt; - if (defined $ibx_url) { - $alt = " `$ibx_url'"; - $ibx_url =~ m!://! or - substr($ibx_url, 0, 0, '../../../'); - $ibx_url = ascii_html($ibx_url); - } else { - $ibx_url = $upfx; - $alt = ''; - } - print $zfh < EOM - } + } + if ($merge_titles) { + print $zfh <
find merged patch emails
+
+
+EOM + undef $merge_titles; } chop($x = <
glossary