diff options
| author | Vlad Shablinsky | 2016-07-13 10:11:59 +0300 | 
|---|---|---|
| committer | Xu Cheng | 2016-07-16 20:39:13 +0800 | 
| commit | 2e916110e4c561b3e4175da099fc795e85ddb822 (patch) | |
| tree | b7edc24e977fc8a3f3d14212e0d15cac57eab137 | |
| parent | 8a968a0b60dbc78f9f48be76762c9f050fa6416d (diff) | |
| download | brew-2e916110e4c561b3e4175da099fc795e85ddb822.tar.bz2 | |
Use HeadVersion for install/reinstall
| -rw-r--r-- | Library/Homebrew/download_strategy.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/formula.rb | 22 | ||||
| -rw-r--r-- | Library/Homebrew/formula_installer.rb | 3 | ||||
| -rw-r--r-- | Library/Homebrew/pkg_version.rb | 6 | ||||
| -rw-r--r-- | Library/Homebrew/software_spec.rb | 3 | 
5 files changed, 30 insertions, 6 deletions
| diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 061e551a6..3016b8833 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -135,6 +135,8 @@ class VCSDownloadStrategy < AbstractDownloadStrategy        clone_repo      end +    version.update_commit(last_commit) if head? +      if @ref_type == :tag && @revision && current_revision        unless current_revision == @revision          raise <<-EOS.undent diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 4cb584525..aa66bbb49 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -287,6 +287,14 @@ class Formula      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) @@ -405,11 +413,23 @@ class Formula      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 diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 375a529bb..4ba8be3ea 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -586,6 +586,8 @@ class FormulaInstaller        end      end +    formula.update_head_version +      if !formula.prefix.directory? || Keg.new(formula.prefix).empty_installation?        raise "Empty installation"      end @@ -593,6 +595,7 @@ class FormulaInstaller    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 diff --git a/Library/Homebrew/pkg_version.rb b/Library/Homebrew/pkg_version.rb index 9e065c835..4bf701f35 100644 --- a/Library/Homebrew/pkg_version.rb +++ b/Library/Homebrew/pkg_version.rb @@ -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) @@ -38,8 +40,4 @@ class PkgVersion    def hash      version.hash ^ revision.hash    end - -  protected - -  attr_reader :version, :revision  end diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 52885772c..c7e91975a 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -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 @@ -203,7 +204,7 @@ end  class HeadSoftwareSpec < SoftwareSpec    def initialize      super -    @resource.version = Version.new("HEAD") +    @resource.version = HeadVersion.new("HEAD")    end    def verify_download_integrity(_fn) | 
