]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiRediff.pm
lei rediff: quiet warnings from Import and Eml
[public-inbox.git] / lib / PublicInbox / LeiRediff.pm
index 6c734bef50efb01e4a8fc15089e781e1499266b4..f6960560f1a24c850863c7869d27b641a5ac00fd 100644 (file)
@@ -16,12 +16,14 @@ use PublicInbox::Import;
 use PublicInbox::LEI;
 use PublicInbox::SolverGit;
 
+my $MODE = '(100644|120000|100755|160000)';
+
 sub rediff_user_cb { # called by solver when done
        my ($res, $self) = @_;
        my $lei = $self->{lei};
        my $log_buf = delete $lei->{log_buf};
        $$log_buf =~ s/^/# /sgm;
-       ref($res) eq 'ARRAY' or return $lei->child_error(1 << 8, $$log_buf);
+       ref($res) eq 'ARRAY' or return $lei->child_error(0, $$log_buf);
        $lei->qerr($$log_buf);
        my ($git, $oid, $type, $size, $di) = @$res;
        my $oid_want = delete $self->{cur_oid_want};
@@ -68,8 +70,7 @@ EOM
        my $tb = $ta;
        $tb =~ tr!A!B!;
        my $lei = $self->{lei};
-       my $wait = delete($self->{-do_done}) ? $lei->{sto}->ipc_do('done') : 0;
-       while (my ($oid_a, $oid_b, $pa, $pb) = splice(@$ctxq, 0, 4)) {
+       while (my ($oid_a, $oid_b, $pa, $pb, $ma, $mb) = splice(@$ctxq, 0, 6)) {
                my $xa = $blob->{$oid_a} //= solve_1($self, $oid_a,
                                                        { path_b => $pa });
                my $xb = $blob->{$oid_b} //= solve_1($self, $oid_b, {
@@ -77,8 +78,8 @@ EOM
                                                path_a => $pa,
                                                path_b => $pb
                                        });
-               $ta .= "M 100644 $xa ".git_quote($pa)."\n" if $xa;
-               $tb .= "M 100644 $xb ".git_quote($pb)."\n" if $xb;
+               $ta .= "M $ma $xa ".git_quote($pa)."\n" if $xa;
+               $tb .= "M $mb $xb ".git_quote($pb)."\n" if $xb;
        }
        my $rw = $self->{gits}->[-1]; # has all known alternates
        if (!$rw->{-tmp}) {
@@ -107,8 +108,9 @@ EOM
        push @cmd, '--'.($opt->{color} && !$opt->{'no-color'} ? '' : 'no-').
                        'color';
        for my $o (@PublicInbox::LEI::diff_opt) {
-               $o =~ s/\|([a-z0-9])\b//i; # remove single char short option
-               my $c = $1;
+               my $c = '';
+               # remove single char short option
+               $o =~ s/\|([a-z0-9])\b//i and $c = $1;
                if ($o =~ s/=[is]@\z//) {
                        my $v = $opt->{$o} or next;
                        push @cmd, map { $c ? "-$c$_" : "--$o=$_" } @$v;
@@ -148,6 +150,15 @@ sub extract_oids { # Eml each_part callback
                if (scalar(@top) >= 4 &&
                                $top[1] =~ $PublicInbox::ViewDiff::IS_OID &&
                                $top[0] =~ $PublicInbox::ViewDiff::IS_OID) {
+                       my ($ma, $mb);
+                       $x =~ /^old mode $MODE/sm and $ma = $1;
+                       $x =~ /^new mode $MODE/sm and $mb = $1;
+                       if (!defined($ma) && $x =~
+                               /^index [a-z0-9]+\.\.[a-z0-9]+ $MODE/sm) {
+                               $ma = $mb = $1;
+                       }
+                       $ma //= '100644';
+                       $mb //= $ma;
                        my ($oid_a, $oid_b, $pa, $pb) = splice(@top, 0, 4);
                        $pa eq '/dev/null' or
                                $pa = (split(m'/', git_unquote($pa), 2))[1];
@@ -155,7 +166,7 @@ sub extract_oids { # Eml each_part callback
                                $pb = (split(m'/', git_unquote($pb), 2))[1];
                        $blobs->{$oid_a} //= undef;
                        $blobs->{$oid_b} //= undef;
-                       push @$ctxq, $oid_a, $oid_b, $pa, $pb;
+                       push @$ctxq, $oid_a, $oid_b, $pa, $pb, $ma, $mb;
                } elsif ($ctxq) {
                        my @out;
                        for (split(/^/sm, $x)) {
@@ -182,15 +193,21 @@ sub extract_oids { # Eml each_part callback
 
 sub input_eml_cb { # callback for all emails
        my ($self, $eml) = @_;
-       $self->{lei}->{sto}->ipc_do('add_eml', $eml);
-       $self->{-do_done} = 1;
+       {
+               local $SIG{__WARN__} = sub {
+                       return if "@_" =~ /^no email in From: .*? or Sender:/;
+                       return if PublicInbox::Eml::warn_ignore(@_);
+                       warn @_;
+               };
+               $self->{tmp_sto}->add_eml($eml);
+               $self->{tmp_sto}->done;
+       }
        $eml->each_part(\&extract_oids, $self, 1);
 }
 
 sub lei_rediff {
        my ($lei, @inputs) = @_;
        $lei->_lei_store(1)->write_prepare($lei);
-       $lei->{opt}->{stdin} = 1 if !@inputs;
        $lei->{opt}->{'in-format'} //= 'eml';
        # maybe it's a non-email (code) blob from a coderepo
        my $git_dirs = $lei->{opt}->{'git-dir'} //= [];
@@ -205,7 +222,7 @@ sub lei_rediff {
                $lei->{curl} //= which('curl') or return
                        $lei->fail('curl needed for', $lxs->remotes);
        }
-       $lei->ale->refresh_externals($lxs);
+       $lei->ale->refresh_externals($lxs, $lei);
        my $self = bless {
                -force_eml => 1, # for LeiInput->input_fh
                lxs => $lxs,
@@ -217,7 +234,7 @@ sub lei_rediff {
        my ($op_c, $ops) = $lei->workers_start($self, 1);
        $lei->{wq1} = $self;
        net_merge_all_done($self) unless $lei->{auth};
-       $op_c->op_wait_event($ops);
+       $lei->wait_wq_events($op_c, $ops);
 }
 
 sub ipc_atfork_child {
@@ -228,7 +245,11 @@ sub ipc_atfork_child {
        binmode $lei->{1}, ':utf8';
        $self->{blobs} = {}; # oidhex => filename
        $self->{rdtmp} = File::Temp->newdir('lei-rediff-XXXX', TMPDIR => 1);
-       $self->{rmt} = [ map {
+       $self->{tmp_sto} = PublicInbox::LeiStore->new(
+                       "$self->{rdtmp}/tmp.store",
+                       { creat => { nproc => 1 }, indexlevel => 'medium' });
+       $self->{tmp_sto}->{priv_eidx}->{parallel} = 0;
+       $self->{rmt} = [ $self->{tmp_sto}->search, map {
                        PublicInbox::LeiRemote->new($lei, $_)
                } $self->{lxs}->remotes ];
        $self->{gits} = [ map {
@@ -241,5 +262,4 @@ sub ipc_atfork_child {
 
 no warnings 'once';
 *net_merge_all_done = \&PublicInbox::LeiInput::input_only_net_merge_all_done;
-*net_merge_all = \&PublicInbox::LeiAuth::net_merge_all;
 1;