]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Import.pm
Import.pm: When purging replace a purged file with a zero length file
[public-inbox.git] / lib / PublicInbox / Import.pm
index b25427ee552628237bc094225f2daf24e98dcdac..3df7d98f298bd64a0ba84dbb8228ca27ae1617d3 100644 (file)
@@ -278,10 +278,12 @@ sub extract_author_info ($) {
 
        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);
                }
@@ -405,6 +407,8 @@ sub add {
                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",
@@ -440,11 +444,14 @@ sub done {
        _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";
        }
 }
@@ -512,11 +519,12 @@ sub purge_oids {
                        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+)/) {