# returns true if there are pending "git cat-file" processes
sub cleanup {
my ($self) = @_;
+ if (my $ac = $self->{async_cat}) {
+ $ac->close; # PublicInbox::GitAsyncCat::close -> EPOLL_CTL_DEL
+ }
cat_async_wait($self);
_destroy($self, qw(cat_rbuf in out pid));
_destroy($self, qw(chk_rbuf in_c out_c pid_c err_c));
use parent qw(PublicInbox::DS Exporter);
use fields qw(git);
use PublicInbox::Syscall qw(EPOLLIN EPOLLET);
-our @EXPORT = qw(git_async_msg);
+our @EXPORT = qw(git_async_cat);
sub new {
my ($class, $git) = @_;
sub close {
my ($self) = @_;
- delete $self->{git};
+ if (my $git = delete $self->{git}) {
+ delete $git->{async_cat}; # drop circular reference
+ }
$self->SUPER::close; # PublicInbox::DS::close
}
-sub git_async_msg ($$$$) {
- my ($ibx, $smsg, $cb, $arg) = @_;
- $ibx->git->cat_async($smsg->{blob}, $cb, $arg);
- $ibx->{async_cat} //= new(__PACKAGE__, $ibx->{git});
+sub git_async_cat ($$$$) {
+ my ($git, $oid, $cb, $arg) = @_;
+ $git->cat_async($oid, $cb, $arg);
+ $git->{async_cat} //= new(__PACKAGE__, $git); # circular reference
}
1;
$self->requeue if $new_size == 1;
}
-sub uid_fetch_cb { # called by git->cat_async via git_async_msg
+sub uid_fetch_cb { # called by git->cat_async via git_async_cat
my ($bref, $oid, $type, $size, $fetch_m_arg) = @_;
my ($self, undef, $ibx, $msgs, undef, $want) = @$fetch_m_arg;
my $smsg = shift @$msgs or die 'BUG: no smsg';
} else {
$smsg->{blob} eq $oid or die "BUG: $smsg->{blob} != $oid";
}
+
$$bref =~ s/(?<!\r)\n/\r\n/sg; # make strict clients happy
# fixup old bug from import (pre-a0c07cba0e5d8b6a)
return;
}
}
- git_async_msg($ibx, $msgs->[0], \&uid_fetch_cb, \@_);
+ git_async_cat($ibx->git, $msgs->[0]->{blob}, \&uid_fetch_cb, \@_);
}
sub cmd_status ($$$;@) {
my $seq = $want->{-seqno}++;
my $cur_num = $msgs->[0]->{num};
if ($cur_num == $seq) { # as expected
- git_async_msg($ibx, $msgs->[0], \&uid_fetch_cb, \@_);
+ git_async_cat($ibx->git, $msgs->[0]->{blob},
+ \&uid_fetch_cb, \@_);
} elsif ($cur_num > $seq) {
# send dummy messages until $seq catches up to $cur_num
my $smsg = bless { num => $seq, ts => 0 }, 'PublicInbox::Smsg';