update: add formula renames to report

This commit is contained in:
Vlad Shablinsky 2015-08-17 21:49:55 +03:00 committed by Xu Cheng
parent 896848dd87
commit e4480cf6bf

View File

@ -62,27 +62,18 @@ module Homebrew
tabs.each(&:write) tabs.each(&:write)
end if load_tap_migrations end if load_tap_migrations
# Migrate installed renamed formulae from main Homebrew repository. load_formula_renames
if load_formula_renames report.update_renamed
report.select_formula(:D).each do |oldname|
newname = FORMULA_RENAMES[oldname]
next unless newname
next unless (dir = HOMEBREW_CELLAR/oldname).directory? && !dir.subdirs.empty?
begin # Migrate installed renamed formulae from core and taps.
migrator = Migrator.new(Formulary.factory("homebrew/homebrew/#{newname}")) report.select_formula(:R).each do |oldname, newname|
migrator.migrate if oldname.include?("/")
rescue Migrator::MigratorDifferentTapsError
end
end
end
# Migrate installed renamed formulae from taps
report.select_formula(:D).each do |oldname|
user, repo, oldname = oldname.split("/", 3) user, repo, oldname = oldname.split("/", 3)
next unless user && repo && oldname newname = newname.split("/", 3).last
tap = Tap.new(user, repo) else
next unless newname = tap.formula_renames[oldname] user, repo = "homebrew", "homebrew"
end
next unless (dir = HOMEBREW_CELLAR/oldname).directory? && !dir.subdirs.empty? next unless (dir = HOMEBREW_CELLAR/oldname).directory? && !dir.subdirs.empty?
begin begin
@ -322,14 +313,45 @@ class Report
dump_formula_report :A, "New Formulae" dump_formula_report :A, "New Formulae"
dump_formula_report :M, "Updated Formulae" dump_formula_report :M, "Updated Formulae"
dump_formula_report :R, "Renamed Formulae"
dump_formula_report :D, "Deleted Formulae" dump_formula_report :D, "Deleted Formulae"
end end
def select_formula(key) def update_renamed
fetch(key, []).map do |path| @hash[:R] ||= []
fetch(:D, []).each do |path|
case path.to_s case path.to_s
when HOMEBREW_TAP_PATH_REGEX when HOMEBREW_TAP_PATH_REGEX
"#{$1}/#{$2.sub("homebrew-", "")}/#{path.basename(".rb")}" user = $1
repo = $2.sub("homebrew-", "")
oldname = path.basename(".rb").to_s
next unless newname = Tap.new(user, repo).formula_renames[oldname]
else
oldname = path.basename(".rb").to_s
next unless newname = FORMULA_RENAMES[oldname]
end
if fetch(:A, []).include?(newpath = path.dirname.join("#{newname}.rb"))
@hash[:R] << [path, newpath]
end
end
@hash[:A] -= @hash[:R].map(&:last) if @hash[:A]
@hash[:D] -= @hash[:R].map(&:first) if @hash[:D]
end
def select_formula(key)
fetch(key, []).map do |path, newpath|
if path.to_s =~ HOMEBREW_TAP_PATH_REGEX
tap = "#{$1}/#{$2.sub("homebrew-", "")}"
if newpath
["#{tap}/#{path.basename(".rb")}", "#{tap}/#{newpath.basename(".rb")}"]
else
"#{tap}/#{path.basename(".rb")}"
end
elsif newpath
["#{path.basename(".rb")}", "#{newpath.basename(".rb")}"]
else else
path.basename(".rb").to_s path.basename(".rb").to_s
end end
@ -338,6 +360,7 @@ class Report
def dump_formula_report(key, title) def dump_formula_report(key, title)
formula = select_formula(key) formula = select_formula(key)
formula.map! { |oldname, newname| "#{oldname} -> #{newname}" } if key == :R
unless formula.empty? unless formula.empty?
ohai title ohai title
puts_columns formula puts_columns formula