]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
import: allow $noisy toggle, simplify `lei rediff'
authorEric Wong <e@80x24.org>
Tue, 26 Nov 2024 21:29:22 +0000 (21:29 +0000)
committerEric Wong <e@80x24.org>
Wed, 27 Nov 2024 20:34:58 +0000 (20:34 +0000)
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.

lib/PublicInbox/Import.pm
lib/PublicInbox/LeiRediff.pm

index ae46c5f400ac9ffb4e07c4579837980b1991d1f6..e6d725fc5563e9da731e8252bc345f846f86d7fd 100644 (file)
@@ -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)';
index 59fee3f6ff12491a8ae5f57201a094680039847e..6df2a96b0406f9829075a49e5c3f883cb47adcbc 100644 (file)
@@ -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;