unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH] viewvcs: generate search query for merge commits
@ 2024-10-02 19:44 Eric Wong
  2024-10-02 22:38 ` [PATCH v2 0/3] viewvcs: commit => query improvements Eric Wong
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Eric Wong @ 2024-10-02 19:44 UTC (permalink / raw)
  To: meta

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 | 66 +++++++++++++++++++++++++++++---------
 1 file changed, 51 insertions(+), 15 deletions(-)

diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index 14c2e4e3..c54a2428 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 ', 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</a>)
 		$x = qq{ (<a
 href="$f.patch">patch</a>)\n   <a href=#parent>parent</a> $P->[0]};
 	} elsif (@$P > 1) {
+		$merge_titles = 1;
 		$x = qq(\n  <a href=#parents>parents</a> $P->[0]\n);
 		shift @$P;
 		$x .= qq(          $_\n) for @$P;
@@ -275,7 +305,10 @@ committer $co
 
 <b>$title_html</b>
 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,17 +326,6 @@ EOM
 		# commit?
 		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;
 </pre><hr><form action="$ibx_url"
 id=related><pre>find related emails, including ancestors/descendants/conflicts
@@ -313,6 +335,20 @@ id=related><pre>find related emails, including ancestors/descendants/conflicts
 EOM
 		}
 	}
+	if ($merge_titles) {
+		print $zfh <<EOM;
+<form action="$ibx_url" id=merged><pre>find merged patch emails
+<textarea name=q cols=78
+EOM
+		my $nr = scalar @$merge_titles;
+		$merge_titles = ascii_html(join ") OR\n(", @$merge_titles);
+		print $zfh 'rows=', $nr, '>(', $merge_titles, <<EOM;
+)</textarea>
+<input type=submit value="search$alt"
+/></pre></form>
+EOM
+		undef $merge_titles;
+	}
 	chop($x = <<EOM);
 <hr><pre>glossary
 --------

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 0/3] viewvcs: commit => query improvements
  2024-10-02 19:44 [PATCH] viewvcs: generate search query for merge commits Eric Wong
@ 2024-10-02 22:38 ` Eric Wong
  2024-10-02 22:39 ` [PATCH v2 1/3] viewvcs: close the <pre> tag if no query is extracted Eric Wong
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2024-10-02 22:38 UTC (permalink / raw)
  To: meta

Threw in some minor formatting and HTML fixups, as well.
Most notably, there is consistently a <hr> before the textarea.

Eric Wong (3):
  viewvcs: close the <pre> tag if no query is extracted
  viewvcs: use wider textarea for search query
  viewvcs: generate search query for merge commits

 lib/PublicInbox/ViewVCS.pm | 75 ++++++++++++++++++++++++++++----------
 1 file changed, 55 insertions(+), 20 deletions(-)

Range-diff against v1:
-:  -------- > 1:  62e2c882 viewvcs: close the <pre> tag if no query is extracted
-:  -------- > 2:  f4b73a39 viewvcs: use wider textarea for search query
1:  8e9b1865 ! 3:  b49fa73f viewvcs: generate search query for merge commits
    @@ lib/PublicInbox/ViewVCS.pm: sub ibx_url_for {
     +			$in_titles = 1;
     +		} elsif ($in_titles) { # commit titles
     +			if (s/^  //) { # break up Xapian phrases
    -+				$t = join ' AND ', map { qq{s:"$_"} }
    ++				$t = join " AND\n ", map { qq{s:"$_"} }
     +					split /["\x{201c}\x{201d}]+/;
     +				push @s, $t if $t ne 's:"..."';
     +			} else { # trailing text or trailers?
    @@ lib/PublicInbox/ViewVCS.pm: committer $co
      	if (-s $fh > $MAX_SIZE) {
     @@ lib/PublicInbox/ViewVCS.pm: EOM
      		# commit?
    + 		print $zfh '</pre>';
      		my ($rows, $q) = PublicInbox::View::dfqry_text $ctx, $s;
    - 		if ($rows) {
    +-		if ($rows) {
     -			my $ibx_url = ibx_url_for($ctx);
     -			my $alt;
     -			if (defined $ibx_url) {
    @@ lib/PublicInbox/ViewVCS.pm: EOM
     -				$ibx_url = $upfx;
     -				$alt = '';
     -			}
    - 			print $zfh <<EOM;
    - </pre><hr><form action="$ibx_url"
    +-			print $zfh <<EOM;
    ++		print $zfh <<EOM if $rows;
    + <hr><form action="$ibx_url"
      id=related><pre>find related emails, including ancestors/descendants/conflicts
    -@@ lib/PublicInbox/ViewVCS.pm: id=related><pre>find related emails, including ancestors/descendants/conflicts
    + <textarea name=q cols=78 rows=$rows>$q</textarea>
    + <input type=submit value="search$alt"
    + />\t(<a href="${ibx_url}_/text/help/">help</a>)</pre></form>
      EOM
    - 		}
    - 	}
    +-		}
    ++	}
     +	if ($merge_titles) {
     +		print $zfh <<EOM;
    -+<form action="$ibx_url" id=merged><pre>find merged patch emails
    ++<hr><form action="$ibx_url" id=merged><pre>find merged patch emails
     +<textarea name=q cols=78
     +EOM
     +		my $nr = scalar @$merge_titles;
    @@ lib/PublicInbox/ViewVCS.pm: id=related><pre>find related emails, including ances
     +/></pre></form>
     +EOM
     +		undef $merge_titles;
    -+	}
    + 	}
      	chop($x = <<EOM);
      <hr><pre>glossary
    - --------

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/3] viewvcs: close the <pre> tag if no query is extracted
  2024-10-02 19:44 [PATCH] viewvcs: generate search query for merge commits Eric Wong
  2024-10-02 22:38 ` [PATCH v2 0/3] viewvcs: commit => query improvements Eric Wong
