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
10 my ($class, $file) = @_;
12 local $ENV{GIT_CONFIG} = defined $file ? $file : default_file();
14 my @cfg = `git config -l`;
15 $? == 0 or die "git config -l failed: $?\n";
17 my %rv = map { split(/=/, $_, 2) } @cfg;
22 my ($self, $recipient) = @_;
23 my $addr = lc($recipient);
26 foreach my $k (keys %$self) {
27 $k =~ /\A(publicinbox\.[A-Z0-9a-z-]+)\.address\z/ or next;
28 (lc($self->{$k}) eq $addr) or next;
33 defined $pfx or return;
36 $_ => $self->{"$pfx.$_"}
37 } (qw(mainrepo description address));
39 $listname =~ s/\Apublicinbox\.//;
40 $rv{listname} = $listname;
45 my ($self, $listname, $key) = @_;
47 $self->{"publicinbox.$listname.$key"};
51 my $f = $ENV{PI_CONFIG};
52 return $f if defined $f;
53 my $pi_dir = $ENV{PI_DIR} || expand_filename('~/.public-inbox/');