From 3a5acfbc133c994905bee470ad2e715af9a3d30c Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Wed, 16 Aug 2023 11:54:18 +0200 Subject: [PATCH 1/3] executables_db: avoid `Formula#all` Instead, collect all formulae from their taps, then load them explicitly via `Formulary`. This should fix #133. --- lib/executables_db.rb | 61 ++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/lib/executables_db.rb b/lib/executables_db.rb index b92c0dae..6dd17230 100644 --- a/lib/executables_db.rb +++ b/lib/executables_db.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true require "formula" +require "formulary" +require "tap" module Homebrew # ExecutablesDB represents a DB associating formulae to the binaries they @@ -54,40 +56,45 @@ def changed? def update!(update_existing: false, install_missing: false, max_downloads: nil) downloads = 0 disabled_formulae = [] - Formula.all.each do |f| - break if max_downloads.present? && downloads > max_downloads.to_i - next if f.tap? - name = f.full_name + Tap.each do |tap| + tap.formula_files_by_name.each do |name, path| + f = Formulary.load_formula_from_path(name, path) - if f.disabled? - disabled_formulae << name - next - end + break if max_downloads.present? && downloads > max_downloads.to_i + next if f.tap? - update_formula = missing_formula?(f) || (update_existing && outdated_formula?(f)) + name = f.full_name - # Install unbottled formulae if they should be added/updated - if !f.bottled? && install_missing && update_formula - downloads += 1 - ohai "Installing #{f}" - system HOMEBREW_BREW_FILE, "install", "--formula", f.to_s - end + if f.disabled? + disabled_formulae << name + next + end - # We don't need to worry about updating outdated versions unless update_existing is true - if f.latest_version_installed? - update_installed_formula f - elsif f.bottled? && update_formula - downloads += 1 - update_bottled_formula f - end + update_formula = missing_formula?(f) || (update_existing && outdated_formula?(f)) + + # Install unbottled formulae if they should be added/updated + if !f.bottled? && install_missing && update_formula + downloads += 1 + ohai "Installing #{f}" + system HOMEBREW_BREW_FILE, "install", "--formula", f.to_s + end + + # We don't need to worry about updating outdated versions unless update_existing is true + if f.latest_version_installed? + update_installed_formula f + elsif f.bottled? && update_formula + downloads += 1 + update_bottled_formula f + end - # renamed formulae - mv f.oldname, name if !f.oldname.nil? && @exes[f.oldname] + # renamed formulae + mv f.oldname, name if !f.oldname.nil? && @exes[f.oldname] - # aliased formulae - f.aliases.each do |a| - mv a, name if @exes[a] + # aliased formulae + f.aliases.each do |a| + mv a, name if @exes[a] + end end end From 656af5ed40011a5d2d47cb1c4a42481344d1204b Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Sun, 22 Oct 2023 15:07:01 -0400 Subject: [PATCH 2/3] add --eval-all, only eval core by default Signed-off-by: William Woodruff --- cmd/which-update.rb | 5 ++++- lib/executables_db.rb | 4 +++- lib/which_update.rb | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/which-update.rb b/cmd/which-update.rb index 52935e96..9afd5775 100755 --- a/cmd/which-update.rb +++ b/cmd/which-update.rb @@ -20,6 +20,8 @@ def which_update_args description: "Update database entries with outdated formula versions." switch "--install-missing", description: "Install and update formulae that are missing from the database and don't have bottles." + switch "--eval-all", + description: "Evaluate all installed taps, rather than just the core tap." flag "--max-downloads=", description: "Specify a maximum number of formulae to download and update." conflicts "--stats", "--commit" @@ -39,7 +41,8 @@ def which_update Homebrew::WhichUpdate.update_and_save! source: args.named.first, commit: args.commit?, update_existing: args.update_existing?, install_missing: args.install_missing?, - max_downloads: args.max_downloads + max_downloads: args.max_downloads, + eval_all: args.eval_all? end end end diff --git a/lib/executables_db.rb b/lib/executables_db.rb index 6dd17230..04f0c1a0 100644 --- a/lib/executables_db.rb +++ b/lib/executables_db.rb @@ -53,10 +53,12 @@ def changed? # update the DB with the installed formulae # @see #save! - def update!(update_existing: false, install_missing: false, max_downloads: nil) + def update!(update_existing: false, install_missing: false, max_downloads: nil, eval_all: false) downloads = 0 disabled_formulae = [] + # Evaluate only the core tap by default. + taps = eval_all ? Tap.each.to_a : [CoreTap.instance] Tap.each do |tap| tap.formula_files_by_name.each do |name, path| f = Formulary.load_formula_from_path(name, path) diff --git a/lib/which_update.rb b/lib/which_update.rb index e8a6b1ce..b6237db3 100755 --- a/lib/which_update.rb +++ b/lib/which_update.rb @@ -45,10 +45,10 @@ def stats(source: nil) end def update_and_save!(source: nil, commit: false, update_existing: false, install_missing: false, - max_downloads: nil) + max_downloads: nil, eval_all: false) source ||= default_source db = ExecutablesDB.new source - db.update!(update_existing: update_existing, install_missing: install_missing, max_downloads: max_downloads) + db.update!(update_existing: update_existing, install_missing: install_missing, max_downloads: max_downloads, eval_all: eval_all) db.save! return if !commit || !db.changed? From a565eb7c5ee29d25f91a98959b06cfa25bed2e91 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Sun, 22 Oct 2023 15:10:23 -0400 Subject: [PATCH 3/3] lintage Signed-off-by: William Woodruff --- lib/executables_db.rb | 2 +- lib/which_update.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/executables_db.rb b/lib/executables_db.rb index 04f0c1a0..464748a2 100644 --- a/lib/executables_db.rb +++ b/lib/executables_db.rb @@ -59,7 +59,7 @@ def update!(update_existing: false, install_missing: false, max_downloads: nil, # Evaluate only the core tap by default. taps = eval_all ? Tap.each.to_a : [CoreTap.instance] - Tap.each do |tap| + taps.each do |tap| tap.formula_files_by_name.each do |name, path| f = Formulary.load_formula_from_path(name, path) diff --git a/lib/which_update.rb b/lib/which_update.rb index b6237db3..23593fbd 100755 --- a/lib/which_update.rb +++ b/lib/which_update.rb @@ -48,7 +48,8 @@ def update_and_save!(source: nil, commit: false, update_existing: false, install max_downloads: nil, eval_all: false) source ||= default_source db = ExecutablesDB.new source - db.update!(update_existing: update_existing, install_missing: install_missing, max_downloads: max_downloads, eval_all: eval_all) + db.update!(update_existing: update_existing, install_missing: install_missing, + max_downloads: max_downloads, eval_all: eval_all) db.save! return if !commit || !db.changed?