From de1a674545481c779bc49feef028eacc1e181d5d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 28 May 2019 23:48:52 +0000 Subject: index: support --verbose option It doesn't implement progress of batches, yet, but it wires up the parsing of the command-line while preserving output compatibility. This output is NOT meant to be stable. --- lib/PublicInbox/Admin.pm | 18 ++++++++++++++++++ lib/PublicInbox/Xapcmd.pm | 14 +------------- 2 files changed, 19 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/PublicInbox/Admin.pm b/lib/PublicInbox/Admin.pm index 34aa3129..07d8b572 100644 --- a/lib/PublicInbox/Admin.pm +++ b/lib/PublicInbox/Admin.pm @@ -167,4 +167,22 @@ sub index_inbox { } } +sub progress_prepare ($) { + my ($opt) = @_; + + # public-inbox-index defaults to quiet, -xcpdb and -compact do not + if (defined($opt->{quiet}) && $opt->{quiet} < 0) { + $opt->{quiet} = !$opt->{verbose}; + } + if ($opt->{quiet}) { + open my $null, '>', '/dev/null' or + die "failed to open /dev/null: $!\n"; + $opt->{1} = fileno($null); # suitable for spawn() redirect + $opt->{-dev_null} = $null; + } else { + $opt->{verbose} ||= 1; + $opt->{-progress} = sub { print STDERR @_ }; + } +} + 1; diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm index 999819c7..7e3d47fb 100644 --- a/lib/PublicInbox/Xapcmd.pm +++ b/lib/PublicInbox/Xapcmd.pm @@ -86,18 +86,6 @@ sub prepare_reindex ($$) { } } -sub progress_prepare ($) { - my ($opt) = @_; - if ($opt->{quiet}) { - open my $null, '>', '/dev/null' or - die "failed to open /dev/null: $!\n"; - $opt->{1} = fileno($null); - $opt->{-dev_null} = $null; - } else { - $opt->{-progress} = sub { print STDERR @_ }; - } -} - sub same_fs_or_die ($$) { my ($x, $y) = @_; return if ((stat($x))[0] == (stat($y))[0]); # 0 - st_dev @@ -132,7 +120,7 @@ sub process_queue { sub run { my ($ibx, $task, $opt) = @_; # task = 'cpdb' or 'compact' my $cb = \&${\"PublicInbox::Xapcmd::$task"}; - progress_prepare($opt ||= {}); + PublicInbox::Admin::progress_prepare($opt ||= {}); my $dir = $ibx->{mainrepo} or die "no mainrepo in inbox\n"; runnable_or_die($XAPIAN_COMPACT) if $opt->{compact}; my $reindex; # v1:{ from => $x40 }, v2:{ from => [ $x40, $x40, .. ] } } -- cgit v1.2.3-24-ge0c7