brew/Library/Homebrew/pkg_version.rb
Jack Nagel 6008187d5f Encode formula revision in installation prefix
In order to allow kegs built with the same version but differing formula
revisions to coexist, we must encode the revision as part of the keg's
name. This is necessary to actually perform an upgrade, as we cannot
upgrade a keg in-place, and temporarily moving it pending the result of
the upgrade is error-prone and potentially slow.

To accomplish this, we introduce a new Formula#pkg_version method that
concatenates the active_spec version with the formula revision. An
exception is made for a formula that has no revision: the tag is
omitted. This preserves compatibility with existing installations.
2014-03-05 20:12:51 -06:00

36 lines
564 B
Ruby

require 'version'
class PkgVersion < Version
attr_reader :version, :revision
RX = /\A(.+?)(?:_(\d+))?\z/
def self.parse(path)
_, version, revision = *path.match(RX)
new(version, revision)
end
def initialize(version, revision)
super(version)
if head?
@revision = 0
else
@revision = revision.to_i
end
end
def to_s
if revision > 0
"#{version}_#{revision}"
else
version
end
end
alias_method :to_str, :to_s
def <=>(other)
super.nonzero? || revision <=> other.revision
end
end