]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Import.pm
import: extract_author_info becomes extract_commit_info
[public-inbox.git] / lib / PublicInbox / Import.pm
index 12abf39995ffbcd1677f94be807828449e06c96c..6ee1935e6f8bbd1900500698674ee9b8fdcf37be 100644 (file)
@@ -106,7 +106,7 @@ sub _cat_blob ($$$) {
        local $/ = "\n";
        my $info = <$r>;
        defined $info or die "EOF from fast-import / cat-blob: $!";
-       $info =~ /\A[a-f0-9]{40} blob (\d+)\n\z/ or return;
+       $info =~ /\A[a-f0-9]{40} blob ([0-9]+)\n\z/ or return;
        my $left = $1;
        my $offset = 0;
        my $buf = '';
@@ -277,7 +277,7 @@ sub git_timestamp {
        "$ts $zone";
 }
 
-sub extract_author_info ($) {
+sub extract_cmt_info ($) {
        my ($mime) = @_;
 
        my $sender = '';
@@ -314,7 +314,17 @@ sub extract_author_info ($) {
                $name = '';
                warn "no name in From: $from or Sender: $sender\n";
        }
-       ($name, $email);
+
+       my $hdr = $mime->header_obj;
+
+       my $subject = $hdr->header('Subject');
+       $subject = '(no subject)' unless defined $subject;
+       # Mime decoding can create nulls replace them with spaces to protect git
+       $subject =~ tr/\0/ /;
+       utf8::encode($subject);
+       my $at = git_timestamp(my @at = msg_datestamp($hdr));
+       my $ct = git_timestamp(my @ct = msg_timestamp($hdr));
+       ($name, $email, $at, $ct, $subject);
 }
 
 # kill potentially confusing/misleading headers
@@ -361,16 +371,8 @@ sub clean_tree_v2 ($$$) {
 sub add {
        my ($self, $mime, $check_cb) = @_; # mime = Email::MIME
 
-       my ($name, $email) = extract_author_info($mime);
-       my $hdr = $mime->header_obj;
-       my @at = msg_datestamp($hdr);
-       my @ct = msg_timestamp($hdr);
-       my $author_time_raw = git_timestamp(@at);
-       my $commit_time_raw = git_timestamp(@ct);
-       my $subject = $mime->header('Subject');
-       $subject = '(no subject)' unless defined $subject;
+       my ($name, $email, $at, $ct, $subject) = extract_cmt_info($mime);
        my $path_type = $self->{path_type};
-
        my $path;
        if ($path_type eq '2/38') {
                $path = mid2path(v1_mid0($mime));
@@ -411,12 +413,9 @@ 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",
-               "committer $self->{ident} $commit_time_raw\n" or wfail;
+               "author $name <$email> $at\n",
+               "committer $self->{ident} $ct\n" or wfail;
        print $w "data ", (length($subject) + 1), "\n",
                $subject, "\n\n" or wfail;
        if ($tip ne '') {
@@ -492,9 +491,9 @@ sub clean_purge_buffer {
 
        foreach my $i (0..$#$buf) {
                my $l = $buf->[$i];
-               if ($l =~ /^author .* (\d+ [\+-]?\d+)$/) {
+               if ($l =~ /^author .* ([0-9]+ [\+-]?[0-9]+)$/) {
                        $buf->[$i] = "author <> $1\n";
-               } elsif ($l =~ /^data (\d+)/) {
+               } elsif ($l =~ /^data ([0-9]+)/) {
                        $buf->[$i++] = "data " . length($cmt_msg) . "\n";
                        $buf->[$i] = $cmt_msg;
                        last;
@@ -524,7 +523,7 @@ sub purge_oids {
                                @buf = ();
                        }
                        push @buf, "commit $tmp\n";
-               } elsif (/^data (\d+)/) {
+               } elsif (/^data ([0-9]+)/) {
                        # only commit message, so $len is small:
                        my $len = $1; # + 1 for trailing "\n"
                        push @buf, $_;
@@ -556,7 +555,7 @@ sub purge_oids {
                        @buf = ();
                } elsif ($_ eq "done\n") {
                        $done = 1;
-               } elsif (/^mark :(\d+)$/) {
+               } elsif (/^mark :([0-9]+)$/) {
                        push @buf, $_;
                        $mark = $1;
                } else {