For cross-inbox Message-ID resolution; having some sort of
stable ordering makes the most sense. Relying on the
order of the config file seems most natural and allows us
to avoid introducing yet another configuration knob.
sub each_inbox {
my ($self, $cb) = @_;
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);
+ }
sub git_config_dump {
my ($file) = @_;
sub git_config_dump {
my ($file) = @_;
+ my (%section_seen, @section_order);
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";
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";
while (defined(my $line = <$fh>)) {
chomp $line;
my ($k, $v) = split(/=/, $line, 2);
while (defined(my $line = <$fh>)) {
chomp $line;
my ($k, $v) = split(/=/, $line, 2);
+ 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;
if (defined $cur) {
if (ref($cur) eq "ARRAY") {
push @$cur, $v;
}
}
close $fh or die "failed to close ($cmd) pipe: $?";
}
}
close $fh or die "failed to close ($cmd) pipe: $?";
+ $rv{-section_order} = \@section_order;
ok(PublicInbox::Config::valid_inbox_name($s), "$d name accepted");
}
ok(PublicInbox::Config::valid_inbox_name($s), "$d name accepted");
}
+{
+ my $f = "$tmpdir/ordered";
+ open my $fh, '>', $f or die "open: $!";
+ my @expect;
+ foreach my $i (0..3) {
+ push @expect, "$i";
+ print $fh <<"" or die "print: $!";
+[publicinbox "$i"]
+ mainrepo = /path/to/$i.git
+ address = $i\@example.com
+
+ }
+ close $fh or die "close: $!";
+ my $cfg = PublicInbox::Config->new($f);
+ my @result;
+ $cfg->each_inbox(sub { push @result, $_[0]->{name} });
+ is_deeply(\@result, \@expect);
+}
+