@ 2024-10-02 22:39 ` Eric Wong
  2024-10-02 22:39 ` [PATCH v2 2/3] viewvcs: use wider textarea for search query Eric Wong
  2024-10-02 22:39 ` [PATCH v2 3/3] viewvcs: generate search query for merge commits Eric Wong
  3 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2024-10-02 22:39 UTC (permalink / raw)
  To: meta

In the odd case we get a patch with no valid query and
no commit title, we still need to close the <pre> tag
we started.
---
 lib/PublicInbox/ViewVCS.pm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index 14c2e4e3..a29789fd 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -291,6 +291,7 @@ EOM
 		# TODO: should there be another textarea which attempts to
 		# search for the exact email which was applied to make this
 		# commit?
+		print $zfh '</pre>';
 		my ($rows, $q) = PublicInbox::View::dfqry_text $ctx, $s;
 		if ($rows) {
 			my $ibx_url = ibx_url_for($ctx);
@@ -305,7 +306,7 @@ EOM
 				$alt = '';
 			}
 			print $zfh <<EOM;
-</pre><hr><form action="$ibx_url"
+<hr><form action="$ibx_url"
 id=related><pre>find related emails, including ancestors/descendants/conflicts
 <textarea name=q cols=${\PublicInbox::View::COLS} rows=$rows>$q</textarea>
 <input type=submit value="search$alt"

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/3] viewvcs: use wider textarea for search query
  2024-10-02 19:44 [PATCH] viewvcs: generate search query for merge commits Eric Wong
  2024-10-02 22:38 ` [PATCH v2 0/3] viewvcs: commit => query improvements Eric Wong
  2024-10-02 22:39 ` [PATCH v2 1/3] viewvcs: close the <pre> tag if no query is extracted Eric Wong
@ 2024-10-02 22:39 ` Eric Wong
  2024-10-02 22:39 ` [PATCH v2 3/3] viewvcs: generate search query for merge commits Eric Wong
  3 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2024-10-02 22:39 UTC (permalink / raw)
  To: meta

We normally wrap text at 72, but the <textarea> can be wider
in case there's long words which aren't broken apart.
With w3m, the enclosing `[' and `]' take up two columns
combined, so it works out to maximizing a standard 80-column
terminal.
---
 lib/PublicInbox/ViewVCS.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index a29789fd..49477619 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -308,7 +308,7 @@ EOM
 			print $zfh <<EOM;
 <hr><form action="$ibx_url"
 id=related><pre>find related emails, including ancestors/descendants/conflicts
-<textarea name=q cols=${\PublicInbox::View::COLS} rows=$rows>$q</textarea>
+<textarea name=q cols=78 rows=$rows>$q</textarea>
 <input type=submit value="search$alt"
 />\t(<a href="${ibx_url}_/text/help/">help</a>)</pre></form>
 EOM

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 3/3] viewvcs: generate search query for merge commits
  2024-10-02 19:44 [PATCH] viewvcs: generate search query for merge commits Eric Wong
                   ` (2 preceding siblings ...)
  2024-10-02 22:39 ` [PATCH v2 2/3] viewvcs: use wider textarea for search query Eric Wong
