Skip to content

Commit

Permalink
Merge pull request #719 from vladshablinsky/epochs
Browse files Browse the repository at this point in the history
Implement epochs
  • Loading branch information
MikeMcQuaid authored Aug 18, 2016
2 parents 48c442e + 6a684f4 commit b39eba6
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 2 deletions.
24 changes: 23 additions & 1 deletion Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ class Formula
# @see .revision
attr_reader :revision

# Used to change version schemes for packages
attr_reader :version_scheme

# The current working directory during builds.
# Will only be non-`nil` inside {#install}.
attr_reader :buildpath
Expand All @@ -139,6 +142,7 @@ def initialize(name, path, spec)
@name = name
@path = path
@revision = self.class.revision || 0
@version_scheme = self.class.version_scheme || 0

if path == Formulary.core_path(name)
@tap = CoreTap.instance
Expand Down Expand Up @@ -432,6 +436,7 @@ def latest_head_prefix
def head_version_outdated?(version, options={})
tab = Tab.for_keg(prefix(version))

return true if tab.version_scheme < version_scheme
return true if stable && tab.stable_version && tab.stable_version < stable.version
return true if devel && tab.devel_version && tab.devel_version < devel.version

Expand Down Expand Up @@ -1014,8 +1019,12 @@ def _outdated_versions(options = {})
installed_kegs.each do |keg|
version = keg.version
all_versions << version
next if version.head?

return [] if pkg_version <= version && !version.head?
tab = Tab.for_keg(keg)
next if version_scheme > tab.version_scheme
next if version_scheme == tab.version_scheme && pkg_version > version
return []
end

head_version = latest_head_version
Expand Down Expand Up @@ -1288,6 +1297,7 @@ def to_hash
"head" => (head.version.to_s if head)
},
"revision" => revision,
"version_scheme" => version_scheme,
"installed" => [],
"linked_keg" => (linked_keg.resolved_path.basename.to_s if linked_keg.exist?),
"pinned" => pinned?,
Expand Down Expand Up @@ -1695,6 +1705,18 @@ class << self
# <pre>revision 1</pre>
attr_rw :revision

# @!attribute [w] version_scheme
# Used for creating new Homebrew versions schemes. For example, if we want
# to change version scheme from one to another, then we may need to update
# `version_scheme` of this {Formula} to be able to use new version scheme.
# E.g. to move from 20151020 scheme to 1.0.0 we need to increment
# `version_scheme`. Without this, the prior scheme will always equate to a
# higher version.
# `0` if unset.
#
# <pre>version_scheme 1</pre>
attr_rw :version_scheme

# A list of the {.stable}, {.devel} and {.head} {SoftwareSpec}s.
# @private
def specs
Expand Down
8 changes: 8 additions & 0 deletions Library/Homebrew/tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def self.create(formula, compiler, stdlib)
"stable" => formula.stable ? formula.stable.version.to_s : nil,
"devel" => formula.devel ? formula.devel.version.to_s : nil,
"head" => formula.head ? formula.head.version.to_s : nil,
"version_scheme" => formula.version_scheme,
}
}
}
Expand Down Expand Up @@ -78,6 +79,7 @@ def self.from_file_content(content, path)
"stable" => nil,
"devel" => nil,
"head" => nil,
"version_scheme" => 0,
}
end

Expand Down Expand Up @@ -142,6 +144,7 @@ def self.for_formula(f)
"stable" => f.stable ? f.stable.version.to_s : nil,
"devel" => f.devel ? f.devel.version.to_s : nil,
"head" => f.head ? f.head.version.to_s : nil,
"version_scheme" => f.version_scheme,
}
}
end
Expand All @@ -168,6 +171,7 @@ def self.empty
"stable" => nil,
"devel" => nil,
"head" => nil,
"version_scheme" => 0,
}
}
}
Expand Down Expand Up @@ -271,6 +275,10 @@ def head_version
Version.create(versions["head"]) if versions["head"]
end

def version_scheme
versions["version_scheme"] || 0
end

def source_modified_time
Time.at(super)
end
Expand Down
66 changes: 65 additions & 1 deletion Library/Homebrew/test/test_formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ def setup_tab_for_prefix(prefix, options = {})

def reset_outdated_versions
f.instance_variable_set(:@outdated_versions, nil)
f.instance_variable_set(:@outdated_versions_head_fetched, nil)
end

def test_greater_different_tap_installed
Expand Down Expand Up @@ -732,4 +731,69 @@ def test_outdated_fetch_head
FileUtils.rm_rf HOMEBREW_CACHE/"testball--git"
FileUtils.rm_rf HOMEBREW_CELLAR/"testball"
end

def test_outdated_versions_version_scheme_changed
@f = formula("testball") do
url "foo"
version "20141010"
version_scheme 1
end

prefix = HOMEBREW_CELLAR.join("testball/0.1")
setup_tab_for_prefix(prefix, :versions => { "stable" => "0.1" })

refute_predicate f.outdated_versions, :empty?
ensure
prefix.rmtree
end

def test_outdated_versions_mixed_version_schemes
@f = formula("testball") do
url "foo"
version "20141010"
version_scheme 3
end

prefix_a = HOMEBREW_CELLAR.join("testball/20141009")
setup_tab_for_prefix(prefix_a, :versions => { "stable" => "20141009", "version_scheme" => 1 })

prefix_b = HOMEBREW_CELLAR.join("testball/2.14")
setup_tab_for_prefix(prefix_b, :versions => { "stable" => "2.14", "version_scheme" => 2 })

refute_predicate f.outdated_versions, :empty?
reset_outdated_versions

prefix_c = HOMEBREW_CELLAR.join("testball/20141009")
setup_tab_for_prefix(prefix_c, :versions => { "stable" => "20141009", "version_scheme" => 3 })

refute_predicate f.outdated_versions, :empty?
reset_outdated_versions

prefix_d = HOMEBREW_CELLAR.join("testball/20141011")
setup_tab_for_prefix(prefix_d, :versions => { "stable" => "20141009", "version_scheme" => 3 })
assert_predicate f.outdated_versions, :empty?
ensure
f.rack.rmtree
end

def test_outdated_versions_head_with_version_scheme
@f = formula("testball") do
url "foo"
version "1.0"
version_scheme 2
end

head_prefix = HOMEBREW_CELLAR.join("testball/HEAD")

setup_tab_for_prefix(head_prefix, :versions => { "stable" => "1.0", "version_scheme" => 1 })
refute_predicate f.outdated_versions, :empty?

reset_outdated_versions
head_prefix.rmtree

setup_tab_for_prefix(head_prefix, :versions => { "stable" => "1.0", "version_scheme" => 2 })
assert_predicate f.outdated_versions, :empty?
ensure
head_prefix.rmtree
end
end

0 comments on commit b39eba6

Please sign in to comment.