2010-10-27 10:03:30 +02:00
|
|
|
require 'formula'
|
|
|
|
|
|
|
|
module Homebrew extend self
|
2011-08-02 12:30:04 +01:00
|
|
|
def versions
|
2012-05-07 20:32:04 -05:00
|
|
|
raise "Please `brew install git` first" unless which "git"
|
2012-03-16 00:35:49 +00:00
|
|
|
raise "Please `brew update' first" unless (HOMEBREW_REPOSITORY/".git").directory?
|
2010-10-27 10:03:30 +02:00
|
|
|
|
2012-02-04 00:01:29 -06:00
|
|
|
raise FormulaUnspecifiedError if ARGV.named.empty?
|
|
|
|
|
2013-11-12 17:32:05 +00:00
|
|
|
opoo <<-EOS.undent
|
|
|
|
brew-versions is unsupported and may be removed soon.
|
|
|
|
Please use the homebrew-versions tap instead:
|
|
|
|
https://github.com/Homebrew/homebrew-versions
|
|
|
|
EOS
|
2011-08-02 12:30:04 +01:00
|
|
|
ARGV.formulae.all? do |f|
|
2012-01-06 14:35:48 -06:00
|
|
|
if ARGV.include? '--compact'
|
|
|
|
puts f.versions * " "
|
|
|
|
else
|
|
|
|
f.versions do |version, sha|
|
2011-12-04 00:05:32 -05:00
|
|
|
print Tty.white.to_s
|
2012-07-10 16:01:02 -05:00
|
|
|
print "#{version.to_s.ljust(8)} "
|
2011-12-04 00:05:32 -05:00
|
|
|
print Tty.reset.to_s
|
2012-01-06 14:35:48 -06:00
|
|
|
puts "git checkout #{sha} #{f.pretty_relative_path}"
|
|
|
|
end
|
2010-10-27 10:03:30 +02:00
|
|
|
end
|
|
|
|
end
|
2011-08-02 12:30:04 +01:00
|
|
|
end
|
|
|
|
end
|
2010-10-27 10:03:30 +02:00
|
|
|
|
|
|
|
|
2011-08-02 12:30:04 +01:00
|
|
|
class Formula
|
2012-01-05 16:15:33 -06:00
|
|
|
def versions
|
|
|
|
versions = []
|
2013-12-17 20:43:45 -06:00
|
|
|
rev_list do |sha|
|
2012-01-05 16:15:33 -06:00
|
|
|
version = version_for_sha sha
|
|
|
|
unless versions.include? version or version.nil?
|
|
|
|
yield version, sha if block_given?
|
|
|
|
versions << version
|
|
|
|
end
|
2010-10-27 10:03:30 +02:00
|
|
|
end
|
2012-01-05 16:15:33 -06:00
|
|
|
return versions
|
2010-10-27 10:03:30 +02:00
|
|
|
end
|
|
|
|
|
2013-12-10 15:16:22 -06:00
|
|
|
def bottle_version_map branch='HEAD'
|
|
|
|
map = Hash.new { |h, k| h[k] = [] }
|
2013-12-17 20:43:45 -06:00
|
|
|
rev_list(branch) do |rev|
|
2013-12-10 15:16:22 -06:00
|
|
|
formula_for_sha(rev) do |f|
|
2014-03-10 14:56:02 -05:00
|
|
|
bottle = f.stable.bottle_specification
|
2013-12-10 15:16:22 -06:00
|
|
|
unless bottle.checksums.empty?
|
2014-03-10 14:56:02 -05:00
|
|
|
map[f.pkg_version] << bottle.revision
|
2013-10-28 10:26:04 +00:00
|
|
|
end
|
|
|
|
end
|
2013-09-21 15:15:07 +01:00
|
|
|
end
|
2013-12-10 15:16:22 -06:00
|
|
|
map
|
2013-09-21 15:15:07 +01:00
|
|
|
end
|
|
|
|
|
2012-01-05 16:15:33 -06:00
|
|
|
def pretty_relative_path
|
2013-04-09 11:01:58 +08:00
|
|
|
if Pathname.pwd == repository
|
|
|
|
entry_name
|
2012-01-05 16:15:33 -06:00
|
|
|
else
|
2013-04-09 11:01:58 +08:00
|
|
|
repository/"#{entry_name}"
|
2012-01-05 16:15:33 -06:00
|
|
|
end
|
2011-08-02 12:30:04 +01:00
|
|
|
end
|
2010-10-27 10:03:30 +02:00
|
|
|
|
2012-01-05 16:15:33 -06:00
|
|
|
private
|
2013-04-09 11:01:58 +08:00
|
|
|
def repository
|
|
|
|
@repository ||= begin
|
2014-04-06 00:31:07 -05:00
|
|
|
if path.to_s =~ HOMEBREW_TAP_DIR_REGEX
|
2014-04-24 11:26:45 +09:00
|
|
|
HOMEBREW_REPOSITORY/"Library/Taps/#$1/#$2"
|
2013-04-09 11:01:58 +08:00
|
|
|
else
|
|
|
|
HOMEBREW_REPOSITORY
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def entry_name
|
|
|
|
@entry_name ||= begin
|
|
|
|
repository == HOMEBREW_REPOSITORY ? "Library/Formula/#{name}.rb" : "#{name}.rb"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-09-21 15:14:44 +01:00
|
|
|
def rev_list branch='HEAD'
|
2013-04-09 11:01:58 +08:00
|
|
|
repository.cd do
|
2013-12-17 20:43:45 -06:00
|
|
|
IO.popen("git rev-list --abbrev-commit --remove-empty #{branch} -- #{entry_name}") do |io|
|
|
|
|
yield io.readline.chomp until io.eof?
|
|
|
|
end
|
2012-01-05 16:15:33 -06:00
|
|
|
end
|
2011-08-02 12:30:04 +01:00
|
|
|
end
|
2010-10-27 10:03:30 +02:00
|
|
|
|
2012-01-05 16:15:33 -06:00
|
|
|
def text_from_sha sha
|
2013-04-09 11:01:58 +08:00
|
|
|
repository.cd do
|
|
|
|
`git cat-file blob #{sha}:#{entry_name}`
|
2012-01-05 16:15:33 -06:00
|
|
|
end
|
2011-09-05 09:39:55 +01:00
|
|
|
end
|
2010-10-27 10:03:30 +02:00
|
|
|
|
2013-04-27 14:44:48 -05:00
|
|
|
IGNORED_EXCEPTIONS = [SyntaxError, TypeError, NameError,
|
2014-02-16 18:35:33 +00:00
|
|
|
ArgumentError, FormulaSpecificationError,
|
|
|
|
FormulaValidationError,]
|
2013-04-27 14:44:48 -05:00
|
|
|
|
2012-01-05 16:15:33 -06:00
|
|
|
def version_for_sha sha
|
2013-09-21 15:14:20 +01:00
|
|
|
formula_for_sha(sha) {|f| f.version }
|
|
|
|
end
|
|
|
|
|
|
|
|
def formula_for_sha sha, &block
|
2012-01-06 14:35:48 -06:00
|
|
|
mktemp do
|
|
|
|
path = Pathname.new(Pathname.pwd+"#{name}.rb")
|
|
|
|
path.write text_from_sha(sha)
|
2012-01-12 00:57:23 -06:00
|
|
|
|
2012-01-27 03:19:53 -06:00
|
|
|
# Unload the class so Formula#version returns the correct value
|
2012-01-26 23:02:18 -06:00
|
|
|
begin
|
2013-12-09 21:10:32 -06:00
|
|
|
old_const = Formulary.unload_formula name
|
2013-09-21 15:14:20 +01:00
|
|
|
nostdout { yield Formula.factory(path.to_s) }
|
2013-04-27 14:44:48 -05:00
|
|
|
rescue *IGNORED_EXCEPTIONS => e
|
2012-01-27 03:19:53 -06:00
|
|
|
# We rescue these so that we can skip bad versions and
|
|
|
|
# continue walking the history
|
2013-03-21 17:04:05 -05:00
|
|
|
ohai "#{e} in #{name} at revision #{sha}", e.backtrace if ARGV.debug?
|
2013-07-03 10:06:11 -07:00
|
|
|
rescue FormulaUnavailableError
|
|
|
|
# Suppress this error
|
2013-12-09 21:10:32 -06:00
|
|
|
ensure
|
|
|
|
Formulary.restore_formula name, old_const
|
2012-01-26 23:02:18 -06:00
|
|
|
end
|
2012-01-27 03:19:53 -06:00
|
|
|
end
|
2011-08-02 14:45:37 +01:00
|
|
|
end
|
2010-10-27 10:03:30 +02:00
|
|
|
end
|