formula: add new HEAD methods

* add `latest_head_version` to return latest HEAD version installed
* add `latest_head_prefix` to return Pathname with latest HEAD version
* add `head_version_outdated?` to check if HEAD version is up-to-date
This commit is contained in:
Vlad Shablinsky 2016-07-22 12:58:24 +03:00 committed by Xu Cheng
parent 00f37d6778
commit 1b88c2912b
No known key found for this signature in database
GPG Key ID: C2A3860FA0B459CE

View File

@ -413,16 +413,36 @@ class Formula
Pathname.new("#{HOMEBREW_LIBRARY}/LinkedKegs/#{name}")
end
def latest_head_prefix
def latest_head_version
head_versions = installed_prefixes.map do |pn|
pn_pkgversion = PkgVersion.parse(pn.basename.to_s)
pn_pkgversion if pn_pkgversion.head?
end.compact
latest_head_version = head_versions.max_by do |pn_pkgversion|
head_versions.max_by do |pn_pkgversion|
[Tab.for_keg(prefix(pn_pkgversion)).source_modified_time, pn_pkgversion.revision]
end
prefix(latest_head_version) if latest_head_version
end
def latest_head_prefix
head_version = latest_head_version
prefix(head_version) if head_version
end
def head_version_outdated?(version, options={})
tab = Tab.for_keg(prefix(version))
return true if stable && tab.stable_version && tab.stable_version < stable.version
return true if devel && tab.devel_version && tab.devel_version < devel.version
if options[:fetch_head]
return false unless head && head.downloader.is_a?(VCSDownloadStrategy)
downloader = head.downloader
downloader.shutup! unless ARGV.verbose?
downloader.commit_outdated?(version.version.commit)
else
false
end
end
# The latest prefix for this formula. Checks for {#head}, then {#devel}