Support formula renames in API

This commit is contained in:
Bo Anderson 2023-04-27 04:09:41 +01:00
parent a696bd8203
commit 5510c3fb2b
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65
2 changed files with 17 additions and 1 deletions

View File

@ -25,10 +25,14 @@ module Homebrew
target: HOMEBREW_CACHE_API/"formula.jws.json"
cache["aliases"] = {}
cache["renames"] = {}
cache["formulae"] = json_formulae.to_h do |json_formula|
json_formula["aliases"].each do |alias_name|
cache["aliases"][alias_name] = json_formula["name"]
end
(json_formula["oldnames"] || [json_formula["oldname"]].compact).each do |oldname|
cache["renames"][oldname] = json_formula["name"]
end
[json_formula["name"], json_formula.except("name")]
end
@ -57,6 +61,16 @@ module Homebrew
cache["aliases"]
end
sig { returns(Hash) }
def all_renames
unless cache.key?("renames")
json_updated = download_and_cache_data!
write_names_and_aliases(regenerate: json_updated)
end
cache["renames"]
end
sig { params(regenerate: T::Boolean).void }
def write_names_and_aliases(regenerate: false)
download_and_cache_data! unless cache.key?("formulae")

View File

@ -933,9 +933,11 @@ class CoreTap < Tap
# @private
sig { returns(Hash) }
def formula_renames
@formula_renames ||= begin
@formula_renames ||= if Homebrew::EnvConfig.no_install_from_api?
self.class.ensure_installed!
super
else
Homebrew::API::Formula.all_renames
end
end