From 881a5493a8c970c10c051cc55d10d2968e71e691 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 19 Sep 2020 09:37:13 +0000 Subject: gcf2: require git dir with OID This amortizes the cost of recreating PublicInbox::Gcf2 objects when alternates change in v2 all.git. --- lib/PublicInbox/Gcf2Client.pm | 13 ------------- lib/PublicInbox/Git.pm | 5 +++-- lib/PublicInbox/GitAsyncCat.pm | 24 +++++++++++++++--------- 3 files changed, 18 insertions(+), 24 deletions(-) (limited to 'lib') diff --git a/lib/PublicInbox/Gcf2Client.pm b/lib/PublicInbox/Gcf2Client.pm index a048cd1a..30f85c71 100644 --- a/lib/PublicInbox/Gcf2Client.pm +++ b/lib/PublicInbox/Gcf2Client.pm @@ -23,19 +23,6 @@ sub new { $self; } -sub add_git_dir { - my ($self, $git_dir) = @_; - - # ensure buffers are drained, length($git_dir) may exceed - # PIPE_BUF on platforms where PIPE_BUF is only 512 bytes - my $inflight = $self->{inflight}; - while (scalar(@$inflight)) { - $self->cat_async_step($inflight); - } - print { $self->{out} } $git_dir, "\n" or - $self->fail("write error: $!"); -} - # always false, since -gcf2 retries internally sub alternates_changed {} diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index b49b5bd3..6bb82b6b 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -190,7 +190,8 @@ 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 =~ s/ missing\n//s) { + $oid = $head; # ref($req) indicates it's already been retried # -gcf2 retries internally, so it never hits this path: if (!ref($req) && !$in_cleanup && $self->alternates_changed) { @@ -198,7 +199,7 @@ sub cat_async_step ($$) { $req, $cb, $arg); } $type = 'missing'; - $oid = ref($req) ? $$req : $req; + $oid = ref($req) ? $$req : $req if $oid eq ''; } else { fail($self, "Unexpected result from async git cat-file: $head"); } diff --git a/lib/PublicInbox/GitAsyncCat.pm b/lib/PublicInbox/GitAsyncCat.pm index db1a7f94..8a54c608 100644 --- a/lib/PublicInbox/GitAsyncCat.pm +++ b/lib/PublicInbox/GitAsyncCat.pm @@ -16,21 +16,27 @@ our @EXPORT = qw(git_async_cat); sub event_step { my ($self) = @_; - my $git = $self->{git}; - return $self->close if ($git->{in} // 0) != ($self->{sock} // 1); - my $inflight = $git->{inflight}; + my $gitish = $self->{gitish}; + return $self->close if ($gitish->{in} // 0) != ($self->{sock} // 1); + my $inflight = $gitish->{inflight}; if ($inflight && @$inflight) { - $git->cat_async_step($inflight); - $self->requeue if @$inflight || exists $git->{cat_rbuf}; + $gitish->cat_async_step($inflight); + $self->requeue if @$inflight || exists $gitish->{cat_rbuf}; } } sub git_async_cat ($$$$) { my ($git, $oid, $cb, $arg) = @_; - $git->cat_async($oid, $cb, $arg); - $git->{async_cat} //= do { - my $self = bless { git => $git }, __PACKAGE__; - $self->SUPER::new($git->{in}, EPOLLIN|EPOLLET); + my $gitish = $git->{gcf2c}; # PublicInbox::Gcf2Client + if ($gitish) { + $oid .= " $git->{git_dir}"; + } else { + $gitish = $git; + } + $gitish->cat_async($oid, $cb, $arg); + $gitish->{async_cat} //= do { + my $self = bless { gitish => $gitish }, __PACKAGE__; + $self->SUPER::new($gitish->{in}, EPOLLIN|EPOLLET); \undef; # this is a true ref() }; } -- cgit v1.2.3-24-ge0c7