# $creat may be any true value, or 0/undef. A hashref is true,
# and $creat->{nproc} may be set to an integer
my ($class, $v2ibx, $creat) = @_;
- my $dir = $v2ibx->{mainrepo} or die "no mainrepo in inbox\n";
+ my $dir = $v2ibx->{inboxdir} or die "no inboxdir in inbox\n";
unless (-d $dir) {
if ($creat) {
require File::Path;
# leaking FDs to it...
$self->idx_init;
- my $mid0;
- my $num = num_for($self, $mime, \$mid0);
+ my ($num, $mid0) = v2_num_for($self, $mime);
defined $num or return; # duplicate
defined $mid0 or die "BUG: $mid0 undefined\n";
my $im = $self->importer;
$cmt;
}
-sub num_for {
- my ($self, $mime, $mid0) = @_;
+sub v2_num_for {
+ my ($self, $mime) = @_;
my $mids = mids($mime->header_obj);
if (@$mids) {
my $mid = $mids->[0];
my $num = $self->{mm}->mid_insert($mid);
if (defined $num) { # common case
- $$mid0 = $mid;
- return $num;
- };
+ return ($num, $mid);
+ }
# crap, Message-ID is already known, hope somebody just resent:
foreach my $m (@$mids) {
# easy, don't store duplicates
# note: do not add more diagnostic info here since
# it gets noisy on public-inbox-watch restarts
- return if $existing;
+ return () if $existing;
}
# AltId may pre-populate article numbers (e.g. X-Mail-Count
my $num = $self->{mm}->num_for($mid);
if (defined $num && !$self->{over}->get_art($num)) {
- $$mid0 = $mid;
- return $num;
+ return ($num, $mid);
}
}
$num = $self->{mm}->mid_insert($m);
if (defined $num) {
warn "alternative <$m> for <$mid> found\n";
- $$mid0 = $m;
- return $num;
+ return ($num, $m);
}
}
}
# none of the existing Message-IDs are good, generate a new one:
- num_for_harder($self, $mime, $mid0);
+ v2_num_for_harder($self, $mime);
}
-sub num_for_harder {
- my ($self, $mime, $mid0) = @_;
+sub v2_num_for_harder {
+ my ($self, $mime) = @_;
my $hdr = $mime->header_obj;
my $dig = content_digest($mime);
- $$mid0 = PublicInbox::Import::digest2mid($dig, $hdr);
- my $num = $self->{mm}->mid_insert($$mid0);
+ my $mid0 = PublicInbox::Import::digest2mid($dig, $hdr);
+ my $num = $self->{mm}->mid_insert($mid0);
unless (defined $num) {
# it's hard to spoof the last Received: header
my @recvd = $hdr->header_raw('Received');
$dig->add("Received: $_") foreach (@recvd);
- $$mid0 = PublicInbox::Import::digest2mid($dig, $hdr);
- $num = $self->{mm}->mid_insert($$mid0);
+ $mid0 = PublicInbox::Import::digest2mid($dig, $hdr);
+ $num = $self->{mm}->mid_insert($mid0);
# fall back to a random Message-ID and give up determinism:
until (defined($num)) {
$dig->add(rand);
- $$mid0 = PublicInbox::Import::digest2mid($dig, $hdr);
- warn "using random Message-ID <$$mid0> as fallback\n";
- $num = $self->{mm}->mid_insert($$mid0);
+ $mid0 = PublicInbox::Import::digest2mid($dig, $hdr);
+ warn "using random Message-ID <$mid0> as fallback\n";
+ $num = $self->{mm}->mid_insert($mid0);
}
}
- PublicInbox::Import::append_mid($hdr, $$mid0);
- $num;
+ PublicInbox::Import::append_mid($hdr, $mid0);
+ ($num, $mid0);
}
sub idx_shard {
# Now that all subprocesses are up, we can open the FDs
# for SQLite:
my $mm = $self->{mm} = PublicInbox::Msgmap->new_file(
- "$self->{-inbox}->{mainrepo}/msgmap.sqlite3", 1);
+ "$self->{-inbox}->{inboxdir}/msgmap.sqlite3", 1);
$mm->{dbh}->begin_work;
});
}
sub _replace_oids ($$$) {
my ($self, $mime, $replace_map) = @_;
$self->done;
- my $pfx = "$self->{-inbox}->{mainrepo}/git";
+ my $pfx = "$self->{-inbox}->{inboxdir}/git";
my $rewrites = []; # epoch => commit
my $max = $self->{epoch_max};
sub fill_alternates ($$) {
my ($self, $epoch) = @_;
- my $pfx = "$self->{-inbox}->{mainrepo}/git";
- my $all = "$self->{-inbox}->{mainrepo}/all.git";
- my @cmd;
+ my $pfx = "$self->{-inbox}->{inboxdir}/git";
+ my $all = "$self->{-inbox}->{inboxdir}/all.git";
+
unless (-d $all) {
PublicInbox::Import::init_bare($all);
}
- @cmd = (qw/git config/, "--file=$pfx/$epoch.git/config",
- 'include.path', '../../all.git/config');
- PublicInbox::Import::run_die(\@cmd);
-
my $alt = "$all/objects/info/alternates";
my %alts;
my @add;
sub git_init {
my ($self, $epoch) = @_;
- my $git_dir = "$self->{-inbox}->{mainrepo}/git/$epoch.git";
+ my $git_dir = "$self->{-inbox}->{inboxdir}/git/$epoch.git";
my @cmd = (qw(git init --bare -q), $git_dir);
PublicInbox::Import::run_die(\@cmd);
+ @cmd = (qw/git config/, "--file=$git_dir/config",
+ 'include.path', '../../all.git/config');
+ PublicInbox::Import::run_die(\@cmd);
fill_alternates($self, $epoch);
$git_dir
}
sub git_dir_latest {
my ($self, $max) = @_;
$$max = -1;
- my $pfx = "$self->{-inbox}->{mainrepo}/git";
+ my $pfx = "$self->{-inbox}->{inboxdir}/git";
return unless -d $pfx;
my $latest;
opendir my $dh, $pfx or die "opendir $pfx: $!\n";
last_epoch_commit($self, $i, $cmt);
}
-sub git_dir_n ($$) { "$_[0]->{-inbox}->{mainrepo}/git/$_[1].git" }
+sub git_dir_n ($$) { "$_[0]->{-inbox}->{inboxdir}/git/$_[1].git" }
sub last_commits ($$) {
my ($self, $epoch_max) = @_;
join(',',sort keys %gone), "\n";
}
foreach my $num (keys %gone) {
- $self->{unindexed}->{$_}++;
+ $self->{unindexed}->{$num}++;
$self->{mm}->num_delete($num);
}
unindex_oid_remote($self, $oid, $mid);