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?
|
|
|
|
|
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 = []
|
|
|
|
rev_list.each do |sha|
|
|
|
|
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-09-21 15:15:07 +01:00
|
|
|
def bottle_filenames branch='HEAD'
|
|
|
|
filenames = []
|
|
|
|
rev_list(branch).each do |sha|
|
2013-09-22 15:59:55 +01:00
|
|
|
filename = formula_for_sha(sha) {|f| bottle_filename f if f.bottle }
|
2013-09-21 15:15:07 +01:00
|
|
|
unless filenames.include? filename or filename.nil?
|
|
|
|
filenames << filename
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return filenames
|
|
|
|
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
|
|
|
|
if path.realpath.to_s =~ %r{#{HOMEBREW_REPOSITORY}/Library/Taps/(\w+)-(\w+)}
|
|
|
|
HOMEBREW_REPOSITORY/"Library/Taps/#$1-#$2"
|
|
|
|
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-09-21 15:14:44 +01:00
|
|
|
`git rev-list --abbrev-commit #{branch} -- #{entry_name}`.split
|
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
|
|
|
|
2012-01-05 16:15:33 -06:00
|
|
|
def sha_for_version version
|
|
|
|
rev_list.find{ |sha| version == version_for_sha(sha) }
|
|
|
|
end
|
2010-10-27 10:03:30 +02:00
|
|
|
|
2013-04-27 14:44:48 -05:00
|
|
|
IGNORED_EXCEPTIONS = [SyntaxError, TypeError, NameError,
|
|
|
|
ArgumentError, FormulaSpecificationError]
|
|
|
|
|
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-06-23 14:07:46 -07:00
|
|
|
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
|
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
|