aboutsummaryrefslogtreecommitdiffstats
path: root/URPM/Resolve.pm
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2007-09-12 10:04:15 +0000
committerPascal Rigaux <pixel@mandriva.com>2007-09-12 10:04:15 +0000
commit03faa33420391a8200ca786e0880e25eacd533d5 (patch)
tree1138ff87d2b70b9151f112d8d545c05f98c41e7a /URPM/Resolve.pm
parenta54bdc8addf8fd2fb0fe0b8743b2c269337a5d66 (diff)
downloadperl-URPM-03faa33420391a8200ca786e0880e25eacd533d5.tar
perl-URPM-03faa33420391a8200ca786e0880e25eacd533d5.tar.gz
perl-URPM-03faa33420391a8200ca786e0880e25eacd533d5.tar.bz2
perl-URPM-03faa33420391a8200ca786e0880e25eacd533d5.tar.xz
perl-URPM-03faa33420391a8200ca786e0880e25eacd533d5.zip
create _choose_required() out of resolve_requested__no_suggests_()
Diffstat (limited to 'URPM/Resolve.pm')
-rw-r--r--URPM/Resolve.pm77
1 files changed, 43 insertions, 34 deletions
diff --git a/URPM/Resolve.pm b/URPM/Resolve.pm
index efd2014..1768100 100644
--- a/URPM/Resolve.pm
+++ b/URPM/Resolve.pm
@@ -61,6 +61,48 @@ sub find_candidate_packages {
\%packages;
}
+#- side-effects: none
+sub _choose_required {
+ my ($urpm, $db, $state, $dep, $properties, %options) = @_;
+
+ #- take the best choice possible.
+ my ($chosen, $prefered) = find_required_package($urpm, $db, $state, $dep->{required});
+
+ #- If no choice is found, this means that nothing can be possibly selected
+ #- according to $dep, so we need to retry the selection, allowing all
+ #- packages that conflict or anything similar to see which strategy can be
+ #- tried. Backtracking is used to avoid trying multiple times the same
+ #- packages. If multiple packages are possible, simply ask the user which
+ #- one to choose; else take the first one available.
+ if (!@$chosen) {
+ $urpm->{debug_URPM}("no packages match " . _id_to_name($urpm, $dep->{required}) . " (it may be in skip.list)") if $urpm->{debug_URPM};
+ unshift @$properties, backtrack_selected($urpm, $db, $state, $dep, %options);
+ return; #- backtrack code choose to continue with same package or completely new strategy.
+ } elsif ($options{callback_choices} && @$chosen > 1) {
+ my @l = grep { ref $_ } $options{callback_choices}->($urpm, $db, $state, $chosen, _id_to_name($urpm, $dep->{required}), $prefered);
+ $urpm->{debug_URPM}("replacing " . _id_to_name($urpm, $dep->{required}) . " with " .
+ join(' ', map { $_->name } @l)) if $urpm->{debug_URPM};
+ unshift @$properties, map {
+ +{
+ required => $_->id,
+ choices => $dep->{required},
+ exists $dep->{from} ? (from => $dep->{from}) : @{[]},
+ exists $dep->{requested} ? (requested => $dep->{requested}) : @{[]},
+ };
+ } @l;
+ return; #- always redo according to choices.
+ }
+
+ #- now do the real work, select the package.
+ my $pkg = shift @$chosen;
+ if ($urpm->{debug_URPM} && $pkg->name ne _id_to_name($urpm, $dep->{required})) {
+ $urpm->{debug_URPM}("chosen " . $pkg->fullname . " for " . _id_to_name($urpm, $dep->{required}));
+ @$chosen and $urpm->{debug_URPM}(" (it could also have chosen " . join(' ', map { scalar $_->fullname } @$chosen));
+ }
+
+ $pkg;
+}
+
sub get_installed_arch {
my ($db, $n) = @_;
my $arch;
@@ -621,40 +663,7 @@ sub resolve_requested__no_suggests_ {
exists $state->{selected}{$dep->{from}->id} or next;
}
- #- take the best choice possible.
- my ($chosen, $prefered) = find_required_package($urpm, $db, $state, $dep->{required});
-
- #- If no choice is found, this means that nothing can be possibly selected
- #- according to $dep, so we need to retry the selection, allowing all
- #- packages that conflict or anything similar to see which strategy can be
- #- tried. Backtracking is used to avoid trying multiple times the same
- #- packages. If multiple packages are possible, simply ask the user which
- #- one to choose; else take the first one available.
- if (!@$chosen) {
- $urpm->{debug_URPM}("no packages match " . _id_to_name($urpm, $dep->{required}) . " (it may be in skip.list)") if $urpm->{debug_URPM};
- unshift @properties, backtrack_selected($urpm, $db, $state, $dep, %options);
- next; #- backtrack code choose to continue with same package or completely new strategy.
- } elsif ($options{callback_choices} && @$chosen > 1) {
- my @l = grep { ref $_ } $options{callback_choices}->($urpm, $db, $state, $chosen, _id_to_name($urpm, $dep->{required}), $prefered);
- $urpm->{debug_URPM}("replacing " . _id_to_name($urpm, $dep->{required}) . " with " .
- join(' ', map { $_->name } @l)) if $urpm->{debug_URPM};
- unshift @properties, map {
- +{
- required => $_->id,
- choices => $dep->{required},
- exists $dep->{from} ? (from => $dep->{from}) : @{[]},
- exists $dep->{requested} ? (requested => $dep->{requested}) : @{[]},
- };
- } @l;
- next; #- always redo according to choices.
- }
-
- #- now do the real work, select the package.
- my $pkg = shift @$chosen;
- if ($urpm->{debug_URPM} && $pkg->name ne _id_to_name($urpm, $dep->{required})) {
- $urpm->{debug_URPM}("chosen " . $pkg->fullname . " for " . _id_to_name($urpm, $dep->{required}));
- @$chosen and $urpm->{debug_URPM}(" (it could also have chosen " . join(' ', map { scalar $_->fullname } @$chosen));
- }
+ my $pkg = _choose_required($urpm, $db, $state, $dep, \@properties, %options) or next;
#- cancel flag if this package should be cancelled but too late (typically keep options).
my @keep;