1 # Copyright (C) 2014, Eric Wong <normalperson@yhbt.net> and all contributors
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
3 package PublicInbox::Config;
6 use File::Path::Expand qw/expand_filename/;
8 # returns key-value pairs of config directives in a hash
9 # if keys may be multi-value, the value is an array ref containing all values
11 my ($class, $file) = @_;
13 local $ENV{GIT_CONFIG} = defined $file ? $file : default_file();
15 my @cfg = `git config -l`;
16 $? == 0 or die "git config -l failed: $?\n";
19 foreach my $line (@cfg) {
20 my ($k, $v) = split(/=/, $line, 2);
24 if (ref($cur) eq "ARRAY") {
27 $rv{$k} = [ $cur, $v ];
37 my ($self, $recipient) = @_;
38 my $addr = lc($recipient);
41 foreach my $k (keys %$self) {
42 $k =~ /\A(publicinbox\.[A-Z0-9a-z-]+)\.address\z/ or next;
44 if (ref($v) eq "ARRAY") {
45 foreach my $alias (@$v) {
46 (lc($alias) eq $addr) or next;
51 (lc($v) eq $addr) or next;
57 defined $pfx or return;
60 foreach my $k (qw(mainrepo address)) {
61 my $v = $self->{"$pfx.$k"};
62 $rv{$k} = $v if defined $v;
65 $listname =~ s/\Apublicinbox\.//;
66 $rv{listname} = $listname;
68 $rv{-primary_address} = ref($v) eq 'ARRAY' ? $v->[0] : $v;
73 my ($self, $listname, $key) = @_;
75 $self->{"publicinbox.$listname.$key"};
79 my $f = $ENV{PI_CONFIG};
80 return $f if defined $f;
81 my $pi_dir = $ENV{PI_DIR} || expand_filename('~/.public-inbox/');