@ 2024-10-02 22:39 ` Eric Wong
  2024-10-07  8:29   ` Eric Wong
  3 siblings, 1 reply; 6+ messages in thread
From: Eric Wong @ 2024-10-02 22:39 UTC (permalink / raw)
  To: meta

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!(&gt; +)([0-9]{4,}-\S+ \S+)!
 		my ($gt, $t) = ($1, $2);
 		$t =~ tr/ :-//d;
@@ -258,6 +287,7 @@ title="list contemporary emails">$2</a>)
 		$x = qq{ (<a
 href="$f.patch">patch</a>)\n   <a href=#parent>parent</a> $P->[0]};
 	} elsif (@$P > 1) {
+		$merge_titles = 1;
 		$x = qq(\n  <a href=#parents>parents</a> $P->[0]\n);
 		shift @$P;
 		$x .= qq(          $_\n) for @$P;
@@ -275,7 +305,10 @@ committer $co
 
 <b>$title_html</b>
 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 '</pre>';
 		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;
+		print $zfh <<EOM if $rows;
 <hr><form action="$ibx_url"
 id=related><pre>find related emails, including ancestors/descendants/conflicts
 <textarea name=q cols=78 rows=$rows>$q</textarea>
 <input type=submit value="search$alt"
 />\t(<a href="${ibx_url}_/text/help/">help</a>)</pre></form>
 EOM
-		}
+	}
+	if ($merge_titles) {
+		print $zfh <<EOM;
+<hr><form action="$ibx_url" id=merged><pre>find merged patch emails
+<textarea name=q cols=78
+EOM
+		my $nr = scalar @$merge_titles;
+		$merge_titles = ascii_html(join ") OR\n(", @$merge_titles);
+		print $zfh 'rows=', $nr, '>(', $merge_titles, <<EOM;
+)</textarea>
+<input type=submit value="search$alt"
+/></pre></form>
+EOM
+		undef $merge_titles;
 	}
 	chop($x = <<EOM);
 <hr><pre>glossary

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 3/3] viewvcs: generate search query for merge commits
  2024-10-02 22:39 ` [PATCH v2 3/3] viewvcs: generate search query for merge commits Eric Wong
@ 2024-10-07  8:29   ` Eric Wong
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2024-10-07  8:29 UTC (permalink / raw)
  To: meta

Eric Wong <e@80x24.org> wrote:
> @@ -275,7 +305,10 @@ committer $co
>  
>  <b>$title_html</b>
>  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;
> +	}

I squashed this in to handle blank commit messages for merges:

diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index 48a16c11..d9df671c 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -334,7 +334,7 @@ id=related><pre>find related emails, including ancestors/descendants/conflicts
 />\t(<a href="${ibx_url}_/text/help/">help</a>)</pre></form>
 EOM
 	}
-	if ($merge_titles) {
+	if (ref $merge_titles) {
 		print $zfh <<EOM;
 <hr><form action="$ibx_url" id=merged><pre>find merged patch emails
 <textarea name=q cols=78

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-10-07  8:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-02 19:44 [PATCH] viewvcs: generate search query for merge commits Eric Wong
2024-10-02 22:38 ` [PATCH v2 0/3] viewvcs: commit => query improvements Eric Wong
2024-10-02 22:39 ` [PATCH v2 1/3] viewvcs: close the <pre> tag if no query is extracted Eric Wong
2024-10-02 22:39 ` [PATCH v2 2/3] viewvcs: use wider textarea for search query Eric Wong
2024-10-02 22:39 ` [PATCH v2 3/3] viewvcs: generate search query for merge commits Eric Wong
2024-10-07  8:29   ` Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).