Class: FormulaVersions

Inherits:
Object
  • Object
show all
Defined in:
Library/Homebrew/formula_versions.rb

Constant Summary collapse

IGNORED_EXCEPTIONS =
[
  ArgumentError, NameError, SyntaxError, TypeError,
  FormulaSpecificationError, FormulaValidationError,
  ErrorDuringExecution, LoadError, MethodDeprecatedError
].freeze
MAX_VERSIONS_DEPTH =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formula) ⇒ FormulaVersions

Returns a new instance of FormulaVersions



14
15
16
17
18
19
20
21
# File 'Library/Homebrew/formula_versions.rb', line 14

def initialize(formula)
  @name = formula.name
  @path = formula.path
  @repository = formula.tap.path
  @entry_name = @path.relative_path_from(repository).to_s
  @current_formula = formula
  @formula_at_revision = {}
end

Instance Attribute Details

#entry_nameObject (readonly)

Returns the value of attribute entry_name



12
13
14
# File 'Library/Homebrew/formula_versions.rb', line 12

def entry_name
  @entry_name
end

#nameObject (readonly)

Returns the value of attribute name



12
13
14
# File 'Library/Homebrew/formula_versions.rb', line 12

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path



12
13
14
# File 'Library/Homebrew/formula_versions.rb', line 12

def path
  @path
end

#repositoryObject (readonly)

Returns the value of attribute repository



12
13
14
# File 'Library/Homebrew/formula_versions.rb', line 12

def repository
  @repository
end

Instance Method Details

#bottle_version_map(branch) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'Library/Homebrew/formula_versions.rb', line 52

def bottle_version_map(branch)
  map = Hash.new { |h, k| h[k] = [] }

  versions_seen = 0
  rev_list(branch) do |rev|
    formula_at_revision(rev) do |f|
      bottle = f.bottle_specification
      map[f.pkg_version] << bottle.rebuild unless bottle.checksums.empty?
      versions_seen = (map.keys + [f.pkg_version]).uniq.length
    end
    return map if versions_seen > MAX_VERSIONS_DEPTH
  end
  map
end

#file_contents_at_revision(rev) ⇒ Object



31
32
33
# File 'Library/Homebrew/formula_versions.rb', line 31

def file_contents_at_revision(rev)
  repository.cd { Utils.popen_read("git", "cat-file", "blob", "#{rev}:#{entry_name}") }
end

#formula_at_revision(rev) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'Library/Homebrew/formula_versions.rb', line 35

def formula_at_revision(rev)
  Homebrew.raise_deprecation_exceptions = true

  yield @formula_at_revision[rev] ||= begin
    contents = file_contents_at_revision(rev)
    nostdout { Formulary.from_contents(name, path, contents) }
  end
rescue *IGNORED_EXCEPTIONS => e
  # We rescue these so that we can skip bad versions and
  # continue walking the history
  ohai "#{e} in #{name} at revision #{rev}", e.backtrace if ARGV.debug?
rescue FormulaUnavailableError
  return
ensure
  Homebrew.raise_deprecation_exceptions = false
end

#previous_version_and_checksum(branch) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'Library/Homebrew/formula_versions.rb', line 67

def previous_version_and_checksum(branch)
  map = {}

  rev_list(branch) do |rev|
    formula_at_revision(rev) do |f|
      [:stable, :devel].each do |spec_sym|
        next unless spec = f.send(spec_sym)
        map[spec_sym] ||= { version: spec.version, checksum: spec.checksum }
      end
    end

    break if map[:stable] || map[:devel]
  end

  map[:stable] ||= {}
  map[:devel] ||= {}

  map
end

#rev_list(branch) ⇒ Object



23
24
25
26
27
28
29
# File 'Library/Homebrew/formula_versions.rb', line 23

def rev_list(branch)
  repository.cd do
    Utils.popen_read("git", "rev-list", "--abbrev-commit", "--remove-empty", branch, "--", entry_name) do |io|
      yield io.readline.chomp until io.eof?
    end
  end
end

#version_attributes_map(attributes, branch) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'Library/Homebrew/formula_versions.rb', line 87

def version_attributes_map(attributes, branch)
  attributes_map = {}
  return attributes_map if attributes.empty?

  attributes.each do |attribute|
    attributes_map[attribute] ||= {
      stable: {},
      devel: {},
    }
  end

  stable_versions_seen = 0
  rev_list(branch) do |rev|
    formula_at_revision(rev) do |f|
      attributes.each do |attribute|
        map = attributes_map[attribute]
        set_attribute_map(map, f, attribute)

        stable_keys_length = (map[:stable].keys + [f.version]).uniq.length
        stable_versions_seen = [stable_versions_seen, stable_keys_length].max
      end
    end
    break if stable_versions_seen > MAX_VERSIONS_DEPTH
  end

  attributes_map
end