]> Sergey Matveev's repositories - public-inbox.git/commitdiff
git: qx: avoid extra "local" for scalar context case
authorEric Wong <e@80x24.org>
Sun, 27 Dec 2020 02:53:03 +0000 (02:53 +0000)
committerEric Wong <e@80x24.org>
Mon, 28 Dec 2020 23:19:47 +0000 (23:19 +0000)
We can use the ternary operator to avoid an early return, here

lib/PublicInbox/Git.pm
t/git.t

index 084069259110d26e8b043822c0c22ecc4a8a81d7..73dc7d3e5d99feae413f92226cde9e4d77b29b3b 100644 (file)
@@ -362,10 +362,8 @@ sub popen {
 sub qx {
        my ($self, @cmd) = @_;
        my $fh = $self->popen(@cmd);
-       local $/ = "\n";
-       return <$fh> if wantarray;
-       local $/;
-       <$fh>
+       local $/ = wantarray ? "\n" : undef;
+       <$fh>;
 }
 
 # check_async and cat_async may trigger the other, so ensure they're
diff --git a/t/git.t b/t/git.t
index dfd7173a432c78dd9072a9530be7e1695b4ee20d..dcd053c569429efc5a91a86857ee932ee938da82 100644 (file)
--- a/t/git.t
+++ b/t/git.t
@@ -79,6 +79,7 @@ if (1) {
        my @ref = $gcf->qx(qw(cat-file blob), $buf);
        my $nl = scalar @ref;
        ok($nl > 1, "qx returned array length of $nl");
+       is(join('', @ref), $ref, 'qx array and scalar context both work');
 
        $gcf->qx(qw(repack -adq));
        ok($gcf->packed_bytes > 0, 'packed size is positive');