TapLoader: improve load logic

* Use `Tap#formula_dir` instead of `Tap#formula_files` to find formula
  file to have better performance and avoid caching issue.
* Change the loader logic to search name -> search alias -> search old name.
  This is more consistence with what we do when loading core formula
  file.

Closes Homebrew/homebrew#49484.

Signed-off-by: Xu Cheng <xucheng@me.com>
This commit is contained in:
Xu Cheng 2016-02-24 20:06:33 +08:00
parent 6b6159a858
commit 6ac6cb4fcd

View File

@ -148,15 +148,17 @@ 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 @tap = Tap.fetch user, repo
name = @tap.formula_renames.fetch(name, name) formula_dir = @tap.formula_dir || @tap.path
path = @tap.formula_files.detect { |file| file.basename(".rb").to_s == name } path = formula_dir/"#{name}.rb"
unless path unless path.file?
if (possible_alias = @tap.alias_dir/name).file? if (possible_alias = @tap.alias_dir/name).file?
path = possible_alias.resolved_path path = possible_alias.resolved_path
name = path.basename(".rb").to_s name = path.basename(".rb").to_s
else elsif (new_name = @tap.formula_renames[name]) &&
path = @tap.path/"#{name}.rb" (new_path = formula_dir/"#{new_name}.rb").file?
path = new_path
name = new_name
end end
end end