]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Git.pm
treewide: "require" + "use" cleanup and docs
[public-inbox.git] / lib / PublicInbox / Git.pm
index 9059584086ca57ecfb3411cb2cae12b87cc9496b..6a527f82f9145ada72a1abbf053bf1987009283d 100644 (file)
@@ -10,7 +10,7 @@ package PublicInbox::Git;
 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);
@@ -114,12 +114,12 @@ sub _bidi_pipe {
 
        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: $!");
@@ -148,16 +148,18 @@ sub read_cat_in_full ($$$) {
 
 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 ($) {
@@ -319,15 +321,15 @@ sub cat_async_begin {
        $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 ($$) {