X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FLeiBlob.pm;h=1692289c5e27ac932fe54b1bda90ea2be04c38b2;hb=HEAD;hp=710430a2c1981e2170c607d83a4cb0c782c54996;hpb=528ef7a3988862763b6ca5b0123be0bf23a64213;p=public-inbox.git diff --git a/lib/PublicInbox/LeiBlob.pm b/lib/PublicInbox/LeiBlob.pm index 710430a2..1692289c 100644 --- a/lib/PublicInbox/LeiBlob.pm +++ b/lib/PublicInbox/LeiBlob.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2021 all contributors +# Copyright (C) all contributors # License: AGPL-3.0+ # "lei blob $OID" command @@ -32,7 +32,7 @@ sub solver_user_cb { # called by solver when done 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 $gd = $git->{git_dir}; @@ -40,7 +40,7 @@ sub solver_user_cb { # called by solver when done # don't try to support all the git-show(1) options for non-blob, # this is just a convenience: $type ne 'blob' and - $lei->err("# $oid is a $type of $size bytes in:\n#\t$gd"); + warn "# $oid is a $type of $size bytes in:\n#\t$gd\n"; my $cmd = [ 'git', "--git-dir=$gd", 'show', $oid ]; my $rdr = { 1 => $lei->{1}, 2 => $lei->{2} }; @@ -70,10 +70,9 @@ sub do_solve_blob { # via wq_do } @$git_dirs ], user_cb => \&solver_user_cb, uarg => $self, - # -cur_di, -qsp, -msg => temporary fields for Qspawn callbacks + # -cur_di, -msg => temporary fields for Qspawn callbacks inboxes => [ $self->{lxs}->locals, @rmt ], }, 'PublicInbox::SolverGit'; - $lei->{env}->{'psgi.errors'} = $lei->{2}; # ugh... local $PublicInbox::DS::in_loop = 0; # waitpid synchronously $solver->solve($lei->{env}, $log, $self->{oid_b}, $hints); } @@ -87,6 +86,16 @@ sub cat_attach_i { # Eml->each_part callback $lei->out($part->body); } +sub extract_attach ($$$) { + my ($lei, $blob, $bref) = @_; + my $eml = PublicInbox::Eml->new($bref); + $eml->each_part(\&cat_attach_i, $lei, 1); + my $idx = delete $lei->{-attach_idx}; + defined($idx) and return $lei->fail(<start_pager if -t $lei->{1}; @@ -102,11 +111,11 @@ sub lei_blob { if ($opt->{mail} // ($has_hints ? 0 : 1)) { if (grep(defined, @$opt{qw(include only)})) { $lxs = $lei->lxs_prepare; - $lei->ale->refresh_externals($lxs); + $lei->ale->refresh_externals($lxs, $lei); } my $rdr = {}; if ($opt->{mail}) { - $rdr->{2} = $lei->{2}; + open $rdr->{2}, '+>', undef or die "open: $!"; } else { open $rdr->{2}, '>', '/dev/null' or die "open: $!"; } @@ -115,21 +124,24 @@ sub lei_blob { if (defined $lei->{-attach_idx}) { my $fh = popen_rd($cmd, $lei->{env}, $rdr); require PublicInbox::Eml; - my $str = do { local $/; <$fh> }; - if (close $fh) { - my $eml = PublicInbox::Eml->new(\$str); - $eml->each_part(\&cat_attach_i, $lei, 1); - my $idx = delete $lei->{-attach_idx}; - defined($idx) and return $lei->fail(< }; + return extract_attach($lei, $blob, \$buf) if close($fh); } else { $rdr->{1} = $lei->{1}; waitpid(spawn($cmd, $lei->{env}, $rdr), 0); } - return if $? == 0; - return $lei->child_error($?) if $opt->{mail}; + my $ce = $?; + return if $ce == 0; + my $lms = $lei->lms; + if (my $bref = $lms ? $lms->local_blob($blob, 1) : undef) { + defined($lei->{-attach_idx}) and + return extract_attach($lei, $blob, $bref); + return $lei->out($$bref); + } elsif ($opt->{mail}) { + my $eh = $rdr->{2}; + seek($eh, 0, 0); + return $lei->child_error($ce, do { local $/; <$eh> }); + } # else: fall through to solver below } # maybe it's a non-email (code) blob from a coderepo @@ -141,7 +153,7 @@ EOM return $lei->fail('no --git-dir to try') unless @$git_dirs; unless ($lxs) { $lxs = $lei->lxs_prepare or return; - $lei->ale->refresh_externals($lxs); + $lei->ale->refresh_externals($lxs, $lei); } if ($lxs->remotes) { require PublicInbox::LeiRemote; @@ -154,8 +166,8 @@ EOM my ($op_c, $ops) = $lei->workers_start($self, 1); $lei->{wq1} = $self; $self->wq_io_do('do_solve_blob', []); - $self->wq_close(1); - $op_c->op_wait_event($ops); + $self->wq_close; + $lei->wait_wq_events($op_c, $ops); } sub ipc_atfork_child {