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);
# 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};
" <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%]";
# 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
$rv .= qq(<a\nhref="#R">reply</a>);
$rv .= $skel;
$rv .= '</pre>';
+ $rv .= $related // '';
$rv .= msg_reply($ctx, $hdr);
}
-# 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
# 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";
}
# 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);
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;
$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};