use PublicInbox::Spawn qw(spawn popen_rd);
use PublicInbox::MID qw(mids mid2path);
use PublicInbox::Address;
-use PublicInbox::MsgTime qw(msg_timestamp msg_datestamp);
+use PublicInbox::Smsg;
+use PublicInbox::MsgTime qw(msg_datestamp);
use PublicInbox::ContentHash qw(content_digest);
use PublicInbox::MDA;
use PublicInbox::Eml;
(($self->{tip} = ":$commit"), $cur);
}
-sub git_timestamp {
- my ($ts, $zone) = @_;
+sub git_timestamp ($) {
+ my ($ts, $zone) = @{$_[0]};
$ts = 0 if $ts < 0; # git uses unsigned times
"$ts $zone";
}
sub extract_cmt_info ($;$) {
my ($mime, $smsg) = @_;
# $mime is PublicInbox::Eml, but remains Email::MIME-compatible
+ $smsg //= bless {}, 'PublicInbox::Smsg';
- my $sender = '';
my $hdr = $mime->header_obj;
- my $from = $hdr->header('From') // '';
+ $smsg->populate($hdr);
+
+ my $sender = '';
+ my $from = delete($smsg->{From}) // '';
my ($email) = PublicInbox::Address::emails($from);
my ($name) = PublicInbox::Address::names($from);
if (!defined($name) || !defined($email)) {
warn "no name in From: $from or Sender: $sender\n";
}
- my $subject = $hdr->header('Subject') // '(no subject)';
- # MIME decoding can create nulls replace them with spaces to protect git
- $subject =~ tr/\0/ /;
+ my $subject = delete($smsg->{Subject}) // '(no subject)';
utf8::encode($subject);
- my $at = git_timestamp(my @at = msg_datestamp($hdr));
- my $ct = git_timestamp(my @ct = msg_timestamp($hdr));
- if ($smsg) {
- $smsg->{ds} = $at[0];
- $smsg->{ts} = $ct[0];
- }
- ($name, $email, $at, $ct, $subject);
+ my $at = git_timestamp(delete $smsg->{-ds});
+ my $ct = git_timestamp(delete $smsg->{-ts});
+ ("$name <$email>", $at, $ct, $subject);
}
# kill potentially confusing/misleading headers
sub add {
my ($self, $mime, $check_cb, $smsg) = @_;
- my ($name, $email, $at, $ct, $subject) = extract_cmt_info($mime, $smsg);
+ my ($author, $at, $ct, $subject) = extract_cmt_info($mime, $smsg);
my $path_type = $self->{path_type};
my $path;
if ($path_type eq '2/38') {
# v2: we need this for Xapian
if ($smsg) {
$smsg->{blob} = $self->get_mark(":$blob");
- $smsg->{bytes} = $n;
+ $smsg->{raw_bytes} = $n;
$smsg->{-raw_email} = \$raw_email;
}
my $ref = $self->{ref};
}
print $w "commit $ref\nmark :$commit\n",
- "author $name <$email> $at\n",
+ "author $author $at\n",
"committer $self->{ident} $ct\n" or wfail;
print $w "data ", (length($subject) + 1), "\n",
$subject, "\n\n" or wfail;
waitpid($pid, 0) == $pid or die 'fast-import did not finish';
$? == 0 or die "fast-import failed: $?";
- _update_git_info($self, 1) if delete $self->{nchg};
-
- $self->lock_release;
+ my $nchg = delete $self->{nchg};
+ _update_git_info($self, 1) if $nchg;
+ $self->lock_release(!!$nchg);
$self->{git}->cleanup;
}
sub rewrite_commit ($$$$) {
my ($self, $oids, $buf, $mime) = @_;
- my ($name, $email, $at, $ct, $subject);
+ my ($author, $at, $ct, $subject);
if ($mime) {
- ($name, $email, $at, $ct, $subject) = extract_cmt_info($mime);
+ ($author, $at, $ct, $subject) = extract_cmt_info($mime);
} else {
- $name = $email = '';
+ $author = '<>';
$subject = 'purged '.join(' ', @$oids);
}
@$oids = ();
my $l = $buf->[$i];
if ($l =~ /^author .* ([0-9]+ [\+-]?[0-9]+)$/) {
$at //= $1;
- $buf->[$i] = "author $name <$email> $at\n";
+ $buf->[$i] = "author $author $at\n";
} elsif ($l =~ /^committer .* ([0-9]+ [\+-]?[0-9]+)$/) {
$ct //= $1;
$buf->[$i] = "committer $self->{ident} $ct\n";