t/imapd.t on my slower 32-bit machine fails without the
following fix. I guess prefetch wasn't being tested on my
faster workstation?
Also, the prior use of `print { $git->{out} }' is a potential (but
unlikely) bug since commit d4ba8828ab23f278
(git: fix asynchronous batching for deep pipelines, 2023-01-04)
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 1c77b4ce..a9db8ad7 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -239,6 +239,16 @@ sub cat_async_retry ($$) {
cat_async_step($self, $inflight); # take one step
}
+# returns true if prefetch is successful
+sub async_prefetch {
+ my ($self, $oid, $cb, $arg) = @_;
+ my $inflight = $self->{inflight} or return;
+ return if @$inflight;
+ substr($oid, 0, 0) = 'contents ' if $self->{-bc};
+ write_all($self, $self->{out}, "$oid\n", \&cat_async_step, $inflight);
+ push(@$inflight, $oid, $cb, $arg);
+}
+
sub cat_async_step ($$) {
my ($self, $inflight) = @_;
die 'BUG: inflight empty or odd' if scalar(@$inflight) < 3;
diff --git a/lib/PublicInbox/GitAsyncCat.pm b/lib/PublicInbox/GitAsyncCat.pm
index 1f86aad0..49a3c602 100644
--- a/lib/PublicInbox/GitAsyncCat.pm
+++ b/lib/PublicInbox/GitAsyncCat.pm
@@ -98,12 +98,8 @@ sub ibx_async_prefetch {
$oid .= " $git->{git_dir}\n";
return $GCF2C->gcf2_async(\$oid, $cb, $arg); # true
}
- } elsif ($git->{async_cat} && (my $inflight = $git->{inflight})) {
- if (!@$inflight) {
- print { $git->{out} } $oid, "\n" or
- $git->fail("write error: $!");
- return push(@$inflight, $oid, $cb, $arg);
- }
+ } elsif ($git->{async_cat}) {
+ return $git->async_prefetch($oid, $cb, $arg);
}
undef;
}