ruby-changes:70042
From: David <ko1@a...>
Date: Fri, 3 Dec 2021 20:01:12 +0900 (JST)
Subject: [ruby-changes:70042] 4c5e862434 (master): [rubygems/rubygems] Improve source gemfile/lockfile equivalence checks
https://git.ruby-lang.org/ruby.git/commit/?id=4c5e862434 From 4c5e862434157c4ef258f432431262b3685c4036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...> Date: Wed, 17 Nov 2021 15:14:30 +0100 Subject: [rubygems/rubygems] Improve source gemfile/lockfile equivalence checks Since we no longer have multiple global sources, each top level dependency is always pinned to a single source, so it makes little sense to talk about adding or removing a source. Instead, source changes always mean to change the source one or more dependencies are pinned to. This logic can now be much simpler. https://github.com/rubygems/rubygems/commit/f1d33fa0df --- lib/bundler/definition.rb | 30 ++++++++++-------------------- spec/bundler/install/deploy_spec.rb | 10 +++++----- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 0c29cdc62f8..2ac05d606f9 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -371,35 +371,25 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/definition.rb#L371 added.concat new_platforms.map {|p| "* platform: #{p}" } deleted.concat deleted_platforms.map {|p| "* platform: #{p}" } - gemfile_sources = sources.lock_sources - - new_sources = gemfile_sources - @locked_sources - deleted_sources = @locked_sources - gemfile_sources - new_deps = @dependencies - locked_dependencies deleted_deps = locked_dependencies - @dependencies - if @locked_sources != gemfile_sources - if new_sources.any? - added.concat new_sources.map {|source| "* source: #{source}" } - end - - if deleted_sources.any? - deleted.concat deleted_sources.map {|source| "* source: #{source}" } - end - end - added.concat new_deps.map {|d| "* #{pretty_dep(d)}" } if new_deps.any? deleted.concat deleted_deps.map {|d| "* #{pretty_dep(d)}" } if deleted_deps.any? both_sources = Hash.new {|h, k| h[k] = [] } @dependencies.each {|d| both_sources[d.name][0] = d } - locked_dependencies.each {|d| both_sources[d.name][1] = d.source } + locked_dependencies.each {|d| both_sources[d.name][1] = d } + + both_sources.each do |name, (dep, lock_dep)| + next if dep.nil? || lock_dep.nil? + + gemfile_source = dep.source || sources.default_source + lock_source = lock_dep.source || sources.default_source + next if lock_source.include?(gemfile_source) - both_sources.each do |name, (dep, lock_source)| - next if lock_source.nil? || lock_source.can_lock?(dep) - gemfile_source_name = dep.source || "no specified source" - lockfile_source_name = lock_source + gemfile_source_name = dep.source ? gemfile_source.identifier : "no specified source" + lockfile_source_name = lock_dep.source ? lock_source.identifier : "no specified source" changed << "* #{name} from `#{lockfile_source_name}` to `#{gemfile_source_name}`" end diff --git a/spec/bundler/install/deploy_spec.rb b/spec/bundler/install/deploy_spec.rb index e2ca96993fb..54fc6371cb0 100644 --- a/spec/bundler/install/deploy_spec.rb +++ b/spec/bundler/install/deploy_spec.rb @@ -357,11 +357,11 @@ RSpec.describe "install in deployment or frozen mode" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/install/deploy_spec.rb#L357 bundle "config set --local deployment true" bundle :install, :raise_on_error => false expect(err).to include("deployment mode") - expect(err).to include("You have added to the Gemfile:\n* source: git://hubz.com") - expect(err).not_to include("You have changed in the Gemfile") + expect(err).not_to include("You have added to the Gemfile") + expect(err).to include("You have changed in the Gemfile:\n* rack from `no specified source` to `git://hubz.com`") end - it "explodes if you unpin a source" do + it "explodes if you change a source" do build_git "rack" install_gemfile <<-G @@ -377,12 +377,12 @@ RSpec.describe "install in deployment or frozen mode" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/install/deploy_spec.rb#L377 bundle "config set --local deployment true" bundle :install, :raise_on_error => false expect(err).to include("deployment mode") - expect(err).to include("You have deleted from the Gemfile:\n* source: #{lib_path("rack-1.0")}") + expect(err).not_to include("You have deleted from the Gemfile") expect(err).not_to include("You have added to the Gemfile") expect(err).to include("You have changed in the Gemfile:\n* rack from `#{lib_path("rack-1.0")}` to `no specified source`") end - it "explodes if you unpin a source, leaving it pinned somewhere else" do + it "explodes if you change a source" do build_lib "foo", :path => lib_path("rack/foo") build_git "rack", :path => lib_path("rack") -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/