diff options
author | Peter Palfrader <peter@palfrader.org> | 2021-05-24 11:23:28 +0200 |
---|---|---|
committer | Laura Arjona Reina <larjona@debian.org> | 2021-06-04 12:59:14 +0000 |
commit | a5752729f894f3bbd06c03a92de42ba51b471916 (patch) | |
tree | 78cdf2c25fb8c1b3814abf2b22cf97bec1a95568 /english/mirror | |
parent | ff5e54356eede6d74127390997ff4fa954aba73e (diff) |
mirror/mirror_list: Sort all mirrors by their name everywhere
Diffstat (limited to 'english/mirror')
-rwxr-xr-x | english/mirror/mirror_list.pl | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/english/mirror/mirror_list.pl b/english/mirror/mirror_list.pl index d73b8cd0dc4..c011cf370e5 100755 --- a/english/mirror/mirror_list.pl +++ b/english/mirror/mirror_list.pl @@ -34,13 +34,31 @@ $mirror_source = 'Mirrors.masterlist' if (! defined $mirror_source); my $last_modify = gmtime((stat($mirror_source))[9]); -my (@mirror, %countries, %countries_sorted, %countries_sponsors, %longest); +my (@mirror, %countries, %countries_sponsors, %longest); my ($count, $cdimagecount); my (%code_of_country, %plain_name_of_country); my %includedsites; my $globalsite; +sub cmpbydomain { + my $sitea = $mirror[$a]{site}; + my $siteb = $mirror[$b]{site}; + + my @a = map(scalar reverse, split(/\./, (scalar reverse $sitea))); + my @b = map(scalar reverse, split(/\./, (scalar reverse $siteb))); + while (1) { + if ((scalar @a == 0) || (scalar @b == 0)) { + return ((scalar @a) <=> (scalar @b)); + } + my $ca = shift @a; + my $cb = shift @b; + my $cmp = $ca cmp $cb; + return $cmp if ($cmp != 0); + } + return 0; +} + sub process_line { my ($lno, $line) = @_; my $field = ''; @@ -194,7 +212,7 @@ END print "-" x length($country); # underline print "\n"; } - foreach my $id (@{ $countries_sorted{$country} }) { + foreach my $id (@{ $countries{$country} }) { next unless defined $mirror[$id]{method}{'archive-http'}; my $aliaslist; if (exists $mirror[$id]{'aliases'}) { @@ -495,7 +513,7 @@ END END } foreach my $country (sort keys %countries) { - foreach my $id (sort @{ $countries{$country} }) { + foreach my $id (@{ $countries{$country} }) { next unless ($mirror[$id]{site} =~ /$officialsiteregex/); my $countryplain = $plain_name_of_country{$country}; @@ -565,7 +583,7 @@ sub primary_mirror_sponsors { <tr><td colspan="3"><hr></td></tr> END foreach my $country (sort keys %countries) { - foreach my $id (sort @{ $countries{$country} }) { + foreach my $id (@{ $countries{$country} }) { next unless ($mirror[$id]{site} =~ /$officialsiteregex/); my $countrycode = $code_of_country{$country}; print <<END; @@ -657,7 +675,7 @@ sub mirror_sponsors { END foreach my $country (sort keys %countries) { next unless $countries_sponsors{$country}; - foreach my $id (sort @{ $countries_sponsors{$country} }) { + foreach my $id (@{ $countries_sponsors{$country} }) { # sites which have Includes don't have to have Sponsor, the included ones # have it; and those are looped over separately anyway, so no need to repeat next if (exists $mirror[$id]{includes}); @@ -712,7 +730,7 @@ sub cdimage_mirrors($) { die unless $which; print "#use wml::debian::languages\n\n<perl>\nmy \@cdmirrors = (\n"; foreach my $country (sort keys %countries) { - foreach my $id (sort @{ $countries{$country} }) { + foreach my $id (@{ $countries{$country} }) { my $countrycode = $code_of_country{$country}; if ($which eq "httpftp") { if (defined $mirror[$id]{method}{'cdimage-ftp'} || @@ -841,7 +859,7 @@ EOF print "\n"; } print "\n"; - foreach my $id (@{ $countries_sorted{$country} }) { + foreach my $id (@{ $countries{$country} }) { next unless keys %{$mirror[$id]{'method'}}; print "Site: "; print "<tt>" if $wml; @@ -927,7 +945,7 @@ sub compact_list($$) { next unless (keys %our_mirrors); my $countryplain = $plain_name_of_country{$country}; my $countrycode = $code_of_country{$country}; - foreach my $id (@{ $countries_sorted{$country} }) { + foreach my $id (@{ $countries{$country} }) { next unless (exists $our_mirrors{$id}); print "<li><".$countrycode."c>: " . $mirror[$id]{site} . ": "; printhtmlftprsync($mirror[$id]{site}, @@ -1010,7 +1028,7 @@ sub generate_html_matrix { } next unless (keys %our_mirrors); print "<tr class=\"country\"><th colspan=\"5\">$country</th></tr>\n"; - foreach my $id (@{ $countries_sorted{$country} }) { + foreach my $id (@{ $countries{$country} }) { next unless (exists $our_mirrors{$id}); print "<tr><th>$mirror[$id]{site}</th>"; print "<td>"; @@ -1120,7 +1138,7 @@ foreach my $id (0..$#mirror) { # Sort the country info arrays to first list the official sites, # then the unofficial sites, but exclude special Debian sites foreach my $country (sort keys %countries) { - my %countries_sorted_o; my %countries_sorted_u; + my (%countries_sorted_o, %countries_sorted_u); foreach my $id (@{ $countries{$country} }) { if ($mirror[$id]{site} =~ /$officialsiteregex/) { push @{ $countries_sorted_o{$country} }, $id; @@ -1133,15 +1151,8 @@ foreach my $country (sort keys %countries) { } } # merge the reordered lists into %countries_sorted - # (there's got to be a cleaner way to do this, but hey) - foreach my $id (@{ $countries_sorted_o{$country} }) { - push @{ $countries_sorted{$country} }, $id; - } - undef %countries_sorted_o; - foreach my $id (@{ $countries_sorted_u{$country} }) { - push @{ $countries_sorted{$country} }, $id; - } - undef %countries_sorted_u; + @{ $countries{$country} } = (sort cmpbydomain @{ $countries_sorted_o{$country} }, + sort cmpbydomain @{ $countries_sorted_u{$country} }); } if ($output_type eq 'html') { |