]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei up: improve --all=local stderr output
authorEric Wong <e@80x24.org>
Wed, 25 Aug 2021 08:40:39 +0000 (08:40 +0000)
committerEric Wong <e@80x24.org>
Wed, 25 Aug 2021 19:33:49 +0000 (19:33 +0000)
The "# $NR written to $DEST ($total matches)" messages are
arguably the most useful output of "lei up --all=local",
but they get intermixed with progress messages from various
workers.  Queue up these finalization messages and only spit
them out on ->DESTROY.

MANIFEST
lib/PublicInbox/LEI.pm
lib/PublicInbox/LeiFinmsg.pm [new file with mode: 0644]
lib/PublicInbox/LeiUp.pm
lib/PublicInbox/LeiXSearch.pm

index fb9f16bfb37ebb3d8f20a80570aa77754ceed306..cf7268ed19a9783b858b2b6bda47a344950ba77c 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -208,6 +208,7 @@ lib/PublicInbox/LeiDedupe.pm
 lib/PublicInbox/LeiEditSearch.pm
 lib/PublicInbox/LeiExportKw.pm
 lib/PublicInbox/LeiExternal.pm
+lib/PublicInbox/LeiFinmsg.pm
 lib/PublicInbox/LeiForgetMailSync.pm
 lib/PublicInbox/LeiForgetSearch.pm
 lib/PublicInbox/LeiHelp.pm
index 5694e92c92001d755cc3062b7d446edce067cf37..28fe0c836d7a3e842217b9bfd3cf63ac8ece2bf8 100644 (file)
@@ -486,6 +486,12 @@ sub err ($;@) {
 
 sub qerr ($;@) { $_[0]->{opt}->{quiet} or err(shift, @_) }
 
+sub qfin { # show message on finalization (LeiFinmsg)
+       my ($lei, $msg) = @_;
+       return if $lei->{opt}->{quiet};
+       $lei->{fmsg} ? push(@{$lei->{fmsg}}, "$msg\n") : qerr($lei, $msg);
+}
+
 sub fail_handler ($;$$) {
        my ($lei, $code, $io) = @_;
        close($io) if $io; # needed to avoid warnings on SIGPIPE
diff --git a/lib/PublicInbox/LeiFinmsg.pm b/lib/PublicInbox/LeiFinmsg.pm
new file mode 100644 (file)
index 0000000..0ef5f07
--- /dev/null
@@ -0,0 +1,21 @@
+# Copyright (C) all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# Finalization messages, used to queue up a bunch of messages which
+# only get written out on ->DESTROY
+package PublicInbox::LeiFinmsg;
+use strict;
+use v5.10.1;
+
+sub new {
+       my ($cls, $io) = @_;
+       bless [ $io ], $cls;
+}
+
+sub DESTROY {
+       my ($self) = @_;
+       my $io = shift @$self;
+       print $io @$self;
+}
+
+1;
index ba11761a69df86b15c16a33467efe675e327973e..85efd9f5ded69c69341332566d61d2a1f8f6466e 100644 (file)
@@ -48,6 +48,8 @@ sub up1 ($$) {
 
 sub up1_redispatch {
        my ($lei, $out, $op_p) = @_;
+       require PublicInbox::LeiFinmsg;
+       $lei->{fmsg} //= PublicInbox::LeiFinmsg->new($lei->{2});
        my $l = bless { %$lei }, ref($lei);
        $l->{opt} = { %{$l->{opt}} };
        delete $l->{sock};
index 1f83e582055c7ef06d40ffae5b632efbd484778b..b9f0d6924d4ca5c9617435e3d5081cc9c65db16e 100644 (file)
@@ -398,9 +398,12 @@ Error closing $lei->{ovv}->{dst}: $!
        if ($lei->{-progress}) {
                my $tot = $lei->{-mset_total} // 0;
                my $nr = $lei->{-nr_write} // 0;
-               $lei->qerr($l2m ?
-                       "# $nr written to $lei->{ovv}->{dst} ($tot matches)" :
-                       "# $tot matches");
+               if ($l2m) {
+                       $lei->qfin("# $nr written to " .
+                               "$lei->{ovv}->{dst} ($tot matches)");
+               } else {
+                       $lei->qerr("# $tot matches");
+               }
        }
        $lei->start_mua if $start_mua;
        $lei->dclose;