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,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 96BDA1FA1A for ; Mon, 10 Aug 2020 02:12:07 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 12/14] convert: speed up --help Date: Mon, 10 Aug 2020 02:12:03 +0000 Message-Id: <20200810021205.18909-13-e@yhbt.net> In-Reply-To: <20200810021205.18909-1-e@yhbt.net> References: <20200810021205.18909-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Lazy-loading dependencies speeds up --help by several hundred milliseconds and is a huge step towards user-friendliness. --- script/public-inbox-convert | 39 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/script/public-inbox-convert b/script/public-inbox-convert index ca16b0dc..c9075207 100755 --- a/script/public-inbox-convert +++ b/script/public-inbox-convert @@ -2,16 +2,8 @@ # Copyright (C) 2018-2020 all contributors # License: AGPL-3.0+ use strict; -use warnings; +use v5.10.1; use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev); -use PublicInbox::InboxWritable; -use PublicInbox::Config; -use PublicInbox::Admin; -use PublicInbox::V2Writable; -use PublicInbox::Git; -use PublicInbox::Spawn qw(spawn); -use Cwd 'abs_path'; -use File::Copy 'cp'; # preserves permissions: my $usage = 'Usage: public-inbox-convert [options] OLD NEW'; my $help = <new; + +require Cwd; +Cwd->import('abs_path'); +require PublicInbox::Config; +require PublicInbox::InboxWritable; + $old_dir = abs_path($old_dir); +my $cfg = PublicInbox::Config->new; my $old; $cfg->each_inbox(sub { $old = $_[0] if abs_path($_[0]->{inboxdir}) eq $old_dir; }); -unless ($old) { +if ($old) { + $old = PublicInbox::InboxWritable->new($old); +} else { warn "W: $old_dir not configured in " . PublicInbox::Config::default_file() . "\n"; - $old = { + $old = PublicInbox::InboxWritable->new({ inboxdir => $old_dir, name => 'ignored', + -primary_address => 'old@example.com', address => [ 'old@example.com' ], - }; - $old = PublicInbox::Inbox->new($old); -} -$old = PublicInbox::InboxWritable->new($old); -if ($old->version >= 2) { - die "Only conversion from v1 inboxes is supported\n"; + }); } +die "Only conversion from v1 inboxes is supported\n" if $old->version >= 2; +require PublicInbox::Admin; $old->{indexlevel} //= PublicInbox::Admin::detect_indexlevel($old); my $env; if ($opt->{'index'}) { @@ -100,14 +98,15 @@ sub link_or_copy ($$) { my ($src, $dst) = @_; link($src, $dst) and return; $!{EXDEV} or warn "link $src, $dst failed: $!, trying cp\n"; - cp($src, $dst) or die "cp $src, $dst failed: $!\n"; + require File::Copy; # preserves permissions: + File::Copy::cp($src, $dst) or die "cp $src, $dst failed: $!\n"; } $old->with_umask(sub { my $old_cfg = "$old->{inboxdir}/config"; local $ENV{GIT_CONFIG} = $old_cfg; my $new_cfg = "$new->{inboxdir}/all.git/config"; - $v2w = PublicInbox::V2Writable->new($new, 1); + $v2w = $new->importer(1); $v2w->init_inbox(delete $opt->{jobs}); unlink $new_cfg; link_or_copy($old_cfg, $new_cfg);