]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiP2q.pm
lei: use standard warn() in more places
[public-inbox.git] / lib / PublicInbox / LeiP2q.pm
index 25f63a10d623c62dbb1abbacbabc786447d9cca1..5c2ce0a13dfc85eda2bf28017f5fa0ac31712754 100644 (file)
@@ -105,6 +105,7 @@ sub do_p2q { # via wq_do
        }
        my $smsg = bless {}, 'PublicInbox::Smsg';
        my $in = $self->{0};
+       my @cmd;
        unless ($in) {
                my $input = $self->{input};
                my $devfd = $lei->path_to_fd($input) // return;
@@ -114,11 +115,13 @@ sub do_p2q { # via wq_do
                        open($in, '<', $input) or
                                return $lei->fail("open < $input: $!");
                } else {
-                       my @cmd = (qw(git format-patch --stdout -1), $input);
+                       @cmd = (qw(git format-patch --stdout -1), $input);
                        $in = popen_rd(\@cmd, undef, { 2 => $lei->{2} });
                }
        };
-       my $eml = PublicInbox::Eml->new(\(do { local $/; <$in> }));
+       my $str = do { local $/; <$in> };
+       @cmd && !close($in) and return $lei->fail("E: @cmd failed: $?");
+       my $eml = PublicInbox::Eml->new(\$str);
        $lei->{diff_want} = +{ map { $_ => 1 } @want };
        $smsg->populate($eml);
        while (my ($pfx, $fields) = each %pfx2smsg) {
@@ -132,7 +135,7 @@ sub do_p2q { # via wq_do
        if ($lei->{opt}->{debug}) {
                my $json = ref(PublicInbox::Config->json)->new;
                $json->utf8->canonical->pretty;
-               $lei->err($json->encode($lei->{qterms}));
+               print { $lei->{2} } $json->encode($lei->{qterms});
        }
        my (@q, %seen);
        for my $pfx (@want) {
@@ -185,18 +188,16 @@ sub lei_p2q { # the "lei patch-to-query" entry point
        } else {
                $self->{input} = $input;
        }
-       my $op = $lei->workers_start($self, 'lei_p2q', 1);
-       $lei->{p2q} = $self;
+       my ($op_c, $ops) = $lei->workers_start($self, 1);
+       $lei->{wq1} = $self;
        $self->wq_io_do('do_p2q', []);
        $self->wq_close(1);
-       while ($op && $op->{sock}) { $op->event_step }
+       $lei->wait_wq_events($op_c, $ops);
 }
 
 sub ipc_atfork_child {
        my ($self) = @_;
-       my $lei = $self->{lei};
-       $lei->_lei_atfork_child;
-       $SIG{__WARN__} = PublicInbox::Eml::warn_ignore_cb();
+       $self->{lei}->_lei_atfork_child;
        $self->SUPER::ipc_atfork_child;
 }