Skip to content

Commit

Permalink
show migrated from when loading packages from API
Browse files Browse the repository at this point in the history
This changes slightly how we load packaged migrated to core taps
when they are loaded using the API. Now it should show the warning
that the package has been migrated and renamed.
  • Loading branch information
apainintheneck committed Jun 29, 2024
1 parent 18d2373 commit 0c81a31
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
11 changes: 5 additions & 6 deletions Library/Homebrew/cask/cask_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,13 @@ def self.try_new(ref, warn: false)
return if Homebrew::EnvConfig.no_install_from_api?
return unless ref.is_a?(String)

token = parse_token(ref)
token ||= begin
ref = CoreCaskTap.instance.tap_migration_renames[ref]
parse_token(ref) if ref
ref = if (token = parse_token(ref))
"#{CoreCaskTap.instance}/#{token}"
else
CoreCaskTap.instance.tap_migration_oldnames_to_full_names[ref]
end
return unless token

ref = "#{CoreCaskTap.instance}/#{token}"
return unless ref

token, tap, = CaskLoader.tap_cask_token_type(ref, warn:)
new("#{tap}/#{token}")
Expand Down
16 changes: 8 additions & 8 deletions Library/Homebrew/formulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -918,23 +918,23 @@ def self.try_new(ref, from: T.unsafe(nil), warn: false)
return if Homebrew::EnvConfig.no_install_from_api?
return unless ref.is_a?(String)

name = parse_name(ref)
name ||= begin
ref = CoreTap.instance.tap_migration_renames[ref]
parse_name(ref) if ref
ref = if (name = parse_name(ref))
"#{CoreTap.instance}/#{name}"
else
name = ref.split("/").last
CoreTap.instance.tap_migration_oldnames_to_full_names[ref]
end
return unless name

alias_name = name
return unless ref

ref = "#{CoreTap.instance}/#{name}"
alias_name = name

return unless (name_tap_type = Formulary.tap_formula_name_type(ref, warn:))

name, tap, type = name_tap_type

options = if type == :alias
{ alias_name: alias_name.downcase }
{ alias_name: T.must(alias_name).downcase }
else
{}
end
Expand Down
24 changes: 13 additions & 11 deletions Library/Homebrew/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def clear_cache
@command_files = nil

@tap_migrations = nil
@tap_migration_renames = nil
@tap_migration_oldnames_to_full_names = nil
@reverse_tap_migrations_renames = nil

@audit_exceptions = nil
Expand Down Expand Up @@ -1285,15 +1285,16 @@ def tap_migrations
end
end

# External formula names to core formula renames
# Old formula names (that were migrated to homebrew/core) to old full names.
sig { returns(T::Hash[String, String]) }
def tap_migration_renames
@tap_migration_renames ||= Tap.each_with_object({}) do |tap, hash|
def tap_migration_oldnames_to_full_names
@tap_migration_oldnames_to_full_names ||= Tap.each_with_object({}) do |tap, hash|
tap.tap_migrations.each do |old_name, new_name|
next unless new_name.start_with?("homebrew/core/")

hash[old_name] = new_name
hash["#{tap}/#{old_name}"] = new_name
full_name = "#{tap}/#{old_name}"
hash[old_name] = full_name
hash[full_name] = full_name
end
end
end
Expand Down Expand Up @@ -1470,15 +1471,16 @@ def tap_migrations
end
end

# External cask names to core cask renames
# Old cask names (that were migrated to homebrew/cask) to old full names.
sig { returns(T::Hash[String, String]) }
def tap_migration_renames
@tap_migration_renames ||= Tap.each_with_object({}) do |tap, hash|
def tap_migration_oldnames_to_full_names
@tap_migration_oldnames_to_full_names ||= Tap.each_with_object({}) do |tap, hash|
tap.tap_migrations.each do |old_name, new_name|
next unless new_name.start_with?("homebrew/cask/")

hash[old_name] = new_name
hash["#{tap}/#{old_name}"] = new_name
full_name = "#{tap}/#{old_name}"
hash[old_name] = full_name
hash[full_name] = full_name
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/tap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ def setup_completion(link:)
JSON
end

describe "#reverse_tap_migration_renames" do
describe "#reverse_tap_migrations_renames" do
it "returns the expected hash" do
expect(homebrew_foo_tap.reverse_tap_migrations_renames).to eq({
"homebrew/cask/google-cloud-sdk" => %w[app-engine-go-32 app-engine-go-64],
Expand Down

0 comments on commit 0c81a31

Please sign in to comment.