use Time::HiRes qw(stat);
use PublicInbox::Spawn qw(popen_rd);
use PublicInbox::Tmpfile;
+use Carp qw(croak);
our @EXPORT_OK = qw(git_unquote git_quote);
our $PIPE_BUFSIZ = 65536; # Linux default
our $in_cleanup;
my $rbuf = delete($self->{cat_rbuf}) // \(my $new = '');
my ($bref, $oid, $type, $size);
my $head = my_readline($self->{in}, $rbuf);
- if ($head =~ /^([0-9a-f]{40}) (\S+) ([0-9]+)$/) {
+ if ($head =~ /^([0-9a-f]{40,}) (\S+) ([0-9]+)$/) {
($oid, $type, $size) = ($1, $2, $3 + 0);
$bref = my_read($self->{in}, $rbuf, $size + 1) or
fail($self, defined($bref) ? 'read EOF' : "read: $!");
sub fail {
my ($self, $msg) = @_;
$self->{inflight} ? cat_async_abort($self) : cleanup($self);
- die $msg;
+ croak("git $self->{git_dir}: $msg");
}
sub popen {
push(@$inflight, $oid, $cb, $arg);
}
+# this is safe to call inside $cb, but not guaranteed to enqueue
+# returns true if successful, undef if not.
+sub async_prefetch {
+ my ($self, $oid, $cb, $arg) = @_;
+ if (defined($self->{async_cat}) && (my $inflight = $self->{inflight})) {
+ # we could use MAX_INFLIGHT here w/o the halving,
+ # but lets not allow one client to monopolize a git process
+ if (scalar(@$inflight) < int(MAX_INFLIGHT/2)) {
+ print { $self->{out} } $oid, "\n" or
+ fail($self, "write error: $!");
+ return push(@$inflight, $oid, $cb, $arg);
+ }
+ }
+ undef;
+}
+
sub extract_cmt_time {
my ($bref, undef, undef, undef, $modified) = @_;