From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 644D71FBCD for ; Wed, 10 Jun 2020 07:06:25 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 33/82] git: cat_async: provide requested OID + "missing" on missing blobs Date: Wed, 10 Jun 2020 07:04:30 +0000 Message-Id: <20200610070519.18252-34-e@yhbt.net> In-Reply-To: <20200610070519.18252-1-e@yhbt.net> References: <20200610070519.18252-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This will make it easier to implement the retries on alternates_changed() of the synchronous ->cat_file API. --- lib/PublicInbox/Git.pm | 13 ++++++++----- t/git.t | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 1c148086f46..b3ae2b812ba 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -20,7 +20,7 @@ use Errno qw(EINTR); our $PIPE_BUFSIZ = 65536; # Linux default use constant MAX_INFLIGHT => - (($^O eq 'linux' ? 4096 : POSIX::_POSIX_PIPE_BUF()) * 2) + (($^O eq 'linux' ? 4096 : POSIX::_POSIX_PIPE_BUF()) * 3) / 65; # SHA-256 hex size + "\n" in preparation for git using non-SHA1 @@ -157,8 +157,8 @@ sub my_readline ($$) { sub cat_async_step ($$) { my ($self, $inflight) = @_; - die 'BUG: inflight empty or odd' if scalar(@$inflight) < 2; - my ($cb, $arg) = splice(@$inflight, 0, 2); + die 'BUG: inflight empty or odd' if scalar(@$inflight) < 3; + my ($req, $cb, $arg) = splice(@$inflight, 0, 3); my $rbuf = delete($self->{cat_rbuf}) // \(my $new = ''); my ($bref, $oid, $type, $size); my $head = my_readline($self->{in}, $rbuf); @@ -167,7 +167,10 @@ sub cat_async_step ($$) { $bref = my_read($self->{in}, $rbuf, $size + 1) or fail($self, defined($bref) ? 'read EOF' : "read: $!"); chop($$bref) eq "\n" or fail($self, 'LF missing after blob'); - } elsif ($head !~ / missing$/) { + } elsif ($head =~ / missing$/) { + $type = 'missing'; + $oid = $req; + } else { fail($self, "Unexpected result from async git cat-file: $head"); } eval { $cb->($bref, $oid, $type, $size, $arg) }; @@ -344,7 +347,7 @@ sub cat_async ($$$;$) { } print { $self->{out} } $oid, "\n" or fail($self, "write error: $!"); - push(@$inflight, $cb, $arg); + push(@$inflight, $oid, $cb, $arg); } sub extract_cmt_time { diff --git a/t/git.t b/t/git.t index 0b2089ba701..98d16f289c3 100644 --- a/t/git.t +++ b/t/git.t @@ -53,7 +53,7 @@ use_ok 'PublicInbox::Git'; is_deeply([$oid_hex, $type, $size], \@x, 'got expected header'); is($arg_res, $arg, 'arg passed to cat_async'); is_deeply($raw, $bref, 'blob result matches'); - is_deeply($missing, [ undef, undef, undef, undef, $arg], + is_deeply($missing, [ undef, 'non-existent', 'missing', undef, $arg], 'non-existent blob gives expected result'); }