From f4bc5c4dbd713b78dec06a042fb26dd50594bc8a Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Tue, 4 Feb 2020 14:52:20 -0700 Subject: avoid invoking the shell during constructor Signed-off-by: Sean Whitton --- lib/Git/Annex.pm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/Git/Annex.pm b/lib/Git/Annex.pm index ad56ca8..0877697 100644 --- a/lib/Git/Annex.pm +++ b/lib/Git/Annex.pm @@ -69,6 +69,7 @@ use Data::Compare; use List::Util qw(all); use Time::HiRes qw(stat time); use Git::Annex::BatchCommand; +use IPC::System::Simple qw(capturex); use Moo; use namespace::clean; @@ -298,14 +299,17 @@ around BUILDARGS => sub { die "fork() failed: $!" unless defined $pid; if ($pid) { wait; - if ($?) { - chomp($toplevel = `git -C $toplevel rev-parse --show-toplevel`); - die "git rev-parse --show-toplevel failed" if $?; - } + chomp($toplevel = capturex "git", + "-C", $toplevel, "rev-parse", "--show-toplevel") + if $?; } else { close STDERR; - chomp(my $output = `git -C $toplevel rev-parse --is-inside-work-tree`); - exit ($output and $output eq "true"); + my $output; + try { + $output = capturex "git", "-C", $toplevel, "rev-parse", + "--is-inside-work-tree"; + }; + exit($output and $output =~ /true/); } return { toplevel => $toplevel }; -- cgit v1.2.3