X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=blobdiff_plain;f=lib%2FPublicInbox%2FGitAsyncCat.pm;h=5f785df72ae4fb387a3ddb8aa28464adc4d65bbb;hp=8701e4cfe4889b654f509f18032a5ebd8413fc64;hb=abbdc3211b2f569c7847caedb16e82e8013b34fa;hpb=f1c9ad532f8dd46df172cfde85329a6e00ed1eab diff --git a/lib/PublicInbox/GitAsyncCat.pm b/lib/PublicInbox/GitAsyncCat.pm index 8701e4cf..5f785df7 100644 --- a/lib/PublicInbox/GitAsyncCat.pm +++ b/lib/PublicInbox/GitAsyncCat.pm @@ -1,7 +1,7 @@ # Copyright (C) 2020 all contributors # License: AGPL-3.0+ # -# internal class used by PublicInbox::Git + Danga::Socket +# internal class used by PublicInbox::Git + PublicInbox::DS # This parses the output pipe of "git cat-file --batch" # # Note: this does NOT set the non-blocking flag, we expect `git cat-file' @@ -11,41 +11,32 @@ package PublicInbox::GitAsyncCat; use strict; use parent qw(PublicInbox::DS Exporter); -use fields qw(git); use PublicInbox::Syscall qw(EPOLLIN EPOLLET); our @EXPORT = qw(git_async_cat); -sub new { +sub _add { my ($class, $git) = @_; - my $self = fields::new($class); $git->batch_prepare; + my $self = bless { git => $git }, $class; $self->SUPER::new($git->{in}, EPOLLIN|EPOLLET); - $self->{git} = $git; - $self; + \undef; # this is a true ref() } sub event_step { my ($self) = @_; - my $git = $self->{git} or return; # ->close-ed + my $git = $self->{git}; + return $self->close if ($git->{in} // 0) != ($self->{sock} // 1); my $inflight = $git->{inflight}; - if (@$inflight) { + if ($inflight && @$inflight) { $git->cat_async_step($inflight); $self->requeue if @$inflight || exists $git->{cat_rbuf}; } } -sub close { - my ($self) = @_; - if (my $git = delete $self->{git}) { - delete $git->{async_cat}; # drop circular reference - } - $self->SUPER::close; # PublicInbox::DS::close -} - sub git_async_cat ($$$$) { my ($git, $oid, $cb, $arg) = @_; $git->cat_async($oid, $cb, $arg); - $git->{async_cat} //= new(__PACKAGE__, $git); # circular reference + $git->{async_cat} //= _add(__PACKAGE__, $git); } 1;