]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Config.pm
cgi: remove dependency on IPC::Run in CGI
[public-inbox.git] / lib / PublicInbox / Config.pm
index 32bd9ab6211e43e272ed0c6d43b274f6fb7dbb73..364f82cd845372c98b59c66d5bcedb531f6ac6d2 100644 (file)
@@ -9,14 +9,16 @@ use File::Path::Expand qw/expand_filename/;
 # if keys may be multi-value, the value is an array ref containing all values
 sub new {
        my ($class, $file) = @_;
+       my ($in, $out);
 
-       local $ENV{GIT_CONFIG} = defined $file ? $file : default_file();
-
-       my @cfg = `git config -l`;
-       $? == 0 or die "git config -l failed: $?\n";
-       chomp @cfg;
+       $file = default_file() unless defined($file);
+       my @cmd = (qw/git config/, "--file=$file", '-l');
+       my $cmd = join(' ', @cmd);
+       my $pid = open(my $fh, '-|', @cmd);
+       defined $pid or die "$cmd failed: $!\n";
        my %rv;
-       foreach my $line (@cfg) {
+       foreach my $line (<$fh>) {
+               chomp $line;
                my ($k, $v) = split(/=/, $line, 2);
                my $cur = $rv{$k};
 
@@ -30,6 +32,8 @@ sub new {
                        $rv{$k} = $v;
                }
        }
+       close $fh or die "failed to close ($cmd) pipe: $!\n";
+       $? and warn "$$ $cmd exited with: ($pid) $?\n";
        bless \%rv, $class;
 }
 
@@ -78,7 +82,7 @@ sub get {
 sub default_file {
        my $f = $ENV{PI_CONFIG};
        return $f if defined $f;
-       my $pi_dir = $ENV{PI_DIR} || expand_filename('~/.public-inbox/');
+       my $pi_dir = $ENV{PI_DIR} || expand_filename('~/.public-inbox');
        "$pi_dir/config";
 }