Streamline some unique sorting repetitions with a function. Patch from Andres Salomon

git-svn-id: http://emdebian.org/svn/current@8350 563faec7-e20c-0410-992a-a66f704d0ccd
This commit is contained in:
codehelp 2012-04-29 15:51:07 +00:00
parent feda7a9f68
commit 4f6125c225
2 changed files with 25 additions and 45 deletions

4
debian/changelog vendored
View file

@ -5,8 +5,10 @@ multistrap (2.1.20) experimental; urgency=low
(Closes: #670402) (Closes: #670402)
* Add an update-alternatives helper. * Add an update-alternatives helper.
* [INTL:de] updated German translation (Closes: #670835) * [INTL:de] updated German translation (Closes: #670835)
* Streamline some unique sorting repetitions with a function. Patch
from Andres Salomon
-- Neil Williams <codehelp@debian.org> Sun, 29 Apr 2012 14:47:57 +0100 -- Neil Williams <codehelp@debian.org> Sun, 29 Apr 2012 15:22:42 +0100
multistrap (2.1.19) experimental; urgency=low multistrap (2.1.19) experimental; urgency=low

View file

@ -32,7 +32,7 @@ use vars qw/ $progname $ourversion $dstrap $extra @aptsources
$repo @dirs @touch %sources $section %keys $host $key $value $preffile $repo @dirs @touch %sources $section %keys $host $key $value $preffile
$type $file $config $tidy $noauth $keyring %keyrings $deflist $cfgdir $type $file $config $tidy $noauth $keyring %keyrings $deflist $cfgdir
@extrapkgs @includes %source $setupsh $configsh $omitrequired $dryrun @extrapkgs @includes %source $setupsh $configsh $omitrequired $dryrun
$omitpreinst @reinstall $tgzname %uniq %required $check @check %uniq $omitpreinst @reinstall $tgzname %required $check @check
$explicit_suite $allow_recommends %omitdebsrc @dsclist @sectoutput $explicit_suite $allow_recommends %omitdebsrc @dsclist @sectoutput
%flatfile %important $addimportant @debconf $hookdir %hooks %flatfile %important $addimportant @debconf $hookdir %hooks
$warn_count $use_shortcut @foreignarches $olddpkg $ignorenative $warn_count $use_shortcut @foreignarches $olddpkg $ignorenative
@ -117,16 +117,8 @@ if (defined $omitrequired and defined $addimportant) {
} }
exit (7); exit (7);
} }
%uniq=(); uniq_sort (\@debootstrap);
foreach my $line (@debootstrap) { uniq_sort (\@aptsources);
$uniq{$line}++;
}
@debootstrap=sort keys %uniq;
%uniq=();
foreach my $line (@aptsources) {
$uniq{$line}++;
}
@aptsources=sort keys %uniq;
if (defined $dryrun) { if (defined $dryrun) {
&dump_config; &dump_config;
exit 0; exit 0;
@ -397,12 +389,9 @@ foreach my $keystr (values %keyrings) {
$str .= " " . $keystr . " "; $str .= " " . $keystr . " ";
} }
chomp($str); chomp($str);
%uniq=();
@s = split (/ /, $str); @s = split (/ /, $str);
foreach my $a (@s) { uniq_sort (\@s);
$uniq{$a}++; $str = join (' ', @s);
}
$str = join (' ', sort keys %uniq);
print "apt-get -y $config_str install $str\n"; print "apt-get -y $config_str install $str\n";
$retval = 0; $retval = 0;
$retval = system ("apt-get -y $config_str install $str"); $retval = system ("apt-get -y $config_str install $str");
@ -869,15 +858,12 @@ sub handle_source_packages {
} }
} }
} }
my %uniqdsc=(); uniq_sort (\@dsclist);
foreach my $a (@dsclist) {
$uniqdsc{$a}++;
}
my $olddir = getcwd(); my $olddir = getcwd();
chdir ($sourcedir); chdir ($sourcedir);
if (scalar keys %uniqdsc > 0) { if (scalar @dsclist > 0) {
print "apt-get -d $config_str source " . join (" ", sort keys %uniqdsc) . "\n"; print "apt-get -d $config_str source " . join (" ", @dsclist) . "\n";
foreach my $srcpkg (sort keys %uniqdsc) { foreach my $srcpkg (@dsclist) {
system ("apt-get -d $config_str source $srcpkg"); system ("apt-get -d $config_str source $srcpkg");
} }
} }
@ -1284,17 +1270,8 @@ sub cascade {
die ("\n"); die ("\n");
} }
} }
my %uniq=(); uniq_sort (\@reinstall);
foreach my $listing (@reinstall) { uniq_sort (\@extrapkgs);
$uniq{$listing}++;
}
@reinstall=();
@reinstall=sort keys %uniq;
%uniq=();
foreach my $x (@extrapkgs) {
$uniq{$x}++;
}
@extrapkgs = keys %uniq;
} }
# returns zero on success, non-zero on fail # returns zero on success, non-zero on fail
@ -1328,6 +1305,15 @@ sub _g {
return gettext(shift); return gettext(shift);
} }
sub uniq_sort {
my $aryref = shift;
my %uniq = ();
foreach my $i (@$aryref) {
$uniq{$i}++;
}
@$aryref = sort keys %uniq;
}
sub dump_config { sub dump_config {
if (not defined $dir or not defined $arch) { if (not defined $dir or not defined $arch) {
my $msg = sprintf(_g("The supplied configuration file '%s'". my $msg = sprintf(_g("The supplied configuration file '%s'".
@ -1336,12 +1322,9 @@ sub dump_config {
} }
my $plural; my $plural;
@check=(); @check=();
%uniq=();
push @check, @debootstrap; push @check, @debootstrap;
push @check, @aptsources; push @check, @aptsources;
foreach my $sect (@check) { $uniq{$sect}++; } uniq_sort (\@check);
@check = sort keys %uniq;
%uniq=();
foreach my $sect (@check) { foreach my $sect (@check) {
if (not exists $keys{$sect}) { if (not exists $keys{$sect}) {
$msg .= sprintf (_g("ERR: The '%s' section is not defined.\n"), $sect); $msg .= sprintf (_g("ERR: The '%s' section is not defined.\n"), $sect);
@ -1363,12 +1346,7 @@ sub dump_config {
printf ("Section name:\t$sect_name\n"); printf ("Section name:\t$sect_name\n");
print "\tsource:\t\t$sources{$sect_name}\n"; print "\tsource:\t\t$sources{$sect_name}\n";
my @sorted = split(/ /, $packages{$sect_name}); my @sorted = split(/ /, $packages{$sect_name});
%uniq=(); uniq_sort (\@sorted);
foreach my $pkg (@sorted) {
$uniq{$pkg}++;
}
@sorted = sort keys %uniq;
%uniq=();
print "\tsuite:\t\t$suites{$sect_name}\n" if (not exists $flatfile{$sect_name}); print "\tsuite:\t\t$suites{$sect_name}\n" if (not exists $flatfile{$sect_name});
print "\tcomponents:\t$components{$sect_name}\n" if (not exists $flatfile{$sect_name}); print "\tcomponents:\t$components{$sect_name}\n" if (not exists $flatfile{$sect_name});
# only list packages in a bootstrapping section # only list packages in a bootstrapping section