Skip to content

Commit

Permalink
update-report: default HOMEBREW_UPDATE_REPORT_ONLY_INSTALLED to on.
Browse files Browse the repository at this point in the history
This avoids reading formula files that the user hasn't explicitly
installed which both speeds up `brew update` and improves the security.
  • Loading branch information
MikeMcQuaid committed Feb 22, 2022
1 parent 6661f5b commit 4dc7652
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 72 deletions.
74 changes: 8 additions & 66 deletions Library/Homebrew/cmd/update-report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,6 @@ def report(preinstall: false)

if paths.any? { |p| tap.cask_file?(p) }
case status
when "A"
# Have a dedicated report array for new casks.
@report[:AC] << tap.formula_file_to_name(src)
when "D"
# Have a dedicated report array for deleted casks.
@report[:DC] << tap.formula_file_to_name(src)
Expand All @@ -346,11 +343,11 @@ def report(preinstall: false)
next unless paths.any? { |p| tap.formula_file?(p) }

case status
when "A", "D"
when "D"
full_name = tap.formula_file_to_name(src)
name = full_name.split("/").last
new_tap = tap.tap_migrations[name]
@report[status.to_sym] << full_name unless new_tap
@report[:D] << full_name unless new_tap
when "M"
name = tap.formula_file_to_name(src)

Expand Down Expand Up @@ -380,45 +377,9 @@ def report(preinstall: false)
next if src_full_name == dst_full_name

@report[:D] << src_full_name
@report[:A] << dst_full_name
end
end

renamed_formulae = Set.new
@report[:D].each do |old_full_name|
old_name = old_full_name.split("/").last
new_name = tap.formula_renames[old_name]
next unless new_name

new_full_name = if tap.core_tap?
new_name
else
"#{tap}/#{new_name}"
end

renamed_formulae << [old_full_name, new_full_name] if @report[:A].include? new_full_name
end

@report[:A].each do |new_full_name|
new_name = new_full_name.split("/").last
old_name = tap.formula_renames.key(new_name)
next unless old_name

old_full_name = if tap.core_tap?
old_name
else
"#{tap}/#{old_name}"
end

renamed_formulae << [old_full_name, new_full_name]
end

unless renamed_formulae.empty?
@report[:A] -= renamed_formulae.map(&:last)
@report[:D] -= renamed_formulae.map(&:first)
@report[:R] = renamed_formulae.to_a
end

@report
end

Expand Down Expand Up @@ -571,16 +532,13 @@ def add(reporter, preinstall: false)
def dump(updated_formula_report: true)
# Key Legend: Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R)

dump_formula_report :A, "New Formulae"
if updated_formula_report
dump_formula_report :M, "Updated Formulae"
else
updated = select_formula(:M).count
ohai "Updated Formulae", "Updated #{updated} #{"formula".pluralize(updated)}." if updated.positive?
end
dump_formula_report :R, "Renamed Formulae"
dump_formula_report :D, "Deleted Formulae"
dump_formula_report :AC, "New Casks"
if updated_formula_report
dump_formula_report :MC, "Updated Casks"
else
Expand All @@ -593,33 +551,17 @@ def dump(updated_formula_report: true)
private

def dump_formula_report(key, title)
# TODO: 3.4.0: odisabled the old functionality and make this default
only_installed = Homebrew::EnvConfig.update_report_only_installed?
if ENV["HOMEBREW_UPDATE_REPORT_ONLY_INSTALLED"]
opoo "HOMEBREW_UPDATE_REPORT_ONLY_INSTALLED can be unset, it is now the default!"
end

formulae = select_formula(key).sort.map do |name, new_name|
# Format list items of renamed formulae
case key
when :R
name = pretty_installed(name) if installed?(name)
new_name = pretty_installed(new_name) if installed?(new_name)
"#{name} -> #{new_name}" unless only_installed
when :A
name if !installed?(name) && !only_installed
when :AC
name.split("/").last if !cask_installed?(name) && !only_installed
when :MC, :DC
name = name.split("/").last
if cask_installed?(name)
pretty_installed(name)
elsif !only_installed
name
end
else
if installed?(name)
pretty_installed(name)
elsif !only_installed
name
end
pretty_installed(name) if cask_installed?(name)
when :M, :D
pretty_installed(name) if installed?(name)
end
end.compact

Expand Down
4 changes: 0 additions & 4 deletions Library/Homebrew/env_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,6 @@ module EnvConfig
default_text: "macOS: `/private/tmp`, Linux: `/tmp`.",
default: HOMEBREW_DEFAULT_TEMP,
},
HOMEBREW_UPDATE_REPORT_ONLY_INSTALLED: {
description: "If set, `brew update` only lists updates to installed software.",
boolean: true,
},
HOMEBREW_UPDATE_TO_TAG: {
description: "If set, always use the latest stable tag (even if developer commands " \
"have been run).",
Expand Down
2 changes: 0 additions & 2 deletions Library/Homebrew/sorbet/rbi/hidden-definitions/hidden.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -2626,8 +2626,6 @@ module Homebrew::EnvConfig

def self.temp(); end

def self.update_report_only_installed?(); end

def self.update_to_tag?(); end

def self.verbose?(); end
Expand Down

0 comments on commit 4dc7652

Please sign in to comment.