]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
test_common: use cached git lookup to reduce stat(2)
authorEric Wong <e@80x24.org>
Thu, 6 Jun 2024 07:44:14 +0000 (07:44 +0000)
committerEric Wong <e@80x24.org>
Fri, 7 Jun 2024 00:39:46 +0000 (00:39 +0000)
This reduces syscalls required to run tests and IMHO improves
readability since we're not having to import `git_exe' everywhere.

lib/PublicInbox/TestCommon.pm

index a01949a3745ece5d1ee572172ebb1e322c239d1b..00e96aeef98214447012d8fd0cce2ffeed7481e1 100644 (file)
@@ -167,11 +167,8 @@ sub require_git ($;$) {
 sub require_git_http_backend (;$) {
        my ($nr) = @_;
        state $ok = do {
-               require PublicInbox::Git;
-               my $git = PublicInbox::Git::git_exe() or plan
-                       skip_all => 'nothing in public-inbox works w/o git';
                my $rdr = { 1 => \my $out, 2 => \my $err };
-               xsys([$git, qw(http-backend)], undef, $rdr);
+               xsys([qw(git http-backend)], undef, $rdr);
                $out =~ /^Status:/ism;
        };
        if (!$ok) {
@@ -274,7 +271,9 @@ sub require_mods {
 
 sub key2script ($) {
        my ($key) = @_;
-       return $key if ($key eq 'git' || index($key, '/') >= 0);
+       require PublicInbox::Git;
+       return PublicInbox::Git::git_exe() if $key eq 'git';
+       return $key if index($key, '/') >= 0;
        # n.b. we may have scripts which don't start with "public-inbox" in
        # the future:
        $key =~ s/\A([-\.])/public-inbox$1/;