From c787df52942dc8b47dc98b0cb23e2b00028885ab Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Tue, 15 Nov 2022 00:04:02 -0800 Subject: [PATCH] Optimize deleted_reason for all taps --- Library/Homebrew/missing_formula.rb | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/Library/Homebrew/missing_formula.rb b/Library/Homebrew/missing_formula.rb index e0b628460e..8cfc46e522 100644 --- a/Library/Homebrew/missing_formula.rb +++ b/Library/Homebrew/missing_formula.rb @@ -154,25 +154,17 @@ module Homebrew end end - # The core tap has thousands of monthly commits making the `git log` - # command below a performance issue when using `brew search` or - # `brew info` to look for a formula that doesn't exist. This first - # checks if the formula existed a month ago before continuing. - 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. + diff_command = ["git", "diff", "--diff-filter=D", "--name-only", + "@{'1 month ago'}", "--", relative_path] + deleted_formula = Utils.popen_read(*diff_command) - # Check if the formula has been deleted in the last month - # by comparing the diff between now and a month ago. - diff_command = "git diff --diff-filter=D --name-only " \ - "#{month_old_commit_hash} HEAD -- #{relative_path}" - - if Utils.popen_read(diff_command).blank? - ofail "No previously deleted formula found." unless silent - return - end + if deleted_formula.blank? + ofail "No previously deleted formula found." unless silent + return end + # Find commit where formula was deleted in the last month. log_command = "git log --since='1 month ago' --diff-filter=D " \ "--name-only --max-count=1 " \ "--format=%H\\\\n%h\\\\n%B -- #{relative_path}"