diff options
author | Eric Wong <e@80x24.org> | 2023-10-11 07:20:49 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-10-11 22:10:42 +0000 |
commit | 01e282ff7524256e8cc8e32a10baaa642ee76b70 (patch) | |
tree | 9cb80a0ca5ac3b605f1231cb372b8966788bc385 /lib/PublicInbox/LeiRediff.pm | |
parent | fa8bce03925461ef47bb8c7f96e20263da93a825 (diff) | |
download | public-inbox-01e282ff7524256e8cc8e32a10baaa642ee76b70.tar.gz |
This required fixing binmode support a few commits ago, along with properly enabling autoflush in popen_wr instead of setting it on the wrapper ProcessIO class.
Diffstat (limited to 'lib/PublicInbox/LeiRediff.pm')
-rw-r--r-- | lib/PublicInbox/LeiRediff.pm | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/lib/PublicInbox/LeiRediff.pm b/lib/PublicInbox/LeiRediff.pm index b894342b..230f3e83 100644 --- a/lib/PublicInbox/LeiRediff.pm +++ b/lib/PublicInbox/LeiRediff.pm @@ -138,35 +138,30 @@ EOM undef; } -sub wait_requote { # OnDestroy callback - my ($lei, $pid, $old_1) = @_; - $lei->{1} = $old_1; # closes stdin of `perl -pe 's/^/> /'` - waitpid($pid, 0) == $pid or die "BUG(?) waitpid: \$!=$! \$?=$?"; - $lei->child_error($?) if $?; -} +# awaitpid callback +sub wait_requote { $_[1]->child_error($?) if $? } -sub requote ($$) { +sub requote ($$) { # '> ' prefix(es) lei->{1} my ($lei, $pfx) = @_; - my $old_1 = $lei->{1}; - my $opt = { 1 => $old_1, 2 => $lei->{2} }; + my $opt = { 1 => $lei->{1}, 2 => $lei->{2} }; # $^X (perl) is overkill, but maybe there's a weird system w/o sed - my ($w, $pid) = popen_wr([$^X, '-pe', "s/^/$pfx/"], $lei->{env}, $opt); - $w->autoflush(1); - binmode $w, ':utf8'; # incompatible with ProcessIO due to syswrite - $lei->{1} = $w; - PublicInbox::OnDestroy->new(\&wait_requote, $lei, $pid, $old_1); + my $w = popen_wr([$^X, '-pe', "s/^/$pfx/"], $lei->{env}, $opt, + \&wait_requote, $lei); + binmode $w, ':utf8'; + $w; } sub extract_oids { # Eml each_part callback my ($ary, $self) = @_; + my $lei = $self->{lei}; my ($p, undef, $idx) = @$ary; - $self->{lei}->out($p->header_obj->as_string, "\n"); + $lei->out($p->header_obj->as_string, "\n"); my ($s, undef) = msg_part_text($p, $p->content_type || 'text/plain'); defined $s or return; - my $rq; - if ($self->{dqre} && $s =~ s/$self->{dqre}//g) { # '> ' prefix(es) - $rq = requote($self->{lei}, $1) if $self->{lei}->{opt}->{drq}; - } + + $self->{dqre} && $s =~ s/$self->{dqre}//g && $lei->{opt}->{drq} and + local $lei->{1} = requote($lei, $1); + my @top = split($PublicInbox::ViewDiff::EXTRACT_DIFFS, $s); undef $s; my $blobs = $self->{blobs}; # blobs to resolve |