2010-10-27 10:03:30 +02:00
|
|
|
require 'formula'
|
|
|
|
|
|
|
|
module Homebrew extend self
|
2011-08-02 12:30:04 +01:00
|
|
|
def versions
|
|
|
|
raise "Please `brew install git` first" unless system "/usr/bin/which -s git"
|
2010-10-27 10:03:30 +02:00
|
|
|
|
2011-08-02 12:30:04 +01:00
|
|
|
ARGV.formulae.all? do |f|
|
2012-01-05 16:15:33 -06:00
|
|
|
f.versions do |version, sha|
|
2011-08-02 12:30:04 +01:00
|
|
|
print Tty.white
|
|
|
|
print "#{version.ljust(8)} "
|
|
|
|
print Tty.reset
|
2011-08-02 14:45:37 +01:00
|
|
|
puts "git checkout #{sha} #{f.pretty_relative_path}"
|
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
|
|
|
|
begin
|
|
|
|
version = mktemp do
|
|
|
|
path = Pathname.new(Pathname.pwd+"#{name}.rb")
|
|
|
|
path.write text_from_sha(sha)
|
|
|
|
Formula.factory(path).version
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
opoo "Version of #{name} could not be determined for #{sha}."
|
|
|
|
end
|
2011-08-02 14:45:37 +01:00
|
|
|
end
|
2010-10-27 10:03:30 +02:00
|
|
|
end
|