From: Eric Wong Date: Tue, 26 Nov 2024 21:29:22 +0000 (+0000) Subject: import: allow $noisy toggle, simplify `lei rediff' X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=00105ef4f60983f4656bac6f483c8f437e68df8e;p=thirdparty%2Fpublic-inbox.git import: allow $noisy toggle, simplify `lei rediff' Creating an anonymous sub for $SIG{__WARN__} every time `lei rediff' is called is wasteful. Instead, provide a knob to prevent the unnecessary warning from being emitted by PublicInbox::Import in the first place so we can use the existing warn_ignore_cb. --- diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm index ae46c5f40..e6d725fc5 100644 --- a/lib/PublicInbox/Import.pm +++ b/lib/PublicInbox/Import.pm @@ -22,6 +22,7 @@ use autodie qw(socketpair); use Carp qw(croak); use Socket qw(AF_UNIX SOCK_STREAM); use PublicInbox::IO qw(read_all); +our $noisy = 1; sub default_branch () { state $default_branch = do { @@ -297,7 +298,7 @@ sub extract_cmt_info ($;$) { utf8::encode($email); } else { $email = ''; - warn "no email in From: $from or Sender: $sender\n"; + warn "no email in From: $from or Sender: $sender\n" if $noisy; } # git gets confused with: @@ -309,7 +310,7 @@ sub extract_cmt_info ($;$) { utf8::encode($name); } else { $name = ''; - warn "no name in From: $from or Sender: $sender\n"; + warn "no name in From: $from or Sender: $sender\n" if $noisy; } my $subject = delete($smsg->{Subject}) // '(no subject)'; diff --git a/lib/PublicInbox/LeiRediff.pm b/lib/PublicInbox/LeiRediff.pm index 59fee3f6f..6df2a96b0 100644 --- a/lib/PublicInbox/LeiRediff.pm +++ b/lib/PublicInbox/LeiRediff.pm @@ -223,11 +223,8 @@ sub dequote_add { # Eml each_part callback sub input_eml_cb { # callback for all emails my ($self, $eml) = @_; { - local $SIG{__WARN__} = sub { - return if "@_" =~ /^no email in From: .*? or Sender:/; - return if PublicInbox::Eml::warn_ignore(@_); - warn @_; - }; + local $PublicInbox::Import::noisy; + local $SIG{__WARN__} = \&PublicInbox::Eml::warn_ignore_cb; $self->{tmp_sto}->add_eml($eml); $eml->each_part(\&dequote_add, $self) if $self->{dqre}; $self->{tmp_sto}->done;