]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
git: make check_async callbacks identical to cat_async
authorEric Wong <e@80x24.org>
Fri, 28 Apr 2023 21:07:30 +0000 (21:07 +0000)
committerEric Wong <e@80x24.org>
Sat, 29 Apr 2023 06:05:13 +0000 (06:05 +0000)
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.

lib/PublicInbox/Git.pm
lib/PublicInbox/RepoSnapshot.pm
lib/PublicInbox/RepoTree.pm
lib/PublicInbox/SearchIdx.pm
lib/PublicInbox/V2Writable.pm

index 61ba8aa1d472b885dbb96523054915c1ae880bf5..764e38d7daabc16a01195b09f5c5086827b627d8 100644 (file)
@@ -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);
 }
 
index 93ba4db6e332a289afa89b177866201bf8134a43..ebcbbd815c0730158f9140e2a35a91ba74bc15ec 100644 (file)
@@ -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') {
index 25dc5b10fab84fa7ee68b876955bb9ea8e7b6926..9c7b86b330b44b0afe133ea0104455001dab37be 100644 (file)
@@ -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 ];
index cfc2d544fe2be4f9d0efabbc48ea49be410b7053..61dc7ce3a3d51cbdf9f51e62110a06017b356186 100644 (file)
@@ -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);
index ae8d778f8e151636bdcf1a8864fba2614595ac7d..191c55889e126e70a1a1c70fd1dee662c9571ad1 100644 (file)
@@ -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);