]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Config.pm
config: ignore missing config files
[public-inbox.git] / lib / PublicInbox / Config.pm
index cead7fc287c1220b7af6905f2d04132d2c2a0a1f..2ff266f184499d2660f755ffc75e8be01d80f9d2 100644 (file)
@@ -32,7 +32,7 @@ sub new {
        $self->{-code_repos} ||= {}; # nick => PublicInbox::Git object
 
        if (my $no = delete $self->{'publicinbox.noobfuscate'}) {
-               $no = [ $no ] if ref($no) ne 'ARRAY';
+               $no = _array($no);
                my @domains;
                foreach my $n (@$no) {
                        my @n = split(/\s+/, $n);
@@ -90,13 +90,22 @@ sub lookup_name ($$) {
 
 sub each_inbox {
        my ($self, $cb) = @_;
-       my %seen;
-       foreach my $k (keys %$self) {
-               $k =~ m!\Apublicinbox\.([^/]+)\.mainrepo\z! or next;
-               next if $seen{$1};
-               $seen{$1} = 1;
-               my $ibx = lookup_name($self, $1) or next;
-               $cb->($ibx);
+       if (my $section_order = $self->{-section_order}) {
+               foreach my $section (@$section_order) {
+                       next if $section !~ m!\Apublicinbox\.([^/]+)\z!;
+                       $self->{"publicinbox.$1.mainrepo"} or next;
+                       my $ibx = lookup_name($self, $1) or next;
+                       $cb->($ibx);
+               }
+       } else {
+               my %seen;
+               foreach my $k (keys %$self) {
+                       $k =~ m!\Apublicinbox\.([^/]+)\.mainrepo\z! or next;
+                       next if $seen{$1};
+                       $seen{$1} = 1;
+                       my $ibx = lookup_name($self, $1) or next;
+                       $cb->($ibx);
+               }
        }
 }
 
@@ -137,7 +146,8 @@ sub default_file {
 
 sub git_config_dump {
        my ($file) = @_;
-       my ($in, $out);
+       my (%section_seen, @section_order);
+       return {} unless -e $file;
        my @cmd = (qw/git config/, "--file=$file", '-l');
        my $cmd = join(' ', @cmd);
        my $fh = popen_rd(\@cmd) or die "popen_rd failed for $file: $!\n";
@@ -146,8 +156,14 @@ sub git_config_dump {
        while (defined(my $line = <$fh>)) {
                chomp $line;
                my ($k, $v) = split(/=/, $line, 2);
-               my $cur = $rv{$k};
 
+               my ($section) = ($k =~ /\A(\S+)\.[^\.]+\z/);
+               unless (defined $section_seen{$section}) {
+                       $section_seen{$section} = 1;
+                       push @section_order, $section;
+               }
+
+               my $cur = $rv{$k};
                if (defined $cur) {
                        if (ref($cur) eq "ARRAY") {
                                push @$cur, $v;
@@ -159,6 +175,7 @@ sub git_config_dump {
                }
        }
        close $fh or die "failed to close ($cmd) pipe: $?";
+       $rv{-section_order} = \@section_order;
 
        \%rv;
 }