Class: FormulaVersions Private

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

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. 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 a private API. This constant may only be used in the Homebrew/brew repository. 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
MAX_VERSIONS_DEPTH =

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

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. 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.

Returns a new instance of FormulaVersions.



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

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. 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.



20
21
22
# File 'formula_versions.rb', line 20

def entry_name
  @entry_name
end

#nameObject (readonly)

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.



20
21
22
# File 'formula_versions.rb', line 20

def name
  @name
end

#pathObject (readonly)

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.



20
21
22
# File 'formula_versions.rb', line 20

def path
  @path
end

#repositoryObject (readonly)

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.



20
21
22
# File 'formula_versions.rb', line 20

def repository
  @repository
end

Instance Method Details

#file_contents_at_revision(rev) ⇒ String

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:

Returns:



42
43
44
# File 'formula_versions.rb', line 42

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

#formula_at_revision(rev, &_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:

  • rev (String)
  • _block (T.proc.params(arg0: Formula).returns(T.type_parameter(:U)))

Returns:

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


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

def formula_at_revision(rev, &_block)
  Homebrew.raise_deprecation_exceptions = true

  yield @formula_at_revision[rev] ||= begin
    contents = file_contents_at_revision(rev)
    nostdout { Formulary.from_contents(name, path, contents, ignore_errors: true) }
  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
rescue FormulaUnavailableError
  nil
ensure
  Homebrew.raise_deprecation_exceptions = false
end

#nostdout(&block) ⇒ Object

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.



68
69
70
71
72
73
74
# File 'formula_versions.rb', line 68

def nostdout(&block)
  if verbose?
    yield
  else
    redirect_stdout(File::NULL, &block)
  end
end

#rev_list(branch) ⇒ Object

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.



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

def rev_list(branch)
  repository.cd do
    rev_list_cmd = ["git", "rev-list", "--abbrev-commit", "--remove-empty"]
    rev_list_cmd << "--first-parent" if repository != CoreTap.instance.path
    Utils.popen_read(*rev_list_cmd, branch, "--", entry_name) do |io|
      yield io.readline.chomp until io.eof?
    end
  end
end