Skip to content

Commit

Permalink
Use HeadVersion for install/reinstall
Browse files Browse the repository at this point in the history
  • Loading branch information
vladshablinsky authored and xu-cheng committed Jul 16, 2016
1 parent 8a968a0 commit 2e91611
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Library/Homebrew/download_strategy.rb
Expand Up @@ -135,6 +135,8 @@ def fetch
clone_repo
end

version.update_commit(last_commit) if head?

if @ref_type == :tag && @revision && current_revision
unless current_revision == @revision
raise <<-EOS.undent
Expand Down
22 changes: 21 additions & 1 deletion Library/Homebrew/formula.rb
Expand Up @@ -287,6 +287,14 @@ def version
active_spec.version
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.
def pkg_version
PkgVersion.new(version, revision)
Expand Down Expand Up @@ -405,11 +413,23 @@ def linked_keg
Pathname.new("#{HOMEBREW_LIBRARY}/LinkedKegs/#{name}")
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}
# and then {#stable}'s {#prefix}
# @private
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
elsif devel && (devel_prefix = prefix(PkgVersion.new(devel.version, revision))).directory?
devel_prefix
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/formula_installer.rb
Expand Up @@ -586,13 +586,16 @@ def build
end
end

formula.update_head_version

if !formula.prefix.directory? || Keg.new(formula.prefix).empty_installation?
raise "Empty installation"
end

rescue Exception
ignore_interrupts do
# any exceptions must leave us with nothing installed
formula.update_head_version
formula.prefix.rmtree if formula.prefix.directory?
formula.rack.rmdir_if_possible
end
Expand Down
6 changes: 2 additions & 4 deletions Library/Homebrew/pkg_version.rb
Expand Up @@ -5,6 +5,8 @@ class PkgVersion

RX = /\A(.+?)(?:_(\d+))?\z/

attr_reader :version, :revision

def self.parse(path)
_, version, revision = *path.match(RX)
version = Version.create(version)
Expand Down Expand Up @@ -38,8 +40,4 @@ def <=>(other)
def hash
version.hash ^ revision.hash
end

protected

attr_reader :version, :revision
end
3 changes: 2 additions & 1 deletion Library/Homebrew/software_spec.rb
Expand Up @@ -29,6 +29,7 @@ class SoftwareSpec
def_delegators :@resource, :cached_download, :clear_cache
def_delegators :@resource, :checksum, :mirrors, :specs, :using
def_delegators :@resource, :version, :mirror, *Checksum::TYPES
def_delegators :@resource, :downloader

def initialize
@resource = Resource.new
Expand Down Expand Up @@ -203,7 +204,7 @@ def add_dep_option(dep)
class HeadSoftwareSpec < SoftwareSpec
def initialize
super
@resource.version = Version.new("HEAD")
@resource.version = HeadVersion.new("HEAD")
end

def verify_download_integrity(_fn)
Expand Down

0 comments on commit 2e91611

Please sign in to comment.