unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH] git: make check_async callbacks identical to cat_async
@ 2023-04-28 21:07 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2023-04-28 21:07 UTC (permalink / raw)
  To: meta

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          | 13 ++++---------
 lib/PublicInbox/RepoSnapshot.pm |  2 +-
 lib/PublicInbox/RepoTree.pm     |  2 +-
 lib/PublicInbox/SearchIdx.pm    |  7 ++++---
 lib/PublicInbox/V2Writable.pm   |  1 +
 5 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 61ba8aa1..764e38d7 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 93ba4db6..ebcbbd81 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 25dc5b10..9c7b86b3 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 cfc2d544..61dc7ce3 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 ae8d778f..191c5588 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);

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-04-28 21:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-28 21:07 [PATCH] git: make check_async callbacks identical to cat_async Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).