if ($cfg) {
$cfg->each_inbox(sub {
my ($ibx) = @_;
- $ibx->{version} ||= 1;
my $path = abs_path($ibx->{inboxdir});
if (defined($path)) {
$dir2ibx{$path} = $ibx;
}
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;
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 {
} split(/[&;]/, $query);
my $f = $params{file} or die "file: required for $type spec $spec\n";
unless (index($f, '/') == 0) {
- if (($ibx->{version} || 1) == 1) {
+ if ($ibx->version == 1) {
$f = "$ibx->{inboxdir}/public-inbox/$f";
} else {
$f = "$ibx->{inboxdir}/$f";
my $ibx = $ctx->{-inbox};
my $max = $ibx->{feedmax};
my $qp = $ctx->{qp};
- my $v = $ibx->{version} || 1;
+ my $v = $ibx->version;
if ($v > 2) {
die "BUG: unsupported inbox version: $v\n";
}
bless $opts, $class;
}
+sub version { $_[0]->{version} // 1 }
+
sub git_epoch {
my ($self, $epoch) = @_;
- ($self->{version} || 1) == 2 or return;
+ $self->version == 2 or return;
$self->{"$epoch.git"} ||= eval {
my $git_dir = "$self->{inboxdir}/git/$epoch.git";
my $g = PublicInbox::Git->new($git_dir);
my ($self) = @_;
$self->{git} ||= eval {
my $git_dir = $self->{inboxdir};
- $git_dir .= '/all.git' if (($self->{version} || 1) == 2);
+ $git_dir .= '/all.git' if $self->version == 2;
my $g = PublicInbox::Git->new($git_dir);
$g->{-httpbackend_limiter} = $self->{-httpbackend_limiter};
_cleanup_later($self);
sub max_git_epoch {
my ($self) = @_;
- my $v = $self->{version};
- return unless defined($v) && $v == 2;
+ return if $self->version < 2;
my $cur = $self->{-max_git_epoch};
my $changed = git($self)->alternates_changed;
if (!defined($cur) || $changed) {
require PublicInbox::Msgmap;
_cleanup_later($self);
my $dir = $self->{inboxdir};
- if (($self->{version} || 1) >= 2) {
+ if ($self->version >= 2) {
PublicInbox::Msgmap->new_file("$dir/msgmap.sqlite3");
} else {
PublicInbox::Msgmap->new($dir);
# TODO: maybe stop supporting this
if ($creat_opt) { # for { nproc => $N }
$self->{-creat_opt} = $creat_opt;
- init_inbox($self) if ($self->{version} || 1) == 1;
+ init_inbox($self) if $self->version == 1;
}
$self;
}
sub init_inbox {
my ($self, $shards, $skip_epoch, $skip_artnum) = @_;
# TODO: honor skip_artnum
- my $v = $self->{version} || 1;
- if ($v == 1) {
+ if ($self->version == 1) {
my $dir = assert_usable_dir($self);
PublicInbox::Import::init_bare($dir);
} else {
sub importer {
my ($self, $parallel) = @_;
- my $v = $self->{version} || 1;
+ my $v = $self->version;
if ($v == 2) {
eval { require PublicInbox::V2Writable };
die "v2 not supported: $@\n" if $@;
# v2 keeps msgmap open, which causes conflicts for filters
# such as PublicInbox::Filter::RubyLang which overload msgmap
# for a predictable serial number.
- if ($im && ($self->{version} || 1) >= 2 && $self->{altid}) {
+ if ($im && $self->version >= 2 && $self->{altid}) {
$im->done;
}
my $self = bless {
inboxdir => $ibx->{inboxdir},
altid => $ibx->{altid},
- version => $ibx->{version} // 1,
+ version => $ibx->version,
}, $class;
my $dir = xdir($self, 1);
$self->{over_ro} = PublicInbox::Over->new("$dir/over.sqlite3");
ref $ibx or die "BUG: expected PublicInbox::Inbox object: $ibx";
my $levels = qr/\A(?:full|medium|basic)\z/;
my $inboxdir = $ibx->{inboxdir};
- my $version = $ibx->{version} || 1;
+ my $version = $ibx->version;
my $indexlevel = 'full';
my $altid = $ibx->{altid};
if ($altid) {
sub prepare_reindex ($$$) {
my ($ibx, $im, $reindex) = @_;
- if ($ibx->{version} == 1) {
+ if ($ibx->version == 1) {
my $dir = $ibx->search->xdir(1);
my $xdb = $PublicInbox::Search::X{Database}->new($dir);
if (my $lc = $xdb->get_metadata('last_commit')) {
-d $old or die "$old does not exist\n";
my $tmp = {};
- my $v = $ibx->{version} ||= 1;
my @q;
my $reshard = $opt->{reshard};
if (defined $reshard && $reshard <= 0) {
# we want temporary directories to be as deep as possible,
# so v2 shards can keep "xap$SCHEMA_VERSION" on a separate FS.
- if ($v == 1) {
+ if ($ibx->version == 1) {
if (defined $reshard) {
warn
"--reshard=$reshard ignored for v1 $ibx->{inboxdir}\n";
$old = PublicInbox::Inbox->new($old);
}
$old = PublicInbox::InboxWritable->new($old);
-if (($old->{version} || 1) >= 2) {
+if ($old->version >= 2) {
die "Only conversion from v1 inboxes is supported\n";
}
my $new = { %$old };
my $ibx = $config->lookup($recipient);
my $git = $ibx->git;
my $im;
-if (($ibx->{version} || 1) == 2) {
+if ($ibx->version == 2) {
require PublicInbox::V2Writable;
$im = PublicInbox::V2Writable->new($ibx);
$im->{parallel} = 0; # pointless to be parallel for a single message