diff options
Diffstat (limited to 'lib/PublicInbox/LeiInspect.pm')
-rw-r--r-- | lib/PublicInbox/LeiInspect.pm | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/lib/PublicInbox/LeiInspect.pm b/lib/PublicInbox/LeiInspect.pm index d7775d4b..576ab2c7 100644 --- a/lib/PublicInbox/LeiInspect.pm +++ b/lib/PublicInbox/LeiInspect.pm @@ -1,4 +1,4 @@ -# Copyright (C) 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> # "lei inspect" general purpose inspector for stuff in SQLite and @@ -12,7 +12,6 @@ use parent qw(PublicInbox::IPC); use PublicInbox::Config; use PublicInbox::MID qw(mids); use PublicInbox::NetReader qw(imap_uri nntp_uri); -use POSIX qw(strftime); use PublicInbox::LeiOverview; *iso8601 = \&PublicInbox::LeiOverview::iso8601; @@ -97,7 +96,6 @@ sub _inspect_doc ($$) { my $term = ($1 // ''); push @{$ent->{terms}->{$term}}, $tn; } - @$_ = sort(@$_) for values %{$ent->{terms} // {}}; $cur = $doc->values_begin; $end = $doc->values_end; for (; $cur != $end; $cur++) { @@ -235,7 +233,8 @@ sub inspect_argv { # via wq_do $lei->{1}->autoflush(0); $lei->out('[') if $multi; while (defined(my $x = shift @$argv)) { - inspect1($lei, $x, scalar(@$argv)) or return; + eval { inspect1($lei, $x, scalar(@$argv)) or return }; + warn "E: $@\n" if $@; } $lei->out(']') if $multi; } @@ -250,21 +249,13 @@ sub inspect_start ($$) { $self->wq_close; } -sub ins_add { # InputPipe->consume callback - my ($lei) = @_; # $_[1] = $rbuf - if (defined $_[1]) { - $_[1] eq '' and return eval { - 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: $!"); - } +sub do_inspect { # lei->do_env cb + my ($lei) = @_; + my $str = delete $lei->{stdin_buf}; + PublicInbox::Eml::strip_from($str); + my $eml = PublicInbox::Eml->new(\$str); + inspect_start($lei, [ 'blob:'.$lei->git_oid($eml)->hexdigest, + map { "mid:$_" } @{mids($eml)} ]); } sub lei_inspect { @@ -281,8 +272,7 @@ sub lei_inspect { return $lei->fail(<<'') if @argv; no args allowed on command-line with --stdin - require PublicInbox::InputPipe; - PublicInbox::InputPipe::consume($lei->{0}, \&ins_add, $lei); + $lei->slurp_stdin(\&do_inspect); } else { inspect_start($lei, \@argv); } |