Use HeadVersion for install/reinstall

This commit is contained in:
Vlad Shablinsky 2016-07-13 10:11:59 +03:00 committed by Xu Cheng
parent 8a968a0b60
commit 2e916110e4
No known key found for this signature in database
GPG Key ID: C2A3860FA0B459CE
5 changed files with 30 additions and 6 deletions

View File

@ -135,6 +135,8 @@ class VCSDownloadStrategy < AbstractDownloadStrategy
clone_repo clone_repo
end end
version.update_commit(last_commit) if head?
if @ref_type == :tag && @revision && current_revision if @ref_type == :tag && @revision && current_revision
unless current_revision == @revision unless current_revision == @revision
raise <<-EOS.undent raise <<-EOS.undent

View File

@ -287,6 +287,14 @@ class Formula
active_spec.version active_spec.version
end end
def update_head_version
return unless head?
return unless head.downloader.is_a?(VCSDownloadStrategy)
return unless head.downloader.cached_location.exist?
head.version.update_commit(head.downloader.last_commit)
end
# The {PkgVersion} for this formula with {version} and {#revision} information. # The {PkgVersion} for this formula with {version} and {#revision} information.
def pkg_version def pkg_version
PkgVersion.new(version, revision) PkgVersion.new(version, revision)
@ -405,11 +413,23 @@ class Formula
Pathname.new("#{HOMEBREW_LIBRARY}/LinkedKegs/#{name}") Pathname.new("#{HOMEBREW_LIBRARY}/LinkedKegs/#{name}")
end end
def latest_head_prefix
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|
[Tab.for_keg(prefix(pn_pkgversion)).source_modified_time, pn_pkgversion.revision]
end
prefix(latest_head_version) if latest_head_version
end
# The latest prefix for this formula. Checks for {#head}, then {#devel} # The latest prefix for this formula. Checks for {#head}, then {#devel}
# and then {#stable}'s {#prefix} # and then {#stable}'s {#prefix}
# @private # @private
def installed_prefix def installed_prefix
if head && (head_prefix = prefix(PkgVersion.new(head.version, revision))).directory? if head && (head_prefix = latest_head_prefix) && head_prefix.directory?
head_prefix head_prefix
elsif devel && (devel_prefix = prefix(PkgVersion.new(devel.version, revision))).directory? elsif devel && (devel_prefix = prefix(PkgVersion.new(devel.version, revision))).directory?
devel_prefix devel_prefix

View File

@ -586,6 +586,8 @@ class FormulaInstaller
end end
end end
formula.update_head_version
if !formula.prefix.directory? || Keg.new(formula.prefix).empty_installation? if !formula.prefix.directory? || Keg.new(formula.prefix).empty_installation?
raise "Empty installation" raise "Empty installation"
end end
@ -593,6 +595,7 @@ class FormulaInstaller
rescue Exception rescue Exception
ignore_interrupts do ignore_interrupts do
# any exceptions must leave us with nothing installed # any exceptions must leave us with nothing installed
formula.update_head_version
formula.prefix.rmtree if formula.prefix.directory? formula.prefix.rmtree if formula.prefix.directory?
formula.rack.rmdir_if_possible formula.rack.rmdir_if_possible
end end

View File

@ -5,6 +5,8 @@ class PkgVersion
RX = /\A(.+?)(?:_(\d+))?\z/ RX = /\A(.+?)(?:_(\d+))?\z/
attr_reader :version, :revision
def self.parse(path) def self.parse(path)
_, version, revision = *path.match(RX) _, version, revision = *path.match(RX)
version = Version.create(version) version = Version.create(version)
@ -38,8 +40,4 @@ class PkgVersion
def hash def hash
version.hash ^ revision.hash version.hash ^ revision.hash
end end
protected
attr_reader :version, :revision
end end

View File

@ -29,6 +29,7 @@ class SoftwareSpec
def_delegators :@resource, :cached_download, :clear_cache def_delegators :@resource, :cached_download, :clear_cache
def_delegators :@resource, :checksum, :mirrors, :specs, :using def_delegators :@resource, :checksum, :mirrors, :specs, :using
def_delegators :@resource, :version, :mirror, *Checksum::TYPES def_delegators :@resource, :version, :mirror, *Checksum::TYPES
def_delegators :@resource, :downloader
def initialize def initialize
@resource = Resource.new @resource = Resource.new
@ -203,7 +204,7 @@ end
class HeadSoftwareSpec < SoftwareSpec class HeadSoftwareSpec < SoftwareSpec
def initialize def initialize
super super
@resource.version = Version.new("HEAD") @resource.version = HeadVersion.new("HEAD")
end end
def verify_download_integrity(_fn) def verify_download_integrity(_fn)