From 62b69765e06df6262ea2f82a94345cc5fc39b000 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Thu, 5 Jun 2025 03:31:21 -0400 Subject: [PATCH] Use newer internal api hash structure --- Library/Homebrew/api/internal.rb | 27 ++++++++++++++------------- Library/Homebrew/formula_stub.rb | 12 ++++++------ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Library/Homebrew/api/internal.rb b/Library/Homebrew/api/internal.rb index 0ddfbede9f..10ec2e4940 100644 --- a/Library/Homebrew/api/internal.rb +++ b/Library/Homebrew/api/internal.rb @@ -20,9 +20,14 @@ module Homebrew sig { params(name: String).returns(T::Hash[String, T.untyped]) } def self.formula(name) - tag = Utils::Bottles.tag - formula_stub = Homebrew::FormulaStub.from_array formula_stub(name) + return cache["formula_stubs"][name] if cache.key?("formula_stubs") && cache["formula_stubs"].key?(name) + stub_array = all_formula_stubs[name] + raise "No formula stub found for #{name}" unless stub_array + + formula_stub = Homebrew::FormulaStub.from_array name, stub_array + + tag = Utils::Bottles.tag bottle_specification = BottleSpecification.new bottle_specification.tap = Homebrew::DEFAULT_REPOSITORY bottle_specification.rebuild formula_stub.rebuild @@ -33,7 +38,10 @@ module Homebrew begin bottle_manifest_resource.fetch - bottle_manifest_resource.formula_json + formula_json = bottle_manifest_resource.formula_json + + cache["formula_stubs"][name] = formula_json + formula_json rescue Resource::BottleManifest::Error opoo "Falling back to API fetch for #{name}" Homebrew::API.fetch "formula/#{name}.json" @@ -54,18 +62,11 @@ module Homebrew end private_class_method :download_and_cache_data! - sig { params(name: String).returns([String, String, Integer, T.nilable(String)]) } - def self.formula_stub(name) + sig { returns(T::Hash[String, [String, Integer, T.nilable(String)]]) } + def self.all_formula_stubs download_and_cache_data! unless cache.key?("all_formula_stubs") - return cache["formula_stubs"][name] if cache["formula_stubs"].key?(name) - - cache["all_formula_stubs"].find do |stub| - next false if stub["name"] != name - - cache["formula_stubs"][name] = stub - true - end + cache["all_formula_stubs"] end end end diff --git a/Library/Homebrew/formula_stub.rb b/Library/Homebrew/formula_stub.rb index 15d975ca20..b64ddcea21 100644 --- a/Library/Homebrew/formula_stub.rb +++ b/Library/Homebrew/formula_stub.rb @@ -11,13 +11,13 @@ module Homebrew const :rebuild, Integer const :sha256, T.nilable(String) - sig { params(array: [String, String, Integer, T.nilable(String)]).returns(FormulaStub) } - def self.from_array(array) + sig { params(name: String, array: [String, Integer, T.nilable(String)]).returns(FormulaStub) } + def self.from_array(name, array) new( - name: array[0], - pkg_version: PkgVersion.parse(array[1]), - rebuild: array[2], - sha256: array[3], + name: name, + pkg_version: PkgVersion.parse(array[0]), + rebuild: array[1], + sha256: array[2], ) end end