Class: FormulaVersions

Inherits:
Object show all
Includes:
Context
Defined in:
formula_versions.rb

Overview

This class is part of an internal API. This class may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Helper class for traversing a formula's previous versions.

Constant Summary collapse

IGNORED_EXCEPTIONS =

This constant is part of an internal API. This constant may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

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

Instance Method Summary collapse

Methods included from Context

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

Constructor Details

#initialize(formula) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:



19
20
21
22
23
24
25
26
27
28
29
# File 'formula_versions.rb', line 19

def initialize(formula)
  @name = formula.name
  @path = formula.path
  @repository = T.must(formula.tap).path
  @relative_path = @path.relative_path_from(repository).to_s
  # Also look at e.g. older homebrew-core paths before sharding.
  if (match = @relative_path.match(%r{^(HomebrewFormula|Formula)/([a-z]|lib)/(.+)}))
    @old_relative_path = "#{match[1]}/#{match[3]}"
  end
  @formula_at_revision = {}
end

Instance Method Details

#formula_at_revision(revision, formula_relative_path = relative_path, &_block) ⇒ T.type_parameter(:U)?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • revision (String)
  • formula_relative_path (String) (defaults to: relative_path)
  • _block (T.proc.params(arg0: Formula).returns(T.type_parameter(:U)))

Returns:

  • (T.type_parameter(:U), nil)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'formula_versions.rb', line 50

def formula_at_revision(revision, formula_relative_path = relative_path, &_block)
  Homebrew.raise_deprecation_exceptions = true

  yield @formula_at_revision[revision] ||= begin
    contents = file_contents_at_revision(revision, formula_relative_path)
    nostdout { Formulary.from_contents(name, path, contents, ignore_errors: true) }
  end
rescue *IGNORED_EXCEPTIONS => e
  require "utils/backtrace"

  # We rescue these so that we can skip bad versions and
  # continue walking the history
  odebug "#{e} in #{name} at revision #{revision}", Utils::Backtrace.clean(e)
rescue FormulaUnavailableError
  nil
ensure
  Homebrew.raise_deprecation_exceptions = false
end

#rev_list(branch) ⇒ Object

This method is part of an internal API. This method may only be used internally in repositories owned by Homebrew, except in casks or formulae. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



31
32
33
34
35
36
37
38
39
40
# File 'formula_versions.rb', line 31

def rev_list(branch)
  repository.cd do
    rev_list_cmd = ["git", "rev-list", "--abbrev-commit", "--remove-empty"]
    [relative_path, old_relative_path].compact.each do |entry|
      Utils.popen_read(*rev_list_cmd, branch, "--", entry) do |io|
        yield [io.readline.chomp, entry] until io.eof?
      end
    end
  end
end