]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiBlob.pm
lei blob: add remote external support
[public-inbox.git] / lib / PublicInbox / LeiBlob.pm
index 97747220a684cffdb520442669397d2ae64206ab..8e610efdaaf33c6099246b1a765b3a66f01a4543 100644 (file)
@@ -6,9 +6,8 @@ package PublicInbox::LeiBlob;
 use strict;
 use v5.10.1;
 use parent qw(PublicInbox::IPC);
-use PublicInbox::Spawn qw(spawn popen_rd);
+use PublicInbox::Spawn qw(spawn popen_rd which);
 use PublicInbox::DS;
-use PublicInbox::Eml;
 
 sub sol_done_wait { # dwaitpid callback
        my ($arg, $pid) = @_;
@@ -19,7 +18,7 @@ sub sol_done_wait { # dwaitpid callback
 
 sub sol_done { # EOF callback for main daemon
        my ($lei) = @_;
-       my $sol = delete $lei->{sol} or return;
+       my $sol = delete $lei->{sol} // return $lei->dclose; # already failed
        $sol->wq_wait_old(\&sol_done_wait, $lei);
 }
 
@@ -67,7 +66,10 @@ sub do_solve_blob { # via wq_do
        }
        open my $log, '+>', \(my $log_buf = '') or die "PerlIO::scalar: $!";
        $lei->{log_buf} = \$log_buf;
-       my $git = $lei->ale->git;
+       my $git = $lei->{ale}->git;
+       my @rmt = map {
+               PublicInbox::LeiRemote->new($lei, $_)
+       } $self->{lxs}->remotes;
        my $solver = bless {
                gits => [ map {
                                PublicInbox::Git->new($lei->rel2abs($_))
@@ -75,7 +77,7 @@ sub do_solve_blob { # via wq_do
                user_cb => \&solver_user_cb,
                uarg => $self,
                # -cur_di, -qsp, -msg => temporary fields for Qspawn callbacks
-               inboxes => [ $self->{lxs}->locals ],
+               inboxes => [ $self->{lxs}->locals, @rmt ],
        }, 'PublicInbox::SolverGit';
        $lei->{env}->{'psgi.errors'} = $lei->{2}; # ugh...
        local $PublicInbox::DS::in_loop = 0; # waitpid synchronously
@@ -85,24 +87,36 @@ sub do_solve_blob { # via wq_do
 sub lei_blob {
        my ($lei, $blob) = @_;
        $lei->start_pager if -t $lei->{1};
+       my $opt = $lei->{opt};
+       my $has_hints = grep(defined, @$opt{qw(oid-a path-a path-b)});
 
-       # first, see if it's a blob returned by "lei q" JSON output:
-       my $rdr = { 1 => $lei->{1} };
-       open $rdr->{2}, '>', '/dev/null' or die "open: $!";
-       my $cmd = [ 'git', '--git-dir='.$lei->ale->git->{git_dir},
-                       'cat-file', 'blob', $blob ];
-       waitpid(spawn($cmd, $lei->{env}, $rdr), 0);
-       return if $? == 0;
+       # first, see if it's a blob returned by "lei q" JSON output:k
+       if ($opt->{mail} // ($has_hints ? 0 : 1)) {
+               my $rdr = { 1 => $lei->{1} };
+               open $rdr->{2}, '>', '/dev/null' or die "open: $!";
+               my $cmd = [ 'git', '--git-dir='.$lei->ale->git->{git_dir},
+                               'cat-file', 'blob', $blob ];
+               waitpid(spawn($cmd, $lei->{env}, $rdr), 0);
+               return if $? == 0;
+       }
 
        # maybe it's a non-email (code) blob from a coderepo
-       my $git_dirs = $lei->{opt}->{'git-dir'} //= [];
-       if ($lei->{opt}->{'cwd'} //= 1) {
+       my $git_dirs = $opt->{'git-dir'} //= [];
+       if ($opt->{'cwd'} // 1) {
                my $cgd = get_git_dir('.');
                unshift(@$git_dirs, $cgd) if defined $cgd;
        }
+       return $lei->fail('no --git-dir to try') unless @$git_dirs;
        my $lxs = $lei->lxs_prepare or return;
+       if ($lxs->remotes) {
+               require PublicInbox::LeiRemote;
+               $lei->{curl} //= which('curl') or return
+                       $lei->fail('curl needed for', $lxs->remotes);
+               $lei->_lei_store(1)->write_prepare($lei);
+       }
        require PublicInbox::SolverGit;
        my $self = bless { lxs => $lxs, oid_b => $blob }, __PACKAGE__;
+       $lei->ale;
        my ($op_c, $ops) = $lei->workers_start($self, 'lei_solve', 1,
                { '' => [ \&sol_done, $lei ] });
        $lei->{sol} = $self;