From 94f2098c36181fd296846e40363582c432d5e8cc Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 29 Mar 2018 22:05:02 +0200 Subject: [PATCH] Only use `HOMEBREW_TAP_PATH_REGEX` once inside `Tap` class. --- Library/Homebrew/cask/lib/hbc/cask_loader.rb | 8 ++++---- Library/Homebrew/exceptions.rb | 3 +-- Library/Homebrew/formula.rb | 4 ++-- Library/Homebrew/tap.rb | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cask_loader.rb b/Library/Homebrew/cask/lib/hbc/cask_loader.rb index 450aa13ba6..1ac85af5fa 100644 --- a/Library/Homebrew/cask/lib/hbc/cask_loader.rb +++ b/Library/Homebrew/cask/lib/hbc/cask_loader.rb @@ -97,14 +97,14 @@ module Hbc class FromTapPathLoader < FromPathLoader def self.can_load?(ref) - File.expand_path(ref).match?(HOMEBREW_TAP_PATH_REGEX) && super + super && !Tap.from_path(ref).nil? end attr_reader :tap - def initialize(tap_path) - @tap = Tap.from_path(File.expand_path(tap_path)) - super tap_path + def initialize(path) + @tap = Tap.from_path(path) + super(path) end private diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 20ad2a3788..b3acf821ec 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -181,8 +181,7 @@ class TapFormulaAmbiguityError < RuntimeError @name = name @paths = paths @formulae = paths.map do |path| - match = path.to_s.match(HOMEBREW_TAP_PATH_REGEX) - "#{Tap.fetch(match[:user], match[:repo])}/#{path.basename(".rb")}" + "#{Tap.from_path(path).name}/#{path.basename(".rb")}" end super <<~EOS diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 305a6398af..9078557890 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -179,8 +179,8 @@ class Formula @tap = if path == Formulary.core_path(name) CoreTap.instance - elsif match = path.to_s.match(HOMEBREW_TAP_PATH_REGEX) - Tap.fetch(match[:user], match[:repo]) + else + Tap.from_path(path) end @full_name = full_name_with_optional_tap(name) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 7b19977fda..e13b9af754 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -39,7 +39,7 @@ class Tap end def self.from_path(path) - match = path.to_s.match(HOMEBREW_TAP_PATH_REGEX) + match = File.expand_path(path).match(HOMEBREW_TAP_PATH_REGEX) raise "Invalid tap path '#{path}'" unless match fetch(match[:user], match[:repo]) rescue