X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FAdmin.pm;h=62ddbe82e707e9a5ff8b1a83d999654b30790992;hb=fb8e7dbd1b711d25d1033c3f5f540ce47f6c0849;hp=44b44b6eb185c311b693d30edf5d0ead3c1bfa4b;hpb=30afcadb13f446c99952883bbaa54e102757b682;p=public-inbox.git
diff --git a/lib/PublicInbox/Admin.pm b/lib/PublicInbox/Admin.pm
index 44b44b6e..62ddbe82 100644
--- a/lib/PublicInbox/Admin.pm
+++ b/lib/PublicInbox/Admin.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2019 all contributors
+# Copyright (C) 2019-2020 all contributors
# License: AGPL-3.0+
# common stuff for administrative command-line tools
@@ -9,7 +9,8 @@ use warnings;
use Cwd 'abs_path';
use base qw(Exporter);
our @EXPORT_OK = qw(resolve_repo_dir);
-require PublicInbox::Config;
+use PublicInbox::Config;
+use PublicInbox::Inbox;
use PublicInbox::Spawn qw(popen_rd);
sub resolve_repo_dir {
@@ -68,10 +69,9 @@ sub unconfigured_ibx ($$) {
sub resolve_inboxes ($;$$) {
my ($argv, $opt, $cfg) = @_;
- require PublicInbox::Inbox;
$opt ||= {};
- $cfg //= eval { PublicInbox::Config->new };
+ $cfg //= PublicInbox::Config->new;
if ($opt->{all}) {
my $cfgfile = PublicInbox::Config::default_file();
$cfg or die "--all specified, but $cfgfile not readable\n";
@@ -84,7 +84,6 @@ sub resolve_inboxes ($;$$) {
if ($cfg) {
$cfg->each_inbox(sub {
my ($ibx) = @_;
- $ibx->{version} ||= 1;
my $path = abs_path($ibx->{inboxdir});
if (defined($path)) {
$dir2ibx{$path} = $ibx;
@@ -97,7 +96,7 @@ EOF
}
if ($opt->{all}) {
my @all = values %dir2ibx;
- @all = grep { $_->{version} >= $min_ver } @all;
+ @all = grep { $_->version >= $min_ver } @all;
push @ibxs, @all;
} else { # directories specified on the command-line
my $i = 0;
@@ -189,7 +188,7 @@ invalid indexlevel=$indexlevel (must be `basic', `medium', or `full')
sub index_inbox {
my ($ibx, $im, $opt) = @_;
my $jobs = delete $opt->{jobs} if $opt;
- if (ref($ibx) && ($ibx->{version} || 1) == 2) {
+ if (ref($ibx) && $ibx->version == 2) {
eval { require PublicInbox::V2Writable };
die "v2 requirements not met: $@\n" if $@;
my $v2w = $im // eval { $ibx->importer(0) } || eval {
@@ -235,4 +234,15 @@ sub progress_prepare ($) {
}
}
+# same unit factors as git:
+sub parse_unsigned ($) {
+ my ($max_size) = @_;
+
+ $$max_size =~ /\A([0-9]+)([kmg])?\z/i or return;
+ my ($n, $unit_factor) = ($1, $2 // '');
+ my %u = ( k => 1024, m => 1024**2, g => 1024**3 );
+ $$max_size = $n * ($u{lc($unit_factor)} // 1);
+ 1;
+}
+
1;