-# Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
#
# git fast-import-based ssoma-mda MDA replacement
-# This is only ever run by public-inbox-mda and public-inbox-learn,
-# not the WWW or NNTP code which only requires read-only access.
+# This is only ever run by public-inbox-mda, public-inbox-learn
+# and public-inbox-watch. Not the WWW or NNTP code which only
+# requires read-only access.
package PublicInbox::Import;
use strict;
use warnings;
my $sender = '';
my $from = $mime->header('From');
+ $from ||= '';
my ($email) = PublicInbox::Address::emails($from);
my ($name) = PublicInbox::Address::names($from);
if (!defined($name) || !defined($email)) {
$sender = $mime->header('Sender');
+ $sender ||= '';
if (!defined($name)) {
($name) = PublicInbox::Address::names($sender);
}
print $w "reset $ref\n" or wfail;
}
+ # Mime decoding can create nulls replace them with spaces to protect git
+ $subject =~ tr/\0/ /;
utf8::encode($subject);
print $w "commit $ref\nmark :$commit\n",
"author $name <$email> $author_time_raw\n",
_update_git_info($self, 1) if delete $self->{nchg};
$self->lock_release;
+
+ $self->{git}->cleanup;
}
sub atfork_child {
my ($self) = @_;
foreach my $f (qw(in out)) {
+ next unless defined($self->{$f});
close $self->{$f} or die "failed to close import[$f]: $!\n";
}
}
push @buf, $buf;
} elsif (/^M 100644 ([a-f0-9]+) (\w+)/) {
my ($oid, $path) = ($1, $2);
+ $tree->{$path} = 1;
if ($purge->{$oid}) {
push @oids, $oid;
- delete $tree->{$path};
+ my $cmd = "M 100644 inline $path\ndata 0\n\n";
+ push @buf, $cmd;
} else {
- $tree->{$path} = 1;
push @buf, $_;
}
} elsif (/^D (\w+)/) {
=head1 DESCRIPTION
An importer and remover for public-inboxes which takes L<Email::MIME>
-messages as input and stores them in a ssoma repository as
-documented in L<https://ssoma.public-inbox.org/ssoma_repository.txt>,
+messages as input and stores them in a git repository as
+documented in L<https://public-inbox.org/public-inbox-v1-format.txt>,
except it does not allow duplicate Message-IDs.
It requires L<git(1)> and L<git-fast-import(1)> to be installed.