]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
admin: common warn_cb
authorEric Wong <e@80x24.org>
Sat, 14 Dec 2024 14:58:03 +0000 (14:58 +0000)
committerEric Wong <e@80x24.org>
Wed, 18 Dec 2024 21:42:16 +0000 (21:42 +0000)
I noticed verbose output from t/extsearch.t was not correctly
commenting out (`# ') informational messages when the
{current_info} prefix is in use.  This also appears to affect
other indexers with the exception of the new -cindex.

So consolidate all the common warning code into
PublicInbox::Admin module so we can handle {current_info}
properly in all contexts.

-cindex gets some unnecessary Eml warning filtering, but that's
probably not a real problem and worth the overall code savings
since PublicInbox::Admin is loaded by script/public-inbox-cindex
anyways.

lib/PublicInbox/Admin.pm
lib/PublicInbox/CodeSearchIdx.pm
lib/PublicInbox/ExtSearchIdx.pm
t/extsearch.t

index fb745cf8eacfd1d7c2ac7009db34ee9e1155a24a..f1aec53d2e99d15d215567046ffb1eb1f1815e56 100644 (file)
@@ -266,6 +266,18 @@ sub index_terminate {
        $ibx->git->cleanup;
 }
 
+sub warn_cb ($) {
+       my ($self) = @_;
+       my $cb = $SIG{__WARN__} || \&CORE::warn;
+       sub {
+               return if PublicInbox::Eml::warn_ignore(@_);
+               my @m = @_;
+               $self->{current_info} ne '' && @m && $m[0] =~ s/\A# // and
+                       unshift @m, '# ', $self->{current_info}, ': ';
+               $cb->(@m);
+       }
+}
+
 sub index_inbox {
        my ($ibx, $im, $opt) = @_;
        require PublicInbox::InboxWritable;
@@ -276,10 +288,7 @@ sub index_inbox {
        local @SIG{keys %SIG} = values %SIG;
        setup_signals(\&index_terminate, $ibx);
        my $idx = { current_info => $ibx->{inboxdir} };
-       local $SIG{__WARN__} = sub {
-               return if PublicInbox::Eml::warn_ignore(@_);
-               warn($idx->{current_info}, ': ', @_);
-       };
+       local $SIG{__WARN__} = warn_cb $idx;
        if ($ibx->version == 2) {
                eval { require PublicInbox::V2Writable };
                die "v2 requirements not met: $@\n" if $@;
index 8b5f5ad0353647054df99ed1261c1d0c0263256e..6dc2a7a9fdd6735f57eaf1f75d142ee1f0bae6c9 100644 (file)
@@ -51,6 +51,7 @@ package PublicInbox::CodeSearchIdx;
 use v5.12;
 # parent order matters, we want ->DESTROY from IPC, not SearchIdx
 use parent qw(PublicInbox::CodeSearch PublicInbox::IPC PublicInbox::SearchIdx);
+use PublicInbox::Admin;
 use PublicInbox::DS qw(awaitpid);
 use PublicInbox::PktOp;
 use PublicInbox::IPC qw(nproc_shards);
@@ -1334,13 +1335,7 @@ sub cidx_run { # main entry point
        };
        local @PRUNE_BATCH = @PRUNE_BATCH;
        $MY_SIG->{$_} = \&parent_quit for qw(TERM QUIT INT);
-       my $cb = $SIG{__WARN__} || \&CORE::warn;
-       local $SIG{__WARN__} = sub {
-               my $m = shift @_;
-               $self->{current_info} eq '' or
-                       $m =~ s/\A(#?\s*)/$1$self->{current_info}: /;
-               $cb->($m, @_);
-       };
+       local $SIG{__WARN__} = PublicInbox::Admin::warn_cb $self;
        load_existing($self) unless $self->{-cidx_internal};
        if ($self->{-opt}->{reindex}) {
                require PublicInbox::SharedKV;
index 52d7c3b155d8e1864bebae43a474016500dc8572..4a4799789c32f60dd344f829b464b1aba8e3171f 100644 (file)
@@ -1110,12 +1110,8 @@ EOS
 sub eidx_sync { # main entry point
        my ($self, $opt) = @_;
 
-       my $warn_cb = $SIG{__WARN__} || \&CORE::warn;
        local $self->{current_info} = '';
-       local $SIG{__WARN__} = sub {
-               return if PublicInbox::Eml::warn_ignore(@_);
-               $warn_cb->($self->{current_info}, ': ', @_);
-       };
+       local $SIG{__WARN__} = PublicInbox::Admin::warn_cb $self;
        $self->idx_init($opt); # acquire lock via V2Writable::_idx_init
        $self->{oidx}->rethread_prepare($opt);
        local $self->{need_checkpoint} = 0;
@@ -1386,11 +1382,7 @@ sub eidx_watch { # public-inbox-extindex --watch main loop
        return if $sync->{quit};
        my $oldset = PublicInbox::DS::block_signals();
        local $self->{current_info} = '';
-       my $cb = $SIG{__WARN__} || \&CORE::warn;
-       local $SIG{__WARN__} = sub {
-               return if PublicInbox::Eml::warn_ignore(@_);
-               $cb->($self->{current_info}, ': ', @_);
-       };
+       local $SIG{__WARN__} = PublicInbox::Admin::warn_cb $self;
        my $sig = {
                HUP => sub { eidx_reload($self, $idler) },
                USR1 => sub { eidx_resync_start($self) },
index 7b75c2083dca4dd97622a00198e62b8b4d005c24..6bcfdd841988e8e7f617541c8b915d3a9e2f8b24 100644 (file)
@@ -292,7 +292,7 @@ if ('reindex catches missed messages') {
        is($oidx->eidx_meta($lc_key), $cmt_b, 'lc-v2 stays unchanged');
        my @err = split(/^/, $err);
        is(scalar(@err), 1, 'only one warning') or diag "err=$err";
-       like($err[0], qr/# reindex_unseen/, 'got reindex_unseen message');
+       like $err[0], qr/# .*? reindex_unseen/, 'got reindex_unseen message';
        my $new = $oidx->get_art($max + 1);
        is($new->{subject}, $eml->header('Subject'), 'new message added');