aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2008-07-03 11:22:38 +0000
committerPascal Rigaux <pixel@mandriva.com>2008-07-03 11:22:38 +0000
commit253ddfa8416e92b5e1da4497b102acfcf5d3ad2a (patch)
tree252cca279db8f33b1be1a28f31c3d44a41413ba3
parentc996c914bd341372a90ef251a9fe0bafe8ff7606 (diff)
downloadperl-URPM-253ddfa8416e92b5e1da4497b102acfcf5d3ad2a.tar
perl-URPM-253ddfa8416e92b5e1da4497b102acfcf5d3ad2a.tar.gz
perl-URPM-253ddfa8416e92b5e1da4497b102acfcf5d3ad2a.tar.bz2
perl-URPM-253ddfa8416e92b5e1da4497b102acfcf5d3ad2a.tar.xz
perl-URPM-253ddfa8416e92b5e1da4497b102acfcf5d3ad2a.zip
create packages_to_remove() and use it to factorize code
-rw-r--r--URPM/Resolve.pm23
1 files changed, 13 insertions, 10 deletions
diff --git a/URPM/Resolve.pm b/URPM/Resolve.pm
index 1f21c94..e989b68 100644
--- a/URPM/Resolve.pm
+++ b/URPM/Resolve.pm
@@ -7,6 +7,7 @@ package URPM;
use strict;
use Config;
+sub listlength { scalar @_ }
sub min { my $n = shift; $_ < $n and $n = $_ foreach @_; $n }
sub uniq { my %l; $l{$_} = 1 foreach @_; grep { delete $l{$_} } @_ }
sub find(&@) {
@@ -25,6 +26,13 @@ sub property2name_op_version {
$_[0] =~ /^([^\s\[]*)(?:\[\*\])?\s*\[?([^\s\]]*)\s*([^\s\]]*)/;
}
+sub packages_to_remove {
+ my ($state) = @_;
+ grep {
+ $state->{rejected}{$_}{removed} && !$state->{rejected}{$_}{obsoleted};
+ } keys %{$state->{rejected} || {}};
+}
+
#- Find candidates packages from a require string (or id).
#- Takes care of direct choices using the '|' separator.
#-
@@ -1822,9 +1830,7 @@ sub build_transaction_set {
);
my @upgrade = grep { ! exists $examined{$_} } keys %{$state->{transaction_state}{selected}};
- my @remove = grep { $state->{transaction_state}{rejected}{$_}{removed} &&
- !$state->{transaction_state}{rejected}{$_}{obsoleted} }
- grep { ! exists $examined{$_} } keys %{$state->{transaction_state}{rejected}};
+ my @remove = grep { ! exists $examined{$_} } packages_to_remove($state->{transaction_state});
@upgrade || @remove or next;
@@ -1846,16 +1852,14 @@ sub build_transaction_set {
#- check that the transaction set has been correctly created.
#- (ie that no other package was removed)
if (keys(%{$state->{selected}}) == keys(%{$state->{transaction_state}{selected}}) &&
- (grep { $state->{rejected}{$_}{removed} && !$state->{rejected}{$_}{obsoleted} } keys %{$state->{rejected}}) ==
- (grep { $state->{transaction_state}{rejected}{$_}{removed} && !$state->{transaction_state}{rejected}{$_}{obsoleted} }
- keys %{$state->{transaction_state}{rejected}})
- ) {
+ listlength(packages_to_remove($state)) == listlength(packages_to_remove($state->{transaction_state}))
+ ) {
foreach (keys(%{$state->{selected}})) {
exists $state->{transaction_state}{selected}{$_} and next;
$urpm->{error}('using one big transaction') if $urpm->{error};
$state->{transaction} = []; last;
}
- foreach (grep { $state->{rejected}{$_}{removed} && !$state->{rejected}{$_}{obsoleted} } keys %{$state->{rejected}}) {
+ foreach (packages_to_remove($state)) {
$state->{transaction_state}{rejected}{$_}{removed} &&
!$state->{transaction_state}{rejected}{$_}{obsoleted} and next;
$urpm->{error}('using one big transaction') if $urpm->{error};
@@ -1869,8 +1873,7 @@ sub build_transaction_set {
$urpm->{debug_URPM}('using one big transaction') if $urpm->{debug_URPM};
push @{$state->{transaction}}, {
upgrade => [ keys %{$state->{selected}} ],
- remove => [ grep { $state->{rejected}{$_}{removed} && !$state->{rejected}{$_}{obsoleted} }
- keys %{$state->{rejected}} ],
+ remove => [ packages_to_remove($state) ],
};
}