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