From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/8] view: generate query in single-message and commit views
Date: Tue, 23 Aug 2022 08:31:56 +0000 [thread overview]
Message-ID: <20220823083203.1128993-2-e@80x24.org> (raw)
In-Reply-To: <20220823083203.1128993-1-e@80x24.org>
The dfblob: search prefix is probably under-utilized, but is
extremely powerful IMHO. To make it easier-to-use, add a search
textarea with it prefilled with values for the existing patch
message. This allows users to easily run a query for all
patches which alter or result in either pre or post-image
blobs in the current patch.
Behavior changes are as follows: "changed" in the diffstat
jumps to the bottom of the message. For /T/ and /t/, it
goes to the "related" anchor which is just above the reply
instructions in the single-message view. For the single
message view, it'll jump to the textarea search form.
I initially wanted to use a normal `<a href=' link, but
figured the textarea is advantageous for two reasons:
1) users should be able to edit the query before submitting
2) crawlers are less likely to waste CPU/disk on forms
It's probably too noisy to add this directly to the /T/ and /t/
views, but seems like a good place to put above the reply
instructions in the single message view.
Note that the queries used by the /$COMMIT_OID/s/ view is
subtly different than the /$MSGID/ view since git will lengthen
its abbreviations over time, while emails are immutable.
I tried adding dfn: (filename) and s: (subject) support, but
couldn't come up with cases where it really made sense for
/$MSGID/. /$COMMIT_OID/s/ may benefit from it, since patchid:
could be flaky due to non-standard diff generation options.
---
lib/PublicInbox/View.pm | 37 +++++++++++++++++++++++++++++++++----
lib/PublicInbox/ViewDiff.pm | 22 ++++++++++++++++------
lib/PublicInbox/ViewVCS.pm | 28 ++++++++++++++++++++++++++++
3 files changed, 77 insertions(+), 10 deletions(-)
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index c28505f1..6bfaf1bb 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -7,6 +7,7 @@ package PublicInbox::View;
use strict;
use v5.10.1;
use List::Util qw(max);
+use Text::Wrap qw(wrap); # stdlib, we need Perl 5.6+ for $huge
use PublicInbox::MsgTime qw(msg_datestamp);
use PublicInbox::Hval qw(ascii_html obfuscate_addrs prurl mid_href
ts2str fmt_ts);
@@ -246,6 +247,7 @@ sub eml_entry {
# scan through all parts, looking for displayable text
$ctx->{mhref} = $mhref;
+ $ctx->{end_id} = "e$id";
$ctx->{obuf} = \$rv;
$eml->each_part(\&add_text_body, $ctx, 1);
delete $ctx->{obuf};
@@ -256,6 +258,9 @@ sub eml_entry {
" <a\nhref=\"${mhref}raw\">raw</a>" .
" <a\nhref=\"${mhref}#R\">reply</a>";
+ delete($ctx->{-qry}) and
+ $rv .= qq[ <a\nhref="${mhref}#related">related</a>];
+
my $hr;
if (defined(my $pct = $smsg->{pct})) { # used by SearchView.pm
$rv .= "\t[relevance $pct%]";
@@ -820,15 +825,38 @@ sub _parent_headers {
# returns a string buffer
sub html_footer {
my ($ctx, $hdr) = @_;
- my $ibx = $ctx->{ibx};
my $upfx = '../';
my $skel;
my $rv = '<pre>';
- if ($ibx->over) {
+ my $related;
+ my $qry = delete $ctx->{-qry};
+ if ($qry && $ctx->{ibx}->isrch) {
+ my $q = ''; # search for either ancestor or descendent patches
+ for (@{$qry->{dfpre}}, @{$qry->{dfpost}}) {
+ 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);
+ $related = <<EOM;
+<form id=related
+action=$upfx
+><pre>find likely ancestor, descendant, or conflicting patches:
+<textarea name=q cols=${\COLS} rows=$rows>$q</textarea>
+<input type=submit value=search
+/>\t(<a href=${upfx}_/text/help/>help</a>)</pre></form>
+EOM
+ }
+ if ($ctx->{ibx}->over) {
my $t = ts2str($ctx->{-t_max});
my $t_fmt = fmt_ts($ctx->{-t_max});
- $skel .= <<EOF;
- other threads:[<a
+ my $fallback = $related ? "\t" : "<a id=related>\t</a>";
+ $skel = <<EOF;
+${fallback}other threads:[<a
href="$upfx?t=$t">~$t_fmt UTC</a>|<a
href="$upfx">newest</a>]
EOF
@@ -869,6 +897,7 @@ EOF
$rv .= qq(<a\nhref="#R">reply</a>);
$rv .= $skel;
$rv .= '</pre>';
+ $rv .= $related // '';
$rv .= msg_reply($ctx, $hdr);
}
diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm
index fb394b7c..960f7e61 100644
--- a/lib/PublicInbox/ViewDiff.pm
+++ b/lib/PublicInbox/ViewDiff.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
#
# used by PublicInbox::View
@@ -141,13 +141,16 @@ sub diff_header ($$$) {
# no need to capture oid_a and oid_b on add/delete,
# we just linkify OIDs directly via s///e in conditional
- if (($$x =~ s/$NULL_TO_BLOB/$1 . oid($dctx, $spfx, $2)/e) ||
- ($$x =~ s/$BLOB_TO_NULL/
- 'index ' . oid($dctx, $spfx, $1) . $2/e)) {
+ if ($$x =~ s/$NULL_TO_BLOB/$1 . oid($dctx, $spfx, $2)/e) {
+ push @{$ctx->{-qry}->{dfpost}}, $2;
+ } elsif ($$x =~ s/$BLOB_TO_NULL/'index '.oid($dctx, $spfx, $1).$2/e) {
+ push @{$ctx->{-qry}->{dfpre}}, $1;
} elsif ($$x =~ $BLOB_TO_BLOB) {
# modification-only, not add/delete:
# linkify hunk headers later using oid_a and oid_b
@$dctx{qw(oid_a oid_b)} = ($1, $2);
+ push @{$ctx->{-qry}->{dfpre}}, $1;
+ push @{$ctx->{-qry}->{dfpost}}, $2;
} else {
warn "BUG? <$$x> had no ^index line";
}
@@ -172,9 +175,16 @@ sub diff_before_or_after ($$) {
# ok, looks like a diffstat, go line-by-line:
for my $l (split(/^/m, $y)) {
if ($l =~ /^ (.+)( +\| .*\z)/s) {
- anchor0($dst, $ctx, $1, $2) and next;
+ anchor0($dst, $ctx, $1, $2) or
+ $$dst .= $linkify->to_html($l);
+ } elsif ($l =~ s/^( [0-9]+ files? )changed,//) {
+ $$dst .= $1;
+ my $end = $ctx->{end_id} // 'related';
+ $$dst .= "<a href=#$end>changed</a>,";
+ $$dst .= ascii_html($l);
+ } else {
+ $$dst .= $linkify->to_html($l);
}
- $$dst .= $linkify->to_html($l);
}
} else { # commit message, notes, etc
$$dst .= $linkify->to_html($y);
diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm
index 19d34092..dcb5c67f 100644
--- a/lib/PublicInbox/ViewVCS.pm
+++ b/lib/PublicInbox/ViewVCS.pm
@@ -21,6 +21,8 @@ use PublicInbox::WwwStream qw(html_oneshot);
use PublicInbox::Linkify;
use PublicInbox::Tmpfile;
use PublicInbox::ViewDiff qw(flush_diff);
+use PublicInbox::View;
+use Text::Wrap qw(wrap);
use PublicInbox::Hval qw(ascii_html to_filename);
my $hl = eval {
require PublicInbox::HlMod;
@@ -157,6 +159,32 @@ EOM
$bdy =~ s/\r?\n/\n/gs;
flush_diff($ctx, \$bdy);
$ctx->zmore($buf);
+ undef $buf;
+ # TODO: should there be another textarea which attempts to
+ # search for the exact email which was applied to make this
+ # commit?
+ if (my $qry = delete $ctx->{-qry}) {
+ my $q = '';
+ for (@{$qry->{dfpost}}, @{$qry->{dfpre}}) {
+ # 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);
+ $ctx->zmore(<<EOM);
+<hr><form action=$upfx
+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
+/>\t(<a href=${upfx}_/text/help/>help</a>)</pre></form>
+EOM
+ }
}
$x = $ctx->zflush($ctx->_html_end);
my $res_hdr = delete $ctx->{-res_hdr};
next prev parent reply other threads:[~2022-08-23 8:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-23 8:31 [PATCH 0/8] www: diff viewing enhancements Eric Wong
2022-08-23 8:31 ` Eric Wong [this message]
2022-08-24 1:09 ` [PATCH 1/8] view: generate query in single-message and commit views Kyle Meyer
2022-08-23 8:31 ` [PATCH 2/8] viewdiff: linkify diffstats for non-format-patch emails Eric Wong
2022-08-23 8:31 ` [PATCH 3/8] viewvcs: remove patchid line from commit header Eric Wong
2022-08-23 8:31 ` [PATCH 4/8] viewvcs: show commit titles for parent commits Eric Wong
2022-08-23 8:32 ` [PATCH 5/8] viewvcs: separate email and date with spaces Eric Wong
2022-08-23 8:32 ` [PATCH 6/8] ibx_async_cat: access ->{git} directly Eric Wong
2022-08-23 8:32 ` [PATCH 7/8] gzip_filter: ->zmore and ->zflush support multiple args Eric Wong
2022-08-23 8:32 ` [PATCH 8/8] viewvcs: don't wait on slow disks for git commit titles Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220823083203.1128993-2-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
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).