From 5da857ce834323983a52411fd36192d4253090f0 Mon Sep 17 00:00:00 2001 From: Zhiming Wang Date: Wed, 22 Mar 2017 00:28:01 -0400 Subject: missing_formula: warn when git-log takes very long --- Library/Homebrew/missing_formula.rb | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/missing_formula.rb b/Library/Homebrew/missing_formula.rb index ba09f7426..8defa86ab 100644 --- a/Library/Homebrew/missing_formula.rb +++ b/Library/Homebrew/missing_formula.rb @@ -125,11 +125,23 @@ module Homebrew relative_path = path.relative_path_from tap.path tap.path.cd do - # 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) + begin + timer_pid = fork do + # Let the user know what's going on when the search goes on for + # more than two seconds. + sleep 2 + opoo "Searching through git history. This may take a while..." + end + + # 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) + ensure + Process.kill "TERM", timer_pid + end + if hash.to_s.empty? || short_hash.to_s.empty? || relative_path.to_s.empty? return -- cgit v1.2.3 From d0bbadde222e0930d411c14fbfa14393db797e4c Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 22 Mar 2017 21:54:56 +0000 Subject: github: don't print when searching PRs. --- Library/Homebrew/utils/github.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 5f961974c..a5ed5394a 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -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") -- cgit v1.2.3 From e55f3a0cc58cd37f28791d19d200d4e3b6bb11be Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 22 Mar 2017 21:55:22 +0000 Subject: info: immediately print FormulaUnavailableError. --- Library/Homebrew/cmd/info.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 7e1815556..e7ad6821d 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -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 -- cgit v1.2.3 From c458ffbd241340e97a60ca0d90e8094bbb45df69 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 22 Mar 2017 21:55:29 +0000 Subject: install: immediately print FormulaUnavailableError. --- Library/Homebrew/cmd/install.rb | 73 +++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index bd7897171..e54286f09 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -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 - - 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 + 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 -- cgit v1.2.3 From 4c2fe5d91ea8802584473ab1d05d04b3ec86ae72 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 22 Mar 2017 21:56:15 +0000 Subject: missing_formula: print immediately when searching git log. --- Library/Homebrew/missing_formula.rb | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/Library/Homebrew/missing_formula.rb b/Library/Homebrew/missing_formula.rb index 8defa86ab..9c1656aa2 100644 --- a/Library/Homebrew/missing_formula.rb +++ b/Library/Homebrew/missing_formula.rb @@ -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,25 +126,17 @@ module Homebrew relative_path = path.relative_path_from tap.path tap.path.cd do - begin - timer_pid = fork do - # Let the user know what's going on when the search goes on for - # more than two seconds. - sleep 2 - opoo "Searching through git history. This may take a while..." - end - - # 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) - ensure - Process.kill "TERM", timer_pid - end + 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 -- cgit v1.2.3 From 35a4836dc363a69f19fa202deef6ae7a9a2b4440 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 22 Mar 2017 21:56:30 +0000 Subject: search: silence searching git log. --- Library/Homebrew/cmd/search.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index db5898872..443739f8c 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -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:" -- cgit v1.2.3