X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FImport.pm;h=e3d65f4aa73b8eb28fa3e9024361c057e2284b9c;hb=23a4e44bedabe5b8b651346cabc2a870c5377a30;hp=1db2a0b858701051f0c03e2e01b19e05b1518da5;hpb=8dfd3da2cb7967fcb52dcd816a6e52d143684061;p=public-inbox.git diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm index 1db2a0b8..e3d65f4a 100644 --- a/lib/PublicInbox/Import.pm +++ b/lib/PublicInbox/Import.pm @@ -8,7 +8,6 @@ package PublicInbox::Import; use strict; use warnings; use Fcntl qw(:flock :DEFAULT); -use Email::Address; use PublicInbox::Spawn qw(spawn); use PublicInbox::MID qw(mid_mime mid2path); @@ -51,6 +50,7 @@ sub gfi_start { $self->{out} = $out_w; $self->{lockfh} = $lockfh; $self->{pid} = $pid; + $self->{nchg} = 0; ($in_r, $out_w); } @@ -131,6 +131,7 @@ sub remove { "data 3\nrm\n\n", 'from ', ($parent ? $parent : $tip), "\n" or wfail; print $w "D $path\n\n" or wfail; + $self->{nchg}++; (($self->{tip} = ":$commit"), $cur); } @@ -139,21 +140,21 @@ sub add { my ($self, $mime) = @_; # mime = Email::MIME my $from = $mime->header('From'); - my @from = Email::Address->parse($from); - my $name = $from[0]->name; - my $email = $from[0]->address; - my $date = $mime->header('Date'); - my $subject = $mime->header('Subject'); - $subject = '(no subject)' unless defined $subject; - my $mid = mid_mime($mime); - my $path = mid2path($mid); - + my ($email) = ($from =~ /([^<\s]+\@[^>\s]+)/g); + my $name = $from; + $name =~ s/\s*\S+\@\S+\s*\z//; # git gets confused with: # "'A U Thor ' via foo" # ref: # $name =~ tr/<>// and $name = $email; + my $date = $mime->header('Date'); + my $subject = $mime->header('Subject'); + $subject = '(no subject)' unless defined $subject; + my $mid = mid_mime($mime); + my $path = mid2path($mid); + my ($r, $w) = $self->gfi_start; my $tip = $self->{tip}; if ($tip ne '') { @@ -191,6 +192,7 @@ sub add { print $w 'from ', ($parent ? $parent : $tip), "\n" or wfail; } print $w "M 100644 :$blob $path\n\n" or wfail; + $self->{nchg}++; $self->{tip} = ":$commit"; } @@ -202,14 +204,15 @@ sub done { my $pid = delete $self->{pid} or die 'BUG: missing {pid} when done'; waitpid($pid, 0) == $pid or die 'fast-import did not finish'; $? == 0 or die "fast-import failed: $?"; + my $nchg = delete $self->{nchg}; # for compatibility with existing ssoma installations # we can probably remove this entirely by 2020 my $git_dir = $self->{git}->{git_dir}; - my $index = "$git_dir/ssoma.index"; # XXX: change the following scope to: if (-e $index) # in 2018 or so.. my @cmd = ('git', "--git-dir=$git_dir"); - unless ($ENV{FAST}) { + if ($nchg && !$ENV{FAST}) { + my $index = "$git_dir/ssoma.index"; my $env = { GIT_INDEX_FILE => $index }; my @rt = (@cmd, qw(read-tree -m -v -i), $self->{ref}); $pid = spawn(\@rt, $env, undef); @@ -217,11 +220,13 @@ sub done { waitpid($pid, 0) == $pid or die 'read-tree did not finish'; $? == 0 or die "failed to update $git_dir/ssoma.index: $?\n"; } - - $pid = spawn([@cmd, 'update-server-info'], undef, undef); - defined $pid or die "spawn update-server-info failed: $!\n"; - waitpid($pid, 0) == $pid or die 'update-server-info did not finish'; - $? == 0 or die "failed to update-server-info: $?\n"; + if ($nchg) { + $pid = spawn([@cmd, 'update-server-info'], undef, undef); + defined $pid or die "spawn update-server-info failed: $!\n"; + waitpid($pid, 0) == $pid or + die 'update-server-info did not finish'; + $? == 0 or die "failed to update-server-info: $?\n"; + } my $lockfh = delete $self->{lockfh} or die "BUG: not locked: $!"; flock($lockfh, LOCK_UN) or die "unlock failed: $!";