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-01-06 14:35:48 -06:00
|
|
|
print "#{version.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
|
|
|
|
|
2012-01-05 16:15:33 -06:00
|
|
|
def pretty_relative_path
|
|
|
|
if Pathname.pwd == HOMEBREW_REPOSITORY
|
|
|
|
"Library/Formula/#{name}.rb"
|
|
|
|
else
|
|
|
|
"#{HOMEBREW_REPOSITORY}/Library/Formula/#{name}.rb"
|
|
|
|
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
|
|
|
|
def rev_list
|
|
|
|
HOMEBREW_REPOSITORY.cd do
|
|
|
|
`git rev-list --abbrev-commit HEAD -- Library/Formula/#{name}.rb`.split
|
|
|
|
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
|
|
|
|
HOMEBREW_REPOSITORY.cd do
|
|
|
|
`git cat-file blob #{sha}:Library/Formula/#{name}.rb`
|
|
|
|
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
|
|
|
|
2012-01-05 16:15:33 -06:00
|
|
|
def version_for_sha sha
|
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-12 00:57:23 -06:00
|
|
|
# FIXME shouldn't have to do this?
|
2012-01-26 23:02:18 -06:00
|
|
|
begin
|
2012-01-27 03:19:53 -06:00
|
|
|
version = nostdout { Formula.factory(path).version }
|
|
|
|
Object.send(:remove_const, Formula.class_s(name))
|
|
|
|
version
|
2012-01-29 16:00:27 -06:00
|
|
|
rescue SyntaxError, TypeError, NameError, ArgumentError
|
2012-01-27 03:19:53 -06:00
|
|
|
# We rescue these so that we can skip bad versions and
|
|
|
|
# continue walking the history
|
2012-01-26 23:02:18 -06:00
|
|
|
nil
|
|
|
|
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
|