-# Copyright (C) 2014, Eric Wong <normalperson@yhbt.net> and all contributors
+# Copyright (C) 2014-2015 all contributors <meta@public-inbox.org>
# License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
package PublicInbox::Config;
use strict;
# 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};
$rv{$k} = $v;
}
}
+ close $fh or die "failed to close ($cmd) pipe: $!\n";
+ $? and warn "$$ $cmd exited with: ($pid) $?\n";
bless \%rv, $class;
}
defined $pfx or return;
my %rv;
- foreach my $k (qw(mainrepo description address)) {
+ foreach my $k (qw(mainrepo address)) {
my $v = $self->{"$pfx.$k"};
$rv{$k} = $v if defined $v;
}
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";
}