Optimize deleted_reason for all taps

This commit is contained in:
apainintheneck 2022-11-15 00:04:02 -08:00
parent 2bc54e56e4
commit c787df5294

View File

@ -154,25 +154,17 @@ module Homebrew
end end
end end
# The core tap has thousands of monthly commits making the `git log` # Check if the formula has been deleted in the last month.
# command below a performance issue when using `brew search` or diff_command = ["git", "diff", "--diff-filter=D", "--name-only",
# `brew info` to look for a formula that doesn't exist. This first "@{'1 month ago'}", "--", relative_path]
# checks if the formula existed a month ago before continuing. deleted_formula = Utils.popen_read(*diff_command)
if tap.is_a? CoreTap
commit_command = "git log --before='1 month ago' --max-count=1 --format=%H"
month_old_commit_hash = Utils.popen_read(commit_command).chomp
# Check if the formula has been deleted in the last month if deleted_formula.blank?
# by comparing the diff between now and a month ago. ofail "No previously deleted formula found." unless silent
diff_command = "git diff --diff-filter=D --name-only " \ return
"#{month_old_commit_hash} HEAD -- #{relative_path}"
if Utils.popen_read(diff_command).blank?
ofail "No previously deleted formula found." unless silent
return
end
end end
# Find commit where formula was deleted in the last month.
log_command = "git log --since='1 month ago' --diff-filter=D " \ log_command = "git log --since='1 month ago' --diff-filter=D " \
"--name-only --max-count=1 " \ "--name-only --max-count=1 " \
"--format=%H\\\\n%h\\\\n%B -- #{relative_path}" "--format=%H\\\\n%h\\\\n%B -- #{relative_path}"