From 03faa33420391a8200ca786e0880e25eacd533d5 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Wed, 12 Sep 2007 10:04:15 +0000 Subject: create _choose_required() out of resolve_requested__no_suggests_() --- URPM/Resolve.pm | 77 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 34 deletions(-) (limited to 'URPM/Resolve.pm') 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; -- cgit v1.2.1