]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Config.pm
update copyright headers and email addresses
[public-inbox.git] / lib / PublicInbox / Config.pm
index d71bc52e203d7c79efc3f9a4c4aab14bfdb974bf..315d788b8f3a508ed8fb53a03cafe2fdc1ad9812 100644 (file)
@@ -1,4 +1,4 @@
-# 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;
@@ -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;
 }
 
@@ -57,7 +61,7 @@ sub lookup {
        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;
        }
@@ -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";
 }