}
sub extract_cmt_info ($;$) {
- my ($mime, $v2w) = @_;
+ my ($mime, $smsg) = @_;
my $sender = '';
my $from = $mime->header('From');
utf8::encode($subject);
my $at = git_timestamp(my @at = msg_datestamp($hdr));
my $ct = git_timestamp(my @ct = msg_timestamp($hdr));
- if ($v2w) { # set fallbacks in case message had no date
- $v2w->{autime} = $at[0];
- $v2w->{cotime} = $ct[0];
+ if ($smsg) {
+ $smsg->{ds} = $at[0];
+ $smsg->{ts} = $ct[0];
}
($name, $email, $at, $ct, $subject);
}
# returns undef on duplicate
# returns the :MARK of the most recent commit
sub add {
- my ($self, $mime, $check_cb, $v2w) = @_; # mime = Email::MIME
+ my ($self, $mime, $check_cb, $smsg) = @_; # mime = Email::MIME
- my ($name, $email, $at, $ct, $subject) = extract_cmt_info($mime, $v2w);
+ my ($name, $email, $at, $ct, $subject) = extract_cmt_info($mime, $smsg);
my $path_type = $self->{path_type};
my $path;
if ($path_type eq '2/38') {
print $w $raw_email, "\n" or wfail;
# v2: we need this for Xapian
- if ($self->{want_object_info}) {
- my $oid = $self->get_mark(":$blob");
- $self->{last_object} = [ $oid, $n, \$raw_email ];
+ if ($smsg) {
+ $smsg->{blob} = $self->get_mark(":$blob");
+ $smsg->{bytes} = $n;
+ $smsg->{-raw_email} = \$raw_email;
}
my $ref = $self->{ref};
my $commit = $self->{mark}++;
use DBI qw(:sql_types); # SQL_BLOB
use PublicInbox::MID qw/id_compress mids_for_index references/;
use PublicInbox::Smsg qw(subject_normalized);
-use PublicInbox::MsgTime qw(msg_timestamp msg_datestamp);
use Compress::Zlib qw(compress);
use PublicInbox::Search;
}
sub add_overview {
- my ($self, $mime, $smsg, $times) = @_;
+ my ($self, $mime, $smsg) = @_;
$smsg->{lines} = $mime->body_raw =~ tr!\n!\n!;
$smsg->{mime} = $mime; # XXX temporary?
my $hdr = $mime->header_obj;
my $dd = $smsg->to_doc_data;
utf8::encode($dd);
$dd = compress($dd);
- my $ds = msg_timestamp($hdr, $times->{autime});
- my $ts = msg_datestamp($hdr, $times->{cotime});
- my $values = [ $ts, $ds, $smsg->{num}, $mids, $refs, $xpath, $dd ];
- add_over($self, $values);
+ add_over($self, [ @$smsg{qw(ts ds num)}, $mids, $refs, $xpath, $dd ]);
}
sub add_over {
my ($self, $mime, $smsg, $mids) = @_;
$smsg->{mime} = $mime; # XXX dangerous
my $hdr = $mime->header_obj;
- $smsg->{ds} = msg_datestamp($hdr, $self->{autime});
- $smsg->{ts} = msg_timestamp($hdr, $self->{cotime});
my $doc = $X->{Document}->new;
my $subj = $smsg->subject;
add_val($doc, PublicInbox::Search::TS(), $smsg->{ts});
sub add_message {
# mime = Email::MIME object
my ($self, $mime, $smsg) = @_;
- my $mids = mids_for_index($mime->header_obj);
+ my $hdr = $mime->header_obj;
+ my $mids = mids_for_index($hdr);
$smsg //= bless { blob => '' }, 'PublicInbox::Smsg'; # test-only compat
$smsg->{mid} //= $mids->[0]; # v1 compatibility
$smsg->{num} //= do { # v1
_msgmap_init($self);
index_mm($self, $mime);
};
+
+ # v1 and tests only:
+ $smsg->{ds} //= msg_datestamp($hdr, $self->{autime});
+ $smsg->{ts} //= msg_timestamp($hdr, $self->{cotime});
+
eval {
# order matters, overview stores every possible piece of
# data in doc_data (deflated). Xapian only stores a subset
# storing doc_data in Xapian sometime after we get multi-inbox
# search working.
if (my $over = $self->{over}) { # v1 only
- $over->add_overview($mime, $smsg, $self);
+ $over->add_overview($mime, $smsg);
}
if (need_xapian($self)) {
add_xapian($self, $mime, $smsg, $mids);
$latest = $1;
$newest ||= $latest;
} elsif ($line =~ /^author .*? ([0-9]+) [\-\+][0-9]+$/) {
- $self->{over}->{autime} = $self->{autime} = $1;
+ $self->{autime} = $1;
} elsif ($line =~ /^committer .*? ([0-9]+) [\-\+][0-9]+$/) {
- $self->{over}->{cotime} = $self->{cotime} = $1;
+ $self->{cotime} = $1;
}
}
close($log) or die "git log failed: \$?=$?";
$self->remove_by_oid($oid, $mid);
} else {
chomp $line;
- my ($bytes, $num, $blob, $mid, $autime, $cotime) =
+ my ($bytes, $num, $blob, $mid, $ds, $ts) =
split(/ /, $line);
$self->begin_txn_lazy;
my $n = read($r, my $msg, $bytes) or die "read: $!\n";
$n == $bytes or die "short read: $n != $bytes\n";
my $mime = PublicInbox::MIME->new(\$msg);
- $self->{autime} = $autime;
- $self->{cotime} = $cotime;
my $smsg = bless {
bytes => $bytes,
num => $num + 0,
blob => $blob,
mid => $mid,
+ ds => $ds,
+ ts => $ts,
}, 'PublicInbox::Smsg';
$self->add_message($mime, $smsg);
}
# called by V2Writable
sub index_raw {
- my ($self, $msgref, $mime, $smsg, $times) = @_;
- my $at = $times->{autime} // time;
- my $ct = $times->{cotime} // time;
+ my ($self, $msgref, $mime, $smsg) = @_;
if (my $w = $self->{w}) {
- print $w join(' ', @$smsg{qw(bytes num blob mid)}, $at, $ct),
+ print $w join(' ', @$smsg{qw(bytes num blob mid ds ts)}),
"\n", $$msgref or die "failed to write shard $!\n";
} else {
$$msgref = undef;
$self->begin_txn_lazy;
- $self->{autime} = $at;
- $self->{cotime} = $ct;
$self->add_message($mime, $smsg);
}
}
use PublicInbox::Msgmap;
use PublicInbox::Spawn qw(spawn popen_rd);
use PublicInbox::SearchIdx;
+use PublicInbox::MsgTime qw(msg_timestamp msg_datestamp);
use IO::Handle; # ->autoflush
use File::Temp qw(tempfile);
# indexes a message, returns true if checkpointing is needed
sub do_idx ($$$$) {
my ($self, $msgref, $mime, $smsg) = @_;
- $self->{over}->add_overview($mime, $smsg, $self);
+ $smsg->{ds} //= msg_datestamp($mime->header_obj, $self->{autime});
+ $smsg->{ts} //= msg_timestamp($mime->header_obj, $self->{cotime});
+ $self->{over}->add_overview($mime, $smsg);
my $idx = idx_shard($self, $smsg->{num} % $self->{shards});
- $idx->index_raw($msgref, $mime, $smsg, $self);
+ $idx->index_raw($msgref, $mime, $smsg);
my $n = $self->{transact_bytes} += $smsg->{bytes};
$n >= (PublicInbox::SearchIdx::BATCH_BYTES * $self->{shards});
}
defined $num or return; # duplicate
defined $mid0 or die "BUG: $mid0 undefined\n";
my $im = $self->importer;
- my $cmt = $im->add($mime, undef, $self); # sets $self->{(au|co)time}
+ my $smsg = bless { mid => $mid0, num => $num }, 'PublicInbox::Smsg';
+ my $cmt = $im->add($mime, undef, $smsg); # sets $smsg->{ds|ts|blob}
$cmt = $im->get_mark($cmt);
$self->{last_commit}->[$self->{epoch_max}] = $cmt;
- my $msgref;
- my $smsg = bless { mid => $mid0, num => $num }, 'PublicInbox::Smsg';
- ($smsg->{blob}, $smsg->{bytes}, $msgref) = @{$im->{last_object}};
+ my $msgref = delete $smsg->{-raw_email};
if (do_idx($self, $msgref, $mime, $smsg)) {
$self->checkpoint;
}
my ($self, $git, $packed_bytes, $tmp) = @_;
my $im = PublicInbox::Import->new($git, undef, undef, $self->{-inbox});
$im->{bytes_added} = int($packed_bytes / $PACKING_FACTOR);
- $im->{want_object_info} = 1;
$im->{lock_path} = undef;
$im->{path_type} = 'v2';
$self->{im} = $im unless $tmp;
body => "hello world\n",
);
my $v2 = require_git(2.6, 1);
-
-$im->{want_object_info} = 1 if $v2;
-like($im->add($mime), qr/\A:\d+\z/, 'added one message');
+my $smsg = {} if $v2;
+like($im->add($mime, undef, $smsg), qr/\A:[0-9]+\z/, 'added one message');
if ($v2) {
- my $info = $im->{last_object};
- like($info->[0], qr/\A[a-f0-9]{40}\z/, 'got last object_id');
- is($mime->as_string, ${$info->[2]}, 'string matches');
- is($info->[1], length(${$info->[2]}), 'length matches');
+ like($smsg->{blob}, qr/\A[a-f0-9]{40}\z/, 'got last object_id');
+ is($mime->as_string, ${$smsg->{-raw_email}}, 'string matches');
+ is($smsg->{bytes}, length(${$smsg->{-raw_email}}), 'length matches');
my @cmd = ('git', "--git-dir=$git->{git_dir}", qw(hash-object --stdin));
my $in = tempfile();
print $in $mime->as_string or die "write failed: $!";
is($?, 0, 'hash-object');
seek($out, 0, SEEK_SET);
chomp(my $hashed_obj = <$out>);
- is($hashed_obj, $info->[0], "last object_id matches exp");
+ is($hashed_obj, $smsg->{blob}, "blob object_id matches exp");
}
$im->done;