]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Import.pm
remove most internal Email::MIME usage
[public-inbox.git] / lib / PublicInbox / Import.pm
index 351bc660e19b862424e474de545beba50d26719b..07d1859920003ea820c8ccd70cb536acee9e2f74 100644 (file)
@@ -15,6 +15,7 @@ use PublicInbox::Address;
 use PublicInbox::MsgTime qw(msg_timestamp msg_datestamp);
 use PublicInbox::ContentId qw(content_digest);
 use PublicInbox::MDA;
+use PublicInbox::Eml;
 use POSIX qw(strftime);
 
 sub new {
@@ -137,7 +138,7 @@ sub check_remove_v1 {
        $info =~ m!\A100644 blob ([a-f0-9]{40})\t!s or die "not blob: $info";
        my $oid = $1;
        my $msg = _cat_blob($r, $w, $oid) or die "BUG: cat-blob $1 failed";
-       my $cur = PublicInbox::MIME->new($msg);
+       my $cur = PublicInbox::Eml->new($msg);
        my $cur_s = $cur->header('Subject');
        $cur_s = '' unless defined $cur_s;
        my $cur_m = $mime->header('Subject');
@@ -212,13 +213,13 @@ sub get_mark {
 }
 
 # returns undef on non-existent
-# ('MISMATCH', Email::MIME) on mismatch
-# (:MARK, Email::MIME) on success
+# ('MISMATCH', PublicInbox::Eml) on mismatch
+# (:MARK, PublicInbox::Eml) on success
 #
 # v2 callers should check with Xapian before calling this as
 # it is not idempotent.
 sub remove {
-       my ($self, $mime, $msg) = @_; # mime = Email::MIME
+       my ($self, $mime, $msg) = @_; # mime = PublicInbox::Eml or Email::MIME
 
        my $path_type = $self->{path_type};
        my ($path, $err, $cur, $blob);
@@ -354,7 +355,7 @@ sub v1_mid0 ($) {
        my $hdr = $mime->header_obj;
        my $mids = mids($hdr);
 
-       if (!scalar(@$mids)) { # spam often has no Message-Id
+       if (!scalar(@$mids)) { # spam often has no Message-ID
                my $mid0 = digest2mid(content_digest($mime), $hdr);
                append_mid($hdr, $mid0);
                return $mid0;
@@ -374,7 +375,7 @@ sub clean_tree_v2 ($$$) {
 # returns undef on duplicate
 # returns the :MARK of the most recent commit
 sub add {
-       my ($self, $mime, $check_cb, $smsg) = @_; # mime = Email::MIME
+       my ($self, $mime, $check_cb, $smsg) = @_;
 
        my ($name, $email, $at, $ct, $subject) = extract_cmt_info($mime, $smsg);
        my $path_type = $self->{path_type};
@@ -440,15 +441,31 @@ sub run_die ($;$$) {
        $? == 0 or die join(' ', @$cmd) . " failed: $?\n";
 }
 
+my @INIT_FILES = ('HEAD' => "ref: refs/heads/master\n",
+               'description' => <<EOD,
+Unnamed repository; edit this file 'description' to name the repository.
+EOD
+               'config' => <<EOC);
+[core]
+       repositoryFormatVersion = 0
+       filemode = true
+       bare = true
+[repack]
+       writeBitmaps = true
+EOC
+
 sub init_bare {
        my ($dir) = @_; # or self
        $dir = $dir->{git}->{git_dir} if ref($dir);
-       my @cmd = (qw(git init --bare -q), $dir);
-       run_die(\@cmd);
-       # set a reasonable default:
-       @cmd = (qw/git config/, "--file=$dir/config",
-               'repack.writeBitmaps', 'true');
-       run_die(\@cmd);
+       require File::Path;
+       File::Path::mkpath([ map { "$dir/$_" } qw(objects/info refs/heads) ]);
+       for (my $i = 0; $i < @INIT_FILES; $i++) {
+               my $f = $dir.'/'.$INIT_FILES[$i++];
+               next if -f $f;
+               open my $fh, '>', $f or die "open $f: $!";
+               print $fh $INIT_FILES[$i] or die "print $f: $!";
+               close $fh or die "close $f: $!";
+       }
 }
 
 sub done {