lib/rubygems/resolver.rb in rubygems-update-2.6.14 vs lib/rubygems/resolver.rb in rubygems-update-2.7.0

- old
+ new

@@ -228,12 +228,32 @@ @missing << dependency exc = Gem::UnsatisfiableDependencyError.new dependency, all exc.errors = @set.errors raise exc end - possibles.sort_by { |s| [s.source, s.version, Gem::Platform.local =~ s.platform ? 1 : 0] }. - map { |s| ActivationRequest.new s, dependency, [] } + + sources = [] + + groups = Hash.new { |hash, key| hash[key] = [] } + + # create groups & sources in the same loop + sources = possibles.map { |spec| + source = spec.source + groups[source] << spec + source + }.uniq.reverse + + activation_requests = [] + + sources.each do |source| + groups[source]. + sort_by { |spec| [spec.version, Gem::Platform.local =~ spec.platform ? 1 : 0] }. + map { |spec| ActivationRequest.new spec, dependency, [] }. + each { |activation_request| activation_requests << activation_request } + end + + activation_requests end def dependencies_for(specification) return [] if @ignore_dependencies spec = specification.spec @@ -252,16 +272,17 @@ @missing << dependency @soft_missing end def sort_dependencies(dependencies, activated, conflicts) - dependencies.sort_by do |dependency| + dependencies.sort_by.with_index do |dependency, i| name = name_for(dependency) [ activated.vertex_named(name).payload ? 0 : 1, amount_constrained(dependency), conflicts[name] ? 0 : 1, activated.vertex_named(name).payload ? 0 : search_for(dependency).count, + i # for stable sort ] end end SINGLE_POSSIBILITY_CONSTRAINT_PENALTY = 1_000_000