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-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, T_FILL_THIS_FORM_SHORT 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 BCBC11FA11 for ; Thu, 20 Aug 2020 20:24:58 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 04/23] init: support --help and -? Date: Thu, 20 Aug 2020 20:24:38 +0000 Message-Id: <20200820202457.21042-5-e@yhbt.net> In-Reply-To: <20200820202457.21042-1-e@yhbt.net> References: <20200820202457.21042-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: And speed those up with some lazy loading, too. --- script/public-inbox-init | 79 +++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 29 deletions(-) diff --git a/script/public-inbox-init b/script/public-inbox-init index 1c8066df..6852f64a 100755 --- a/script/public-inbox-init +++ b/script/public-inbox-init @@ -1,57 +1,76 @@ -#!/usr/bin/perl -w +#!perl -w # Copyright (C) 2014-2020 all contributors # License: AGPL-3.0+ -# -# Initializes a public-inbox, basically a wrapper for git-init(1) use strict; -use warnings; -sub usage { - print STDERR < \$version, 'L|index-level|indexlevel=s' => \$indexlevel, 'S|skip|skip-epoch=i' => \$skip_epoch, 'N|skip-artnum=i' => \$skip_artnum, 'j|jobs=i' => \$jobs, + 'help|?' => \$show_help, ); -GetOptions(%opts) or usage(); +my $usage_cb = sub { + print STDERR "Usage: $usage\n"; + exit 1; +}; +GetOptions(%opts) or $usage_cb->(); +if ($show_help) { print $help; exit 0 }; PublicInbox::Admin::indexlevel_ok_or_die($indexlevel) if defined $indexlevel; -my $name = shift @ARGV or usage(); -my $inboxdir = shift @ARGV or usage(); -my $http_url = shift @ARGV or usage(); +my $name = shift @ARGV or $usage_cb->(); +my $inboxdir = shift @ARGV or $usage_cb->(); +my $http_url = shift @ARGV or $usage_cb->(); my (@address) = @ARGV; -@address or usage(); +@address or $usage_cb->(); my %seen; +require PublicInbox::Config; my $pi_config = PublicInbox::Config->default_file; -my $dir = dirname($pi_config); -mkpath($dir); # will croak on fatal errors +require File::Basename; +my $dir = File::Basename::dirname($pi_config); +require File::Path; +File::Path::mkpath($dir); # will croak on fatal errors # first, we grab a flock to prevent simultaneous public-inbox-init # processes from trampling over each other, or exiting with 255 on # O_EXCL failure below. This gets unlocked automatically on exit: +require PublicInbox::Lock; my $lock_obj = { lock_path => "$pi_config.flock" }; PublicInbox::Lock::lock_acquire($lock_obj); # git-config will operate on this (and rename on success): +require File::Temp; my $fh = File::Temp->new(TEMPLATE => 'pi-init-XXXXXXXX', DIR => $dir); # Now, we grab another lock to use git-config(1) locking, so it won't @@ -111,7 +130,8 @@ close($fh) or die "failed to close $pi_config_tmp: $!\n"; my $pfx = "publicinbox.$name"; my @x = (qw/git config/, "--file=$pi_config_tmp"); -$inboxdir = abs_path($inboxdir); +require Cwd; +$inboxdir = Cwd::abs_path($inboxdir); die "`\\n' not allowed in `$inboxdir'\n" if $inboxdir =~ /\n/s; if (-f "$inboxdir/inbox.lock") { if (!defined $version) { @@ -148,6 +168,7 @@ if (defined $jobs) { $creat_opt->{nproc} = $jobs; } +require PublicInbox::InboxWritable; $ibx = PublicInbox::InboxWritable->new($ibx, $creat_opt); $ibx->init_inbox(0, $skip_epoch, $skip_artnum);