+ my $next = {};
+ for my $ibx (values %$CLEANUP) {
+ my $again;
+ if ($have_devel_peek) {
+ foreach my $f (qw(mm search over)) {
+ # we bump refcnt by assigning tmp, here:
+ my $tmp = $ibx->{$f} or next;
+ next if Devel::Peek::SvREFCNT($tmp) > 2;
+ delete $ibx->{$f};
+ # refcnt is zero when tmp is out-of-scope
+ }
+ }
+ if (my $git = $ibx->{git}) {
+ $again = $git->cleanup;
+ }
+ if (my $gits = $ibx->{-repo_objs}) {
+ foreach my $git (@$gits) {
+ $again = 1 if $git->cleanup;
+ }
+ }
+ if ($have_devel_peek) {
+ $again ||= !!($ibx->{over} || $ibx->{mm} ||
+ $ibx->{search});
+ }
+ $next->{"$ibx"} = $ibx if $again;
+ }
+ $CLEANUP = $next;
+}
+
+sub cleanup_possible () {
+ # no need to require DS, here, if it were enabled another
+ # module would've require'd it, already
+ eval { PublicInbox::DS::in_loop() } or return 0;
+
+ eval {
+ require Devel::Peek; # needs separate package in Fedora
+ $have_devel_peek = 1;
+ };
+ 1;