From: Eric Wong Date: Fri, 28 Apr 2023 21:07:30 +0000 (+0000) Subject: git: make check_async callbacks identical to cat_async X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=847389d8d4012177616e51f0af3151ed8ab58ff3;p=thirdparty%2Fpublic-inbox.git git: make check_async callbacks identical to cat_async This simplifies Git->cat_async_step and fixes Git->async_abort, the latter of which was passing arguments improperly for the --batch-check (or `info') case at the cost of making the few check_async callers handle an extra argument. The extra (PublicInbox::Git) $self argument for check_async callbacks is now gone, as avoiding the temporary cyclic reference doesn't seem worthwhile since the temporary cyclic reference appears in the ->cat_async code paths, too. --- diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 61ba8aa1d..764e38d7d 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -299,13 +299,8 @@ sub cat_async_step ($$) { } $self->{rbuf} = $rbuf if $$rbuf ne ''; splice(@$inflight, 0, 3); # don't retry $cb on ->fail - if ($info) { - eval { $cb->($oid, $type, $size, $arg, $self) }; - async_err($self, $req, $oid, $@, 'check') if $@; - } else { - eval { $cb->($bref, $oid, $type, $size, $arg) }; - async_err($self, $req, $oid, $@, 'cat') if $@; - } + eval { $cb->($bref, $oid, $type, $size, $arg) }; + async_err($self, $req, $oid, $@, $info ? 'check' : 'cat') if $@; } sub cat_async_wait ($) { @@ -357,7 +352,7 @@ sub check_async_step ($$) { } $self->{rbuf_c} = $rbuf if $$rbuf ne ''; splice(@$inflight_c, 0, 3); # don't retry $cb on ->fail - eval { $cb->($hex, $type, $size, $arg, $self) }; + eval { $cb->(undef, $hex, $type, $size, $arg) }; async_err($self, $req, $hex, $@, 'check') if $@; } @@ -415,7 +410,7 @@ sub check_async ($$$$) { } sub _check_cb { # check_async callback - my ($hex, $type, $size, $result) = @_; + my (undef, $hex, $type, $size, $result) = @_; @$result = ($hex, $type, $size); } diff --git a/lib/PublicInbox/RepoSnapshot.pm b/lib/PublicInbox/RepoSnapshot.pm index 93ba4db6e..ebcbbd815 100644 --- a/lib/PublicInbox/RepoSnapshot.pm +++ b/lib/PublicInbox/RepoSnapshot.pm @@ -42,7 +42,7 @@ sub archive_hdr { # parse_hdr for Qspawn } sub ver_check { # git->check_async callback - my ($oid, $type, $size, $ctx) = @_; + my (undef, $oid, $type, $size, $ctx) = @_; return if defined $ctx->{etag}; my $treeish = shift @{$ctx->{-try}} // die 'BUG: no {-try}'; if ($type eq 'missing') { diff --git a/lib/PublicInbox/RepoTree.pm b/lib/PublicInbox/RepoTree.pm index 25dc5b10f..9c7b86b33 100644 --- a/lib/PublicInbox/RepoTree.pm +++ b/lib/PublicInbox/RepoTree.pm @@ -62,7 +62,7 @@ sub find_missing { } sub tree_show { # git check_async callback - my ($oid, $type, $size, $ctx) = @_; + my (undef, $oid, $type, $size, $ctx) = @_; return find_missing($ctx) if $type eq 'missing'; my $res = [ $ctx->{git}, $oid, $type, $size ]; diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index cfc2d544f..61dc7ce3a 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -839,10 +839,10 @@ sub index_sync { } sub check_size { # check_async cb for -index --max-size=... - my ($oid, $type, $size, $arg, $git) = @_; - (($type // '') eq 'blob') or die "E: bad $oid in $git->{git_dir}"; + my (undef, $oid, $type, $size, $arg) = @_; + ($type // '') eq 'blob' or die "E: bad $oid in $arg->{git}->{git_dir}"; if ($size <= $arg->{max_size}) { - $git->cat_async($oid, $arg->{index_oid}, $arg); + $arg->{git}->cat_async($oid, $arg->{index_oid}, $arg); } else { warn "W: skipping $oid ($size > $arg->{max_size})\n"; } @@ -924,6 +924,7 @@ sub process_stack { $arg->{autime} = $at; $arg->{cotime} = $ct; if ($sync->{max_size}) { + $arg->{git} = $git; $git->check_async($oid, \&check_size, $arg); } else { $git->cat_async($oid, \&index_both, $arg); diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index ae8d778f8..191c55889 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -1160,6 +1160,7 @@ sub index_todo ($$$) { }; if ($f eq 'm') { if ($sync->{max_size}) { + $req->{git} = $all; $all->check_async($oid, \&check_size, $req); } else { $all->cat_async($oid, $index_oid, $req);