use strict;
use warnings;
use POSIX qw(dup2);
-require IO::Handle;
+use IO::Handle; # ->autoflush
use PublicInbox::Spawn qw(spawn popen_rd);
use PublicInbox::Tmpfile;
use base qw(Exporter);
my @cmd = (qw(git), "--git-dir=$self->{git_dir}",
qw(-c core.abbrev=40 cat-file), $batch);
- my $redir = { 0 => fileno($out_r), 1 => fileno($in_w) };
+ my $redir = { 0 => $out_r, 1 => $in_w };
if ($err) {
my $id = "git.$self->{git_dir}$batch.err";
my $fh = tmpfile($id) or fail($self, "tmpfile($id): $!");
$self->{$err} = $fh;
- $redir->{2} = fileno($fh);
+ $redir->{2} = $fh;
}
my $p = spawn(\@cmd, undef, $redir);
defined $p or fail($self, "spawn failed: $!");
sub _cat_async_step ($$$) {
my ($self, $inflight, $in) = @_;
- my $cb = shift @$inflight or die 'BUG: inflight empty';
+ my $pair = shift @$inflight or die 'BUG: inflight empty';
+ my ($cb, $arg) = @$pair;
local $/ = "\n";
my $head = $in->getline;
- return eval { $cb->(undef) } if $head =~ / missing$/;
+ $head =~ / missing$/ and return
+ eval { $cb->(undef, undef, undef, undef, $arg) };
$head =~ /^([0-9a-f]{40}) (\S+) ([0-9]+)$/ or
fail($self, "Unexpected result from async git cat-file: $head");
my ($oid_hex, $type, $size) = ($1, $2, $3 + 0);
my $bref = read_cat_in_full($self, $in, $size);
- eval { $cb->($bref, $oid_hex, $type, $size) };
+ eval { $cb->($bref, $oid_hex, $type, $size, $arg) };
}
sub cat_async_wait ($) {
$self->{inflight} = [];
}
-sub cat_async ($$$) {
- my ($self, $oid, $cb) = @_;
+sub cat_async ($$$;$) {
+ my ($self, $oid, $cb, $arg) = @_;
my $inflight = $self->{inflight} or die 'BUG: not in async';
if (scalar(@$inflight) >= MAX_INFLIGHT) {
_cat_async_step($self, $inflight, $self->{in});
}
$self->{out}->print($oid, "\n") or fail($self, "write error: $!");
- push @$inflight, $cb;
+ push(@$inflight, [ $cb, $arg ]);
}
sub commit_title ($$) {