about summary refs log tree commit homepage
path: root/lib/PublicInbox/Config.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-04-01 23:07:38 +0000
committerEric Wong <normalperson@yhbt.net>2014-04-05 06:55:35 +0000
commit71abf270f5b11f147be839a9b057e106d0f8509f (patch)
treed0e4a24f103aa8ce7012f840a36a58ffd3cd0ac1 /lib/PublicInbox/Config.pm
parentb949afc9edf89dd494cac6255c78b124d58e11a5 (diff)
downloadpublic-inbox-71abf270f5b11f147be839a9b057e106d0f8509f.tar.gz
We will be reusing the config parsing code for the CGI
script, too.
Diffstat (limited to 'lib/PublicInbox/Config.pm')
-rw-r--r--lib/PublicInbox/Config.pm10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index d91c28a9..9ba4ad32 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -3,12 +3,13 @@
 package PublicInbox::Config;
 use strict;
 use warnings;
+use File::Path::Expand qw/expand_filename/;
 
 # returns key-value pairs of config directives in a hash
 sub new {
         my ($class, $file) = @_;
 
-        local $ENV{GIT_CONFIG} = $file;
+        local $ENV{GIT_CONFIG} = defined $file ? $file : default_file();
 
         my @cfg = `git config -l`;
         $? == 0 or die "git config -l failed: $?\n";
@@ -37,4 +38,11 @@ sub lookup {
         \%rv;
 }
 
+sub default_file {
+        my $f = $ENV{PI_CONFIG};
+        return $f if defined $f;
+        my $pi_dir = $ENV{PI_DIR} || expand_filename('~/.public-inbox/');
+        "$pi_dir/config";
+}
+
 1;