From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id AA2051F4D3 for ; Sat, 14 Dec 2024 14:58:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1734188285; bh=hcEgSZXQN8bu0rmL3ELayNEpfWq8Ty30Y78vkL4ZYZQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=l5YgusT5O5PoYyWEjmqsXXSiGyQQrLsegXROKyTKEGWm3J3Kaph+wUykAeRk9H/l2 8ZcLiVggaGmyFtEZY2rs4t8k+apyQgKgf9zt3vP2vY5OcXS15C3ov0M/sOZyUiqA/l A9yDoo71Ae6cv/hPbCmXQ88bUo6HXQCYvdB/Kfw8= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/3] admin: common warn_cb Date: Sat, 14 Dec 2024 14:58:03 +0000 Message-ID: <20241214145805.755893-3-e@80x24.org> In-Reply-To: <20241214145805.755893-1-e@80x24.org> References: <20241214145805.755893-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 17 +++++++++++++---- lib/PublicInbox/CodeSearchIdx.pm | 9 ++------- lib/PublicInbox/ExtSearchIdx.pm | 12 ++---------- t/extsearch.t | 2 +- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/lib/PublicInbox/Admin.pm b/lib/PublicInbox/Admin.pm index fb745cf8..f1aec53d 100644 --- a/lib/PublicInbox/Admin.pm +++ b/lib/PublicInbox/Admin.pm @@ -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 $@; diff --git a/lib/PublicInbox/CodeSearchIdx.pm b/lib/PublicInbox/CodeSearchIdx.pm index 8b5f5ad0..6dc2a7a9 100644 --- a/lib/PublicInbox/CodeSearchIdx.pm +++ b/lib/PublicInbox/CodeSearchIdx.pm @@ -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; diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm index 52d7c3b1..4a479978 100644 --- a/lib/PublicInbox/ExtSearchIdx.pm +++ b/lib/PublicInbox/ExtSearchIdx.pm @@ -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) }, diff --git a/t/extsearch.t b/t/extsearch.t index 7b75c208..6bcfdd84 100644 --- a/t/extsearch.t +++ b/t/extsearch.t @@ -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');