centralize the logic of handling homebrew-
in Tap.fetch
Closes Homebrew/homebrew#46537. Signed-off-by: Xu Cheng <xucheng@me.com>
This commit is contained in:
parent
9755662e49
commit
48950f2cc0
@ -69,7 +69,7 @@ module Homebrew
|
||||
def github_info(f)
|
||||
if f.tap?
|
||||
user, repo = f.tap.split("/", 2)
|
||||
tap = Tap.fetch user, repo.gsub(/^homebrew-/, "")
|
||||
tap = Tap.fetch user, repo
|
||||
if remote = tap.remote
|
||||
path = f.path.relative_path_from(tap.path)
|
||||
github_remote_path(remote, path)
|
||||
|
@ -16,9 +16,7 @@ module Homebrew
|
||||
ARGV.named.each do |name|
|
||||
if !File.exist?(name) && (name !~ HOMEBREW_CORE_FORMULA_REGEX) \
|
||||
&& (name =~ HOMEBREW_TAP_FORMULA_REGEX || name =~ HOMEBREW_CASK_TAP_FORMULA_REGEX)
|
||||
user = $1
|
||||
repo = $2.sub(/^homebrew-/, "")
|
||||
tap = Tap.fetch(user, repo)
|
||||
tap = Tap.fetch($1, $2)
|
||||
tap.install unless tap.installed?
|
||||
end
|
||||
end unless ARGV.force?
|
||||
|
@ -403,10 +403,8 @@ class Report
|
||||
fetch(:D, []).each do |path|
|
||||
case path.to_s
|
||||
when HOMEBREW_TAP_PATH_REGEX
|
||||
user = $1
|
||||
repo = $2.sub("homebrew-", "")
|
||||
oldname = path.basename(".rb").to_s
|
||||
next unless newname = Tap.fetch(user, repo).formula_renames[oldname]
|
||||
next unless newname = Tap.fetch($1, $2).formula_renames[oldname]
|
||||
else
|
||||
oldname = path.basename(".rb").to_s
|
||||
next unless newname = FORMULA_RENAMES[oldname]
|
||||
@ -427,7 +425,7 @@ class Report
|
||||
def select_formula(key)
|
||||
fetch(key, []).map do |path, newpath|
|
||||
if path.to_s =~ HOMEBREW_TAP_PATH_REGEX
|
||||
tap = "#{$1}/#{$2.sub("homebrew-", "")}"
|
||||
tap = Tap.fetch($1, $2)
|
||||
if newpath
|
||||
["#{tap}/#{path.basename(".rb")}", "#{tap}/#{newpath.basename(".rb")}"]
|
||||
else
|
||||
|
@ -76,7 +76,7 @@ class TapFormulaAmbiguityError < RuntimeError
|
||||
@paths = paths
|
||||
@formulae = paths.map do |path|
|
||||
path.to_s =~ HOMEBREW_TAP_PATH_REGEX
|
||||
"#{$1}/#{$2.sub("homebrew-", "")}/#{path.basename(".rb")}"
|
||||
"#{Tap.fetch($1, $2)}/#{path.basename(".rb")}"
|
||||
end
|
||||
|
||||
super <<-EOS.undent
|
||||
|
@ -134,7 +134,7 @@ class Formula
|
||||
@revision = self.class.revision || 0
|
||||
|
||||
if path.to_s =~ HOMEBREW_TAP_PATH_REGEX
|
||||
@full_name = "#{$1}/#{$2.gsub(/^homebrew-/, "")}/#{name}"
|
||||
@full_name = "#{Tap.fetch($1, $2)}/#{name}"
|
||||
else
|
||||
@full_name = name
|
||||
end
|
||||
@ -296,7 +296,7 @@ class Formula
|
||||
end
|
||||
elsif tap?
|
||||
user, repo = tap.split("/")
|
||||
formula_renames = Tap.fetch(user, repo.sub("homebrew-", "")).formula_renames
|
||||
formula_renames = Tap.fetch(user, repo).formula_renames
|
||||
if formula_renames.value?(name)
|
||||
formula_renames.to_a.rassoc(name).first
|
||||
end
|
||||
@ -309,7 +309,7 @@ class Formula
|
||||
Formula.core_alias_reverse_table[name] || []
|
||||
elsif tap?
|
||||
user, repo = tap.split("/")
|
||||
Tap.fetch(user, repo.sub("homebrew-", "")).alias_reverse_table[full_name] || []
|
||||
Tap.fetch(user, repo).alias_reverse_table[full_name] || []
|
||||
else
|
||||
[]
|
||||
end
|
||||
|
@ -145,7 +145,7 @@ class Formulary
|
||||
|
||||
def initialize(tapped_name)
|
||||
user, repo, name = tapped_name.split("/", 3).map(&:downcase)
|
||||
@tap = Tap.fetch user, repo.sub(/^homebrew-/, "")
|
||||
@tap = Tap.fetch user, repo
|
||||
name = @tap.formula_renames.fetch(name, name)
|
||||
path = @tap.formula_files.detect { |file| file.basename(".rb").to_s == name }
|
||||
|
||||
|
@ -31,9 +31,7 @@ class Migrator
|
||||
msg = if tap == "Homebrew/homebrew"
|
||||
"Please try to use #{formula.oldname} to refer the formula.\n"
|
||||
elsif tap
|
||||
user, repo = tap.split("/")
|
||||
repo.sub!("homebrew-", "")
|
||||
"Please try to use fully-qualified #{user}/#{repo}/#{formula.oldname} to refer the formula.\n"
|
||||
"Please try to use fully-qualified #{Tap.fetch(*tap.split("/"))}/#{formula.oldname} to refer the formula.\n"
|
||||
end
|
||||
|
||||
super <<-EOS.undent
|
||||
|
@ -17,6 +17,9 @@ class Tap
|
||||
end
|
||||
|
||||
def self.fetch(user, repo)
|
||||
# we special case homebrew so users don't have to shift in a terminal
|
||||
user = "Homebrew" if user == "homebrew"
|
||||
repo = repo.strip_prefix "homebrew-"
|
||||
cache_key = "#{user}/#{repo}".downcase
|
||||
CACHE.fetch(cache_key) { |key| CACHE[key] = Tap.new(user, repo) }
|
||||
end
|
||||
@ -39,9 +42,9 @@ class Tap
|
||||
# e.g. `/usr/local/Library/Taps/user/homebrew-repo`
|
||||
attr_reader :path
|
||||
|
||||
# @private
|
||||
def initialize(user, repo)
|
||||
# we special case homebrew so users don't have to shift in a terminal
|
||||
@user = user == "homebrew" ? "Homebrew" : user
|
||||
@user = user
|
||||
@repo = repo
|
||||
@name = "#{@user}/#{@repo}".downcase
|
||||
@path = TAP_DIRECTORY/"#{@user}/homebrew-#{@repo}".downcase
|
||||
@ -268,7 +271,7 @@ class Tap
|
||||
|
||||
TAP_DIRECTORY.subdirs.each do |user|
|
||||
user.subdirs.each do |repo|
|
||||
yield fetch(user.basename.to_s, repo.basename.to_s.sub("homebrew-", ""))
|
||||
yield fetch(user.basename.to_s, repo.basename.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user