From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 12/14] convert: speed up --help
Date: Mon, 10 Aug 2020 02:12:03 +0000 [thread overview]
Message-ID: <20200810021205.18909-13-e@yhbt.net> (raw)
In-Reply-To: <20200810021205.18909-1-e@yhbt.net>
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 <meta@public-inbox.org>
# License: AGPL-3.0+ <http://www.gnu.org/licenses/agpl-3.0.txt>
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 = <<EOF; # the following should fit w/o scrolling in 80x24 term:
usage: $usage
@@ -57,27 +49,33 @@ my $old_dir = shift(@ARGV) or die $usage;
my $new_dir = shift(@ARGV) or die $usage;
die "$new_dir exists\n" if -d $new_dir;
die "$old_dir not a directory\n" unless -d $old_dir;
-my $cfg = PublicInbox::Config->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);
next prev parent reply other threads:[~2020-08-10 2:12 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-10 2:11 [PATCH 00/14] more indexing related improvements Eric Wong
2020-08-10 2:11 ` [PATCH 01/14] index: require --reindex when using --xapian-only Eric Wong
2020-08-10 2:11 ` [PATCH 02/14] index: --sequential-shard works incrementally Eric Wong
2020-08-10 2:11 ` [PATCH 03/14] doc: index: more notes about latest changes Eric Wong
2020-08-10 2:38 ` Kyle Meyer
2020-08-10 6:29 ` Eric Wong
2020-08-10 2:11 ` [PATCH 04/14] doc: add some notes around -xcpdb / -edit / -purge Eric Wong
2020-08-10 2:11 ` [PATCH 05/14] index+xcpdb: improve SIG{INT,TERM,HUP,PIPE} behavior Eric Wong
2020-08-10 2:11 ` [PATCH 06/14] msgmap: tmp_clone: simplify + meaningful filename Eric Wong
2020-08-10 2:11 ` [PATCH 07/14] avoid File::Temp::tempfile in more places Eric Wong
2020-08-10 2:11 ` [PATCH 08/14] admin: use a generic veriable name Eric Wong
2020-08-10 2:38 ` Kyle Meyer
2020-08-10 2:12 ` [PATCH 09/14] index: cleanup internal variables Eric Wong
2020-08-10 2:12 ` [PATCH 10/14] searchidx: use singular `$opt' for consistency with v2 Eric Wong
2020-08-10 2:12 ` [PATCH 11/14] convert: support new -index options Eric Wong
2020-08-10 2:12 ` Eric Wong [this message]
2020-08-10 2:12 ` [PATCH 13/14] convert: check ARGV more correctly Eric Wong
2020-08-10 2:12 ` [PATCH 14/14] convert: set No_COW on copied SQLite files Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200810021205.18909-13-e@yhbt.net \
--to=e@yhbt.net \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).