'); - eml_entry($ctx, $eml) . '' . $end; + print { $ctx->zfh } $beg, '
';
+ print { $ctx->{zfh} } eml_entry($ctx, $eml), '', $end;
}
sub next_in_queue ($$) {
@@ -414,15 +413,15 @@ $ctx->{level} = $lvl;
if (!$ghost_ok) { # first non-ghost
$ctx->{-title_html} =
ascii_html($smsg->{subject});
- $ctx->zadd($ctx->html_top);
+ print { $ctx->zfh } $ctx->html_top;
}
return $smsg;
}
# buffer the ghost entry and loop
- $ctx->zadd(ghost_index_entry($ctx, $lvl, $smsg));
+ print { $ctx->zfh } ghost_index_entry($ctx, $lvl, $smsg)
} else { # all done
- $ctx->zadd(join('', thread_adj_level($ctx, 0)));
- $ctx->zadd(${delete($ctx->{skel})});
+ print { $ctx->zfh } thread_adj_level($ctx, 0),
+ ${delete($ctx->{skel})};
return;
}
}
@@ -491,7 +490,7 @@ if ($eml) {
my $smsg = $ctx->{smsg};
if (exists $ctx->{-html_tip}) {
$ctx->{-title_html} = ascii_html($smsg->{subject});
- $ctx->zadd($ctx->html_top);
+ print { $ctx->zfh } $ctx->html_top;
}
return eml_entry($ctx, $eml);
} else {
@@ -499,7 +498,7 @@ while (my $smsg = shift @{$ctx->{msgs}}) {
return $smsg if exists($smsg->{blob});
}
my $skel = delete($ctx->{skel}) or return; # all done
- $ctx->zadd($$skel);
+ print { $ctx->zfh } $$skel;
undef;
}
}
@@ -560,8 +559,9 @@ my ($part, $depth, $idx) = @$p;
my $ct = $part->content_type || 'text/plain';
my $fn = $part->filename;
my ($s, $err) = msg_part_text($part, $ct);
- $s // return $ctx->zadd(attach_link($ctx, $ct, $p, $fn) // '');
- my $buf = $part->{is_submsg} ? submsg_hdr($ctx, $part)."\n" : '';
+ my $zfh = $ctx->zfh;
+ $s // return print $zfh (attach_link($ctx, $ct, $p, $fn) // '');
+ say $zfh submsg_hdr($ctx, $part) if $part->{is_submsg};
# makes no difference to browsers, and don't screw up filename
# link generation in diffs with the extra '%0D'
@@ -609,21 +609,19 @@ my @sections = PublicInbox::MsgIter::split_quotes($s);
undef $s; # free memory
if (defined($fn) || ($depth > 0 && !$part->{is_submsg}) || $err) {
# badly-encoded message with $err? tell the world about it!
- $buf .= attach_link($ctx, $ct, $p, $fn, $err) . "\n";
+ say $zfh attach_link($ctx, $ct, $p, $fn, $err);
}
delete $part->{bdy}; # save memory
- $ctx->zadd($buf);
- undef $buf;
for my $cur (@sections) { # $cur may be huge
if ($cur =~ /\A>/) {
# we use a here to allow users to specify
# their own color for quoted text
- $ctx->zadd(qq(),
- $l->to_html($cur), '');
+ print $zfh qq(),
+ $l->to_html($cur), '';
} elsif ($diff) {
flush_diff($ctx, \$cur);
} else { # regular lines, OK
- $ctx->zadd($l->to_html($cur));
+ print $zfh $l->to_html($cur);
}
undef $cur; # free memory
}
@@ -685,10 +683,10 @@ my $x = ascii_html($mids->[0]);
$hbuf .= qq[Message-ID: <$x> (raw)\n];
}
if (!$nr) { # first (and only) message, common case
- $ctx->zadd($ctx->html_top, $hbuf);
+ print { $ctx->zfh } $ctx->html_top, $hbuf;
} else {
delete $ctx->{-title_html};
- $ctx->zadd($ctx->{-html_tip}, $hbuf);
+ print { $ctx->zfh } $ctx->{-html_tip}, $hbuf;
}
$ctx->{-linkify} //= PublicInbox::Linkify->new;
$hbuf = '';
@@ -699,7 +697,7 @@ for my $h (qw(Message-ID X-Alt-Message-ID)) {
$hbuf .= "$h: $_\n" for ($eml->header_raw($h));
}
$ctx->{-linkify}->linkify_mids('..', \$hbuf, 1); # escapes HTML
- $ctx->zadd($hbuf);
+ print { $ctx->{zfh} } $hbuf;
$hbuf = '';
}
my @irt = $eml->header_raw('In-Reply-To');
@@ -717,7 +715,7 @@ $refs //= references($eml);
$hbuf .= 'References: <'.join(">\n\t<", @$refs).">\n" if @$refs;
}
$ctx->{-linkify}->linkify_mids('..', \$hbuf); # escapes HTML
- $ctx->zadd($hbuf .= "\n");
+ say { $ctx->{zfh} } $hbuf;
1;
}
@@ -771,7 +769,7 @@ # writes to zbuf
sub html_footer {
my ($ctx, $hdr) = @_;
my $upfx = '../';
- my ($related, $skel);
+ my (@related, $skel);
my $foot = '';
my $qry = delete $ctx->{-qry};
if ($qry && $ctx->{ibx}->isrch) {
@@ -786,7 +784,7 @@ local $Text::Wrap::huge = 'overflow';
$q = wrap('', '', $q);
my $rows = ($q =~ tr/\n/\n/) + 1;
$q = ascii_html($q);
- $related = <find likely ancestor, descendant, or conflicting patches for {ibx}->over) {
my $t = ts2str($ctx->{-t_max});
my $t_fmt = fmt_ts($ctx->{-t_max});
- my $fallback = $related ? "\t" : "\t";
+ my $fallback = @related ? "\t" : "\t";
$skel = <~$t_fmt UTC|latest);
}
- $foot .= qq(reply);
# $skel may be big for big threads, don't append it to $foot
- $skel .= ' ' . ($related // '');
- $ctx->zadd($foot, $skel .= msg_reply($ctx, $hdr));
+ print { $ctx->zfh } $foot, qq(reply),
+ $skel, '', @related,
+ msg_reply($ctx, $hdr);
}
sub ghost_parent {
diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm
index 95b615dc7c11a7a2084b57d9a1e1bcaac64300de..5d23881b55c1e9a2c74b2d6afd3c1b0c04954488 100644
--- a/lib/PublicInbox/ViewDiff.pm
+++ b/lib/PublicInbox/ViewDiff.pm
@@ -67,8 +67,8 @@ defined($spfx) ? qq({Q}">$oid) : $oid;
}
# returns true if diffstat anchor written, false otherwise
-sub anchor0 ($$$$) {
- my ($dst, $ctx, $fn, $rest) = @_;
+sub anchor0 ($$$) {
+ my ($ctx, $fn, $rest) = @_;
my $orig = $fn;
@@ -84,15 +84,12 @@
# long filenames will require us to check in anchor1()
push(@{$ctx->{-long_path}}, $fn) if $fn =~ s!\A\.\.\./?!!;
- if (defined(my $attr = to_attr($ctx->{-apfx}.$fn))) {
- $ctx->{-anchors}->{$attr} = 1;
- my $spaces = ($orig =~ s/( +)\z//) ? $1 : '';
- $$dst .= " " .
- ascii_html($orig) . '' . $spaces .
+ my $attr = to_attr($ctx->{-apfx}.$fn) // return;
+ $ctx->{-anchors}->{$attr} = 1;
+ my $spaces = ($orig =~ s/( +)\z//) ? $1 : '';
+ print { $ctx->{zfh} } " ",
+ ascii_html($orig), '', $spaces,
$ctx->{-linkify}->to_html($rest);
- return 1;
- }
- undef;
}
# returns "diff --git" anchor destination, undef otherwise
@@ -156,33 +153,34 @@ } else {
warn "BUG? <$$x> had no ^index line";
}
$$x =~ s!^diff --git!anchor1($ctx, $pb) // 'diff --git'!ems;
- $ctx->zadd(qq($$x));
+ print { $ctx->{zfh} } qq(), $$x, '';
$dctx;
}
sub diff_before_or_after ($$) {
my ($ctx, $x) = @_;
- if (exists $ctx->{-anchors} && $$x =~ /\A(.*?) # likely "---\n"
+ if (exists $ctx->{-anchors} && $$x =~ /\A(.*?) # likely "---\n" # \$1
# diffstat lines:
((?:^\x20(?:[^\n]+?)(?:\x20+\|\x20[^\n]*\n))+)
(\x20[0-9]+\x20files?\x20)changed,([^\n]+\n)
(.*?)\z/msx) { # notes, commit message, etc
my @x = ($5, $4, $3, $2, $1);
+ undef $$x;
my $lnk = $ctx->{-linkify};
- $$x = $lnk->to_html(pop @x); # uninteresting prefix
- for my $l (split(/^/m, pop(@x))) { # per-file diffstat lines
+ my $zfh = $ctx->{zfh};
+ print $zfh $lnk->to_html(pop @x); # $1 uninteresting prefix
+ for my $l (split(/^/m, pop(@x))) { # $2 per-file stat lines
$l =~ /^ (.+)( +\| .*\z)/s and
- anchor0($x, $ctx, $1, $2) and next;
- $$x .= $lnk->to_html($l);
+ anchor0($ctx, $1, $2) and next;
+ print $zfh $lnk->to_html($l);
}
- $$x .= pop @x; # $3 /^ \d+ files? /
my $ch = $ctx->{changed_href} // '#related';
- $$x .= qq(changed,);
- $$x .= ascii_html(pop @x); # $4: insertions/deletions
- # notes, commit message, etc
- $ctx->zadd($$x .= $lnk->to_html(pop @x));
+ print $zfh pop(@x), # $3 /^ \d+ files? /
+ qq(changed,),
+ ascii_html(pop @x), # insertions/deletions
+ $lnk->to_html(@x); # notes, commit message, etc
} else {
- $ctx->zadd($ctx->{-linkify}->to_html($$x));
+ print { $ctx->{zfh} } $ctx->{-linkify}->to_html($$x);
}
}
@@ -195,6 +193,7 @@ undef $$cur; # free memory
my $lnk = $ctx->{-linkify};
my $dctx; # {}, keys: Q, oid_a, oid_b
+ my $zfh = $ctx->zfh;
while (defined(my $x = shift @top)) {
if (scalar(@top) >= 4 &&
@@ -202,7 +201,7 @@ $top[1] =~ $IS_OID &&
$top[0] =~ $IS_OID) {
$dctx = diff_header(\$x, $ctx, \@top);
} elsif ($dctx) {
- my $after = '';
+ open(my $afh, '>>', \(my $after='')) or die "open: $!";
# Quiet "Complex regular subexpression recursion limit"
# warning. Perl will truncate matches upon hitting
@@ -218,25 +217,25 @@ for my $s (split(/((?:(?:^\+[^\n]*\n)+)|
(?:(?:^-[^\n]*\n)+)|
(?:^@@ [^\n]+\n))/xsm, $x)) {
if (!defined($dctx)) {
- $after .= $s;
+ print $afh $s;
} elsif ($s =~ s/\A@@ (\S+) (\S+) @@//) {
- $ctx->zadd(qq() .
- diff_hunk($dctx, $1, $2) .
- $lnk->to_html($s) .
- '');
+ print $zfh qq(),
+ diff_hunk($dctx, $1, $2),
+ $lnk->to_html($s),
+ '';
} elsif ($s =~ /\A\+/) { # $s may be huge
- $ctx->zadd(qq(),
+ print $zfh qq(),
$lnk->to_html($s),
- '');
+ '';
} elsif ($s =~ /\A-- $/sm) { # email sig starts
$dctx = undef;
- $after .= $s;
+ print $afh $s;
} elsif ($s =~ /\A-/) { # $s may be huge
- $ctx->zadd(qq(),
- $lnk->to_html($s),
- '');
+ print $zfh qq(),
+ $lnk->to_html($s),
+ '';
} else { # $s may be huge
- $ctx->zadd($lnk->to_html($s));
+ print $zfh $lnk->to_html($s);
}
}
diff_before_or_after($ctx, \$after) if !$dctx;
diff --git a/lib/PublicInbox/WwwAtomStream.pm b/lib/PublicInbox/WwwAtomStream.pm
index 1c7ae881018773ef91feaab9c37c54769f59a908..33da32443c0f941cb01ce6de07a625b03d176097 100644
--- a/lib/PublicInbox/WwwAtomStream.pm
+++ b/lib/PublicInbox/WwwAtomStream.pm
@@ -146,15 +146,15 @@ my ($email) = PublicInbox::Address::emails($from);
my $name = ascii_html(join(', ', PublicInbox::Address::names($from)));
$email = ascii_html($email // $ctx->{ibx}->{-primary_address});
- $ctx->zadd(
- (delete($ctx->{emit_header}) ? atom_header($ctx, $title) : '').
+ print { $ctx->zfh }
+ (delete($ctx->{emit_header}) ? atom_header($ctx, $title) : ''),
"));
+ qq();
$ctx->{mhref} = $href;
$ctx->{changed_href} = "${href}#related";
$eml->each_part(\&PublicInbox::View::add_text_body, $ctx, 1);
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index 2a318e5e6640cc3071e5b443bb2b6df4de457dab..77b6f9c29e4ec675120cd2b47f5c6f003abb8e2f 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -181,11 +181,12 @@ my $res_hdr = [ 'Content-Type' => 'text/html; charset=UTF-8',
'Content-Length' => undef ];
bless $ctx, __PACKAGE__;
$ctx->{gz} = PublicInbox::GzipFilter::gz_or_noop($res_hdr, $ctx->{env});
+ my @top;
$ctx->{base_url} // do {
- $ctx->zadd(html_top($ctx));
+ @top = html_top($ctx);
$ctx->{base_url} = base_url($ctx);
};
- my $bdy = $ctx->zflush(@_[2..$#_], _html_end($ctx));
+ my $bdy = $ctx->zflush(@top, @_[2..$#_], _html_end($ctx));
$res_hdr->[3] = length($bdy);
[ $code, $res_hdr, [ $bdy ] ]
}
@@ -216,7 +217,7 @@ $ctx->{base_url} = base_url($ctx);
my $h = $ctx->{-res_hdr} = ['Content-Type', 'text/html; charset=UTF-8'];
$ctx->{gz} = PublicInbox::GzipFilter::gz_or_noop($h, $ctx->{env});
bless $ctx, __PACKAGE__;
- $ctx->zadd(html_top($ctx));
+ print { $ctx->zfh } html_top($ctx);
}
1;