$self->{out}->print($obj."\n") or fail($self, "write error: $!");
my $in = $self->{in};
my $info = async_info_compat($in);
+ my (undef, $type, $left) = @$info;
$cb->($info);
- return if scalar(@$info) != 3; # missing
+ return if $info->[1] eq 'missing';
my $max = 8192;
- my $left = $info->[2];
my ($buf, $r);
while ($left > 0) {
$r = read($in, $buf, $left > $max ? $max : $left);
$r = read($in, $buf, 1);
defined($r) or fail($self, "read failed: $!");
fail($self, 'newline missing after blob') if ($r != 1 || $buf ne "\n");
+ $cb->(0);
}
sub check_async {
}
$cb->($info); # $info may 0 (EOF, or undef, $cb will see $!)
return $self->close unless $info;
- if ($check || (scalar(@$info) != 3)) {
+ if ($check || $info->[1] eq 'missing') {
# do not monopolize the event loop if we're drained:
return if ${$self->{rbuf}} eq '';
goto take_job;
my $lf = chop $$rbuf;
$lf eq "\n" or die "BUG: missing LF (got $lf)";
$cb->($rbuf);
+ $cb->(0);
return if $buf eq '';
goto take_job;
my $buf = '';
$req->{-repo}->{git}->cat_async($req->{env}, $hex, sub {
my ($r) = @_;
- return if ref($r) ne 'SCALAR';
- $buf .= $$r;
- return if bytes::length($buf) < $size;
- $ct ||= index($buf, "\0") >= 0 ?
- 'application/octet-stream' :
- 'text/plain; charset=UTF-8';
- $res->([200, ['Content-Type', $ct,
- 'Content-Length', $size ],
- [ $buf ]]);
+ if (ref($r) eq 'SCALAR') {
+ $buf .= $$r;
+ } elsif ($r == 0) {
+ return if bytes::length($buf) < $size;
+ $ct ||= index($buf, "\0") >= 0 ?
+ 'application/octet-stream' :
+ 'text/plain; charset=UTF-8';
+ $res->([200, ['Content-Type', $ct,
+ 'Content-Length', $size ],
+ [ $buf ]]);
+ }
});
}
}
return if $ref eq 'ARRAY'; # redundant info
if ($ref eq 'SCALAR') {
$buf .= $$r;
- if (bytes::length($buf) == $size) {
- my $fh = $res->($self->rt(200, 'html'));
- my $sed = git_blob_sed($req, $hex, $size);
- $fh->write($sed->($buf));
- $fh->write($sed->(undef));
- $fh->close;
- }
- return;
+ } elsif (!defined $r) {
+ my $cb = $res or return;
+ $res = undef;
+ $cb->($self->rt(500, 'plain', "Error\n"));
+ } elsif ($r == 0) {
+ my $fh = $res->($self->rt(200, 'html'));
+ my $sed = git_blob_sed($req, $hex, $size);
+ $fh->write($sed->($buf));
+ $fh->write($sed->(undef));
+ $fh->close;
}
- my $cb = $res or return;
- $res = undef;
- $cb->($self->rt(500, 'plain', "Error\n"));
});
}
}
my @info;
my $str = '';
+ my $eof_seen = 0;
$git->cat_async_compat('HEAD:foo.txt', sub {
my $ref = $_[0];
my $t = ref $ref;
push @info, $ref;
} elsif ($t eq 'SCALAR') {
$str .= $$ref;
+ } elsif ($ref == 0) {
+ $eof_seen++;
} else {
fail "fail type: $t";
}
});
+ is($eof_seen, 1, 'EOF seen once');
is_deeply(\@info, [ [ 'bf4f17855632367a160bef055fc8ba4675d10e6b',
'blob', 18 ]], 'info matches compat');
is($str, "-----\nhello\nworld\n", 'data matches compat');