]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Git.pm
wwwstream: allow undef noop callback
[public-inbox.git] / lib / PublicInbox / Git.pm
index d8211827f1aa85e82934b2e83616a77015e8c3b5..f47bc439080749c25100aca9cb1bb0f32b2d7c13 100644 (file)
@@ -28,7 +28,9 @@ sub _bidi_pipe {
 
        my @cmd = ('git', "--git-dir=$self->{git_dir}", qw(cat-file), $batch);
        my $redir = { 0 => fileno($out_r), 1 => fileno($in_w) };
-       $self->{$pid} = spawn(\@cmd, undef, $redir);
+       my $p = spawn(\@cmd, undef, $redir);
+       defined $p or fail($self, "spawn failed: $!");
+       $self->{$pid} = $p;
        $out_w->autoflush(1);
        $self->{$out} = $out_w;
        $self->{$in} = $in_r;
@@ -41,6 +43,7 @@ sub cat_file {
        $self->{out}->print($obj, "\n") or fail($self, "write error: $!");
 
        my $in = $self->{in};
+       local $/ = "\n";
        my $head = $in->getline;
        $head =~ / missing$/ and return undef;
        $head =~ /^[0-9a-f]{40} \S+ (\d+)$/ or
@@ -90,6 +93,7 @@ sub check {
        my ($self, $obj) = @_;
        $self->_bidi_pipe(qw(--batch-check in_c out_c pid_c));
        $self->{out_c}->print($obj, "\n") or fail($self, "write error: $!");
+       local $/ = "\n";
        chomp(my $line = $self->{in_c}->getline);
        my ($hex, $type, $size) = split(' ', $line);
        return if $type eq 'missing';
@@ -120,6 +124,8 @@ sub popen {
 sub qx {
        my ($self, @cmd) = @_;
        my $fh = $self->popen(@cmd);
+       defined $fh or return;
+       local $/ = "\n";
        return <$fh> if wantarray;
        local $/;
        <$fh>