From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 5B5981F9F9 for ; Sun, 9 Jun 2019 02:51:49 +0000 (UTC) From: "Eric Wong (Contractor, The Linux Foundation)" To: meta@public-inbox.org Subject: [PATCH 09/11] admin: expose ->config Date: Sun, 9 Jun 2019 02:51:45 +0000 Message-Id: <20190609025147.24966-10-e@80x24.org> In-Reply-To: <20190609025147.24966-1-e@80x24.org> References: <20190609025147.24966-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: No point in forcing admin programs to reparse the config themselves; and we won't support multiple instances of it; unlike the WWW code. --- lib/PublicInbox/Admin.pm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/PublicInbox/Admin.pm b/lib/PublicInbox/Admin.pm index cebd144..8a2f204 100644 --- a/lib/PublicInbox/Admin.pm +++ b/lib/PublicInbox/Admin.pm @@ -9,6 +9,8 @@ use warnings; use Cwd 'abs_path'; use base qw(Exporter); our @EXPORT_OK = qw(resolve_repo_dir); +my $CFG; # all the admin stuff is a singleton +require PublicInbox::Config; sub resolve_repo_dir { my ($cd, $ver) = @_; @@ -78,24 +80,25 @@ sub unconfigured_ibx ($$) { }); } +sub config () { $CFG //= eval { PublicInbox::Config->new } } + sub resolve_inboxes ($;$) { my ($argv, $opt) = @_; - require PublicInbox::Config; require PublicInbox::Inbox; $opt ||= {}; - my $config = eval { PublicInbox::Config->new }; + my $cfg = config(); if ($opt->{all}) { my $cfgfile = PublicInbox::Config::default_file(); - $config or die "--all specified, but $cfgfile not readable\n"; + $cfg or die "--all specified, but $cfgfile not readable\n"; @$argv and die "--all specified, but directories specified\n"; } my $min_ver = $opt->{-min_inbox_version} || 0; my (@old, @ibxs); my %dir2ibx; - if ($config) { - $config->each_inbox(sub { + if ($cfg) { + $cfg->each_inbox(sub { my ($ibx) = @_; $ibx->{version} ||= 1; $dir2ibx{abs_path($ibx->{mainrepo})} = $ibx; -- EW