tap/untap/update/prune: remove obsolete method, add migrate_taps

This commit is contained in:
Xu Cheng 2015-05-08 20:19:12 +08:00
parent e2b0bca931
commit 171c3dd2d9
4 changed files with 11 additions and 105 deletions

View File

@ -36,7 +36,7 @@ module Homebrew
end
end
repair_taps(false) unless ARGV.dry_run?
migrate_taps :force => true unless ARGV.dry_run?
if ObserverPathnameExtension.total.zero?
puts "Nothing pruned" if ARGV.verbose?

View File

@ -5,7 +5,7 @@ module Homebrew
puts "#{user.basename}/#{repo.basename.sub("homebrew-", "")}" if (repo/".git").directory?
end
elsif ARGV.first == "--repair"
repair_taps
migrate_taps :force => true
else
opoo "Already tapped!" unless install_tap(*tap_args)
end
@ -26,7 +26,6 @@ module Homebrew
files = []
tapd.find_formula { |file| files << file }
link_tap_formula(files)
puts "Tapped #{files.length} formula#{plural(files.length, 'e')} (#{tapd.abv})"
if private_tap?(repouser, repo) then puts <<-EOS.undent
@ -42,59 +41,12 @@ module Homebrew
true
end
def link_tap_formula(paths, warn_about_conflicts=true)
ignores = (HOMEBREW_LIBRARY/"Formula/.gitignore").read.split rescue []
tapped = 0
paths.each do |path|
to = HOMEBREW_LIBRARY.join("Formula", path.basename)
# Unexpected, but possible, lets proceed as if nothing happened
to.delete if to.symlink? && to.resolved_path == path
begin
to.make_relative_symlink(path)
rescue SystemCallError
to = to.resolved_path if to.symlink?
opoo <<-EOS.undent if warn_about_conflicts
Could not create link for #{Tty.white}#{tap_ref(path)}#{Tty.reset}, as it
conflicts with #{Tty.white}#{tap_ref(to)}#{Tty.reset}. You will need to use the
fully-qualified name when referring this formula, e.g.
brew install #{tap_ref(path)}
EOS
else
ignores << path.basename.to_s
tapped += 1
end
end
HOMEBREW_LIBRARY.join("Formula/.gitignore").atomic_write(ignores.uniq.join("\n"))
tapped
end
def repair_taps(warn_about_conflicts=true)
count = 0
# prune dead symlinks in Formula
Dir.glob("#{HOMEBREW_LIBRARY}/Formula/*.rb") do |fn|
if not File.exist? fn
File.delete fn
count += 1
end
end
puts "Pruned #{count} dead formula#{plural(count, 'e')}"
return unless HOMEBREW_REPOSITORY.join("Library/Taps").exist?
count = 0
# check symlinks are all set in each tap
each_tap do |user, repo|
files = []
repo.find_formula { |file| files << file }
count += link_tap_formula(files, warn_about_conflicts)
end
puts "Tapped #{count} formula#{plural(count, 'e')}"
# Migrate tapped formulae from symlink-based to directory-based structure.
def migrate_taps(options={})
ignore = HOMEBREW_LIBRARY/"Formula/.gitignore"
return unless ignore.exist? || options.fetch(:force, false)
(HOMEBREW_LIBRARY/"Formula").children.select(&:symlink?).each(&:unlink)
ignore.unlink if ignore.exist?
end
private
@ -124,13 +76,4 @@ module Homebrew
rescue GitHub::Error
false
end
def tap_ref(path)
case path.to_s
when %r{^#{Regexp.escape(HOMEBREW_LIBRARY.to_s)}/Formula}o
"Homebrew/homebrew/#{path.basename(".rb")}"
when HOMEBREW_TAP_PATH_REGEX
"#{$1}/#{$2.sub("homebrew-", "")}/#{path.basename(".rb")}"
end
end
end

View File

@ -21,29 +21,9 @@ module Homebrew
files = []
tapd.find_formula { |file| files << file }
unlink_tap_formula(files)
tapd.rmtree
tapd.dirname.rmdir_if_possible
puts "Untapped #{files.length} formula#{plural(files.length, 'e')}"
end
end
def unlink_tap_formula paths
untapped = 0
gitignores = (HOMEBREW_LIBRARY/"Formula/.gitignore").read.split rescue []
paths.each do |path|
link = HOMEBREW_LIBRARY.join("Formula", path.basename)
if link.symlink? && (!link.exist? || link.resolved_path == path)
link.delete
gitignores.delete(path.basename.to_s)
untapped += 1
end
end
HOMEBREW_REPOSITORY.join("Library/Formula/.gitignore").atomic_write(gitignores * "\n")
untapped
end
end

View File

@ -1,5 +1,4 @@
require 'cmd/tap'
require 'cmd/untap'
module Homebrew
def update
@ -16,20 +15,12 @@ module Homebrew
cd HOMEBREW_REPOSITORY
git_init_if_necessary
tapped_formulae = []
HOMEBREW_LIBRARY.join("Formula").children.each do |path|
next unless path.symlink?
tapped_formulae << path.resolved_path
end
unlink_tap_formula(tapped_formulae)
# migrate to new directories based tap structure
migrate_taps
report = Report.new
master_updater = Updater.new(HOMEBREW_REPOSITORY)
begin
master_updater.pull!
ensure
link_tap_formula(tapped_formulae)
end
master_updater.pull!
report.update(master_updater.report)
# rename Taps directories
@ -52,10 +43,6 @@ module Homebrew
end
end
# we unlink first in case the formula has moved to another tap
Homebrew.unlink_tap_formula(report.removed_tapped_formula)
Homebrew.link_tap_formula(report.new_tapped_formula)
# automatically tap any migrated formulae's new tap
report.select_formula(:D).each do |f|
next unless (HOMEBREW_CELLAR/f).exist?
@ -95,7 +82,6 @@ module Homebrew
end
def rename_taps_dir_if_necessary
need_repair_taps = false
Dir.glob("#{HOMEBREW_LIBRARY}/Taps/*/") do |tapd|
begin
tapd_basename = File.basename(tapd)
@ -107,7 +93,6 @@ module Homebrew
FileUtils.mkdir_p("#{HOMEBREW_LIBRARY}/Taps/#{user.downcase}")
FileUtils.mv(tapd, "#{HOMEBREW_LIBRARY}/Taps/#{user.downcase}/homebrew-#{repo.downcase}")
need_repair_taps = true
if tapd_basename.count("-") >= 2
opoo "Homebrew changed the structure of Taps like <someuser>/<sometap>. "\
@ -123,8 +108,6 @@ module Homebrew
next # next tap directory
end
end
repair_taps if need_repair_taps
end
def load_tap_migrations