Class: FormulaVersions Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Helper class for traversing a formula's previous versions.

Constant Summary collapse

IGNORED_EXCEPTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

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

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

2

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Context

current, current=, #debug?, #quiet?, #verbose?, #with_context

Constructor Details

#initialize(formula) ⇒ FormulaVersions

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of FormulaVersions.


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

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)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


19
20
21
# File 'Library/Homebrew/formula_versions.rb', line 19

def entry_name
  @entry_name
end

#nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


19
20
21
# File 'Library/Homebrew/formula_versions.rb', line 19

def name
  @name
end

#pathObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


19
20
21
# File 'Library/Homebrew/formula_versions.rb', line 19

def path
  @path
end

#repositoryObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


19
20
21
# File 'Library/Homebrew/formula_versions.rb', line 19

def repository
  @repository
end

Instance Method Details

#bottle_version_map(branch) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'Library/Homebrew/formula_versions.rb', line 59

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
  rescue MacOSVersionError => e
    odebug "#{e} in #{name} at revision #{rev}" if debug?
    break
  end
  map
end

#file_contents_at_revision(rev) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


38
39
40
# File 'Library/Homebrew/formula_versions.rb', line 38

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

#formula_at_revision(rev) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'Library/Homebrew/formula_versions.rb', line 42

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
  odebug "#{e} in #{name} at revision #{rev}", e.backtrace if debug?
rescue FormulaUnavailableError
  nil
ensure
  Homebrew.raise_deprecation_exceptions = false
end

#rev_list(branch) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


30
31
32
33
34
35
36
# File 'Library/Homebrew/formula_versions.rb', line 30

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