From 2bac2c5e41de98f9aa50fbf69060a3bdef54f61f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 4 Oct 2023 03:49:19 +0000 Subject: lei: do_env combines fchdir and local This will make switching $lei contexts less error-prone and hopefully save us from some suprising bugs in the future. Followup-to: 759885e60e59 (lei: ensure --stdin sets %ENV and $current_lei, 2023-09-14) --- lib/PublicInbox/LeiInspect.pm | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'lib/PublicInbox/LeiInspect.pm') diff --git a/lib/PublicInbox/LeiInspect.pm b/lib/PublicInbox/LeiInspect.pm index 0455e739..f801610f 100644 --- a/lib/PublicInbox/LeiInspect.pm +++ b/lib/PublicInbox/LeiInspect.pm @@ -251,24 +251,20 @@ sub inspect_start ($$) { $self->wq_close; } +sub do_inspect { # lei->do_env cb + my ($lei) = @_; + my $str = delete $lei->{istr}; + $str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s; + my $eml = PublicInbox::Eml->new(\$str); + inspect_start($lei, [ 'blob:'.$lei->git_oid($eml)->hexdigest, + map { "mid:$_" } @{mids($eml)} ]); +} + sub ins_add { # InputPipe->consume callback my ($lei) = @_; # $_[1] = $rbuf - if (defined $_[1]) { - $_[1] eq '' and return eval { - $lei->fchdir; - local %ENV = %{$lei->{env}}; - local $PublicInbox::LEI::current_lei = $lei; - my $str = delete $lei->{istr}; - $str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s; - my $eml = PublicInbox::Eml->new(\$str); - inspect_start($lei, [ - 'blob:'.$lei->git_oid($eml)->hexdigest, - map { "mid:$_" } @{mids($eml)} ]); - }; - $lei->{istr} .= $_[1]; - } else { - $lei->fail("error reading stdin: $!"); - } + $_[1] // return $lei->fail("error reading stdin: $!"); + return $lei->{istr} .= $_[1] if $_[1] ne ''; + $lei->do_env(\&do_inspect); } sub lei_inspect { -- cgit v1.2.3-24-ge0c7