Merge pull request #2377 from zmwangx/warn-on-slow-missing-formula-search

missing_formula: warn when git-log takes very long
This commit is contained in:
Mike McQuaid 2017-03-23 09:51:41 +00:00 committed by GitHub
commit 53bcec7679
5 changed files with 49 additions and 43 deletions

View File

@ -55,11 +55,10 @@ module Homebrew
info_formula Formulary.find_with_priority(f)
end
rescue FormulaUnavailableError => e
ofail e.message
# No formula with this name, try a missing formula lookup
if (reason = Homebrew::MissingFormula.reason(f))
ofail "#{e.message}\n#{reason}"
else
ofail e.message
$stderr.puts reason
end
end
end

View File

@ -206,44 +206,47 @@ module Homebrew
# formula was found, but there's a problem with its implementation).
ofail e.message
rescue FormulaUnavailableError => e
if (reason = Homebrew::MissingFormula.reason(e.name))
ofail "#{e.message}\n#{reason}"
elsif e.name == "updog"
if e.name == "updog"
ofail "What's updog?"
return
end
ofail e.message
if (reason = Homebrew::MissingFormula.reason(e.name))
$stderr.puts reason
return
end
query = query_regexp(e.name)
ohai "Searching for similarly named formulae..."
formulae_search_results = search_formulae(query)
case formulae_search_results.length
when 0
ofail "No similarly named formulae found."
when 1
puts "This similarly named formula was found:"
puts formulae_search_results
puts "To install it, run:\n brew install #{formulae_search_results.first}"
else
ofail e.message
puts "These similarly named formulae were found:"
puts Formatter.columns(formulae_search_results)
puts "To install one of them, run (for example):\n brew install #{formulae_search_results.first}"
end
query = query_regexp(e.name)
ohai "Searching for similarly named formulae..."
formulae_search_results = search_formulae(query)
case formulae_search_results.length
when 0
ofail "No similarly named formulae found."
when 1
puts "This similarly named formula was found:"
puts formulae_search_results
puts "To install it, run:\n brew install #{formulae_search_results.first}"
else
puts "These similarly named formulae were found:"
puts Formatter.columns(formulae_search_results)
puts "To install one of them, run (for example):\n brew install #{formulae_search_results.first}"
end
ohai "Searching taps..."
taps_search_results = search_taps(query)
case taps_search_results.length
when 0
ofail "No formulae found in taps."
when 1
puts "This formula was found in a tap:"
puts taps_search_results
puts "To install it, run:\n brew install #{taps_search_results.first}"
else
puts "These formulae were found in taps:"
puts Formatter.columns(taps_search_results)
puts "To install one of them, run (for example):\n brew install #{taps_search_results.first}"
end
ohai "Searching taps..."
taps_search_results = search_taps(query)
case taps_search_results.length
when 0
ofail "No formulae found in taps."
when 1
puts "This formula was found in a tap:"
puts taps_search_results
puts "To install it, run:\n brew install #{taps_search_results.first}"
else
puts "These formulae were found in taps:"
puts Formatter.columns(taps_search_results)
puts "To install one of them, run (for example):\n brew install #{taps_search_results.first}"
end
end
end

View File

@ -67,7 +67,7 @@ module Homebrew
if $stdout.tty?
count = local_results.length + tap_results.length
if reason = Homebrew::MissingFormula.reason(query)
if reason = Homebrew::MissingFormula.reason(query, silent: true)
if count > 0
puts
puts "If you meant #{query.inspect} specifically:"

View File

@ -5,8 +5,9 @@ require "utils"
module Homebrew
module MissingFormula
class << self
def reason(name)
blacklisted_reason(name) || tap_migration_reason(name) || deleted_reason(name)
def reason(name, silent: false)
blacklisted_reason(name) || tap_migration_reason(name) ||
deleted_reason(name, silent: silent)
end
def blacklisted_reason(name)
@ -117,7 +118,7 @@ module Homebrew
message
end
def deleted_reason(name)
def deleted_reason(name, silent: false)
path = Formulary.path name
return if File.exist? path
tap = Tap.from_path(path)
@ -125,13 +126,17 @@ module Homebrew
relative_path = path.relative_path_from tap.path
tap.path.cd do
ohai "Searching for a previously deleted formula..." unless silent
# We know this may return incomplete results for shallow clones but
# we don't want to nag everyone with a shallow clone to unshallow it.
log_command = "git log --name-only --max-count=1 --format=%H\\\\n%h\\\\n%B -- #{relative_path}"
hash, short_hash, *commit_message, relative_path =
Utils.popen_read(log_command).gsub("\\n", "\n").lines.map(&:chomp)
if hash.to_s.empty? || short_hash.to_s.empty? ||
relative_path.to_s.empty?
ofail "No previously deleted formula found." unless silent
return
end

View File

@ -268,7 +268,6 @@ module GitHub
def print_pull_requests_matching(query)
return [] if ENV["HOMEBREW_NO_GITHUB_API"]
ohai "Searching pull requests..."
open_or_closed_prs = issues_matching(query, type: "pr")