| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-19 17:57:36 -05:00
										 |  |  | require "formula" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-17 06:09:57 +02:00
										 |  |  | # Helper class for traversing a formula's previous versions. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # @api private | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  | class FormulaVersions | 
					
						
							| 
									
										
										
										
											2020-08-02 14:32:31 +02:00
										 |  |  |   include Context | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |   IGNORED_EXCEPTIONS = [ | 
					
						
							|  |  |  |     ArgumentError, NameError, SyntaxError, TypeError, | 
					
						
							|  |  |  |     FormulaSpecificationError, FormulaValidationError, | 
					
						
							| 
									
										
										
										
											2016-10-08 12:04:38 +02:00
										 |  |  |     ErrorDuringExecution, LoadError, MethodDeprecatedError | 
					
						
							| 
									
										
										
										
											2016-09-17 15:17:27 +01:00
										 |  |  |   ].freeze | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-23 18:56:22 +01:00
										 |  |  |   MAX_VERSIONS_DEPTH = 2
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-02 16:42:54 +08:00
										 |  |  |   attr_reader :name, :path, :repository, :entry_name | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-23 18:56:22 +01:00
										 |  |  |   def initialize(formula) | 
					
						
							| 
									
										
										
										
											2015-04-01 21:06:03 -04:00
										 |  |  |     @name = formula.name | 
					
						
							| 
									
										
										
										
											2015-09-02 16:42:54 +08:00
										 |  |  |     @path = formula.path | 
					
						
							| 
									
										
										
										
											2015-12-06 22:45:03 +08:00
										 |  |  |     @repository = formula.tap.path | 
					
						
							| 
									
										
										
										
											2015-09-02 16:42:54 +08:00
										 |  |  |     @entry_name = @path.relative_path_from(repository).to_s | 
					
						
							| 
									
										
										
										
											2017-04-23 18:56:22 +01:00
										 |  |  |     @current_formula = formula | 
					
						
							| 
									
										
										
										
											2017-06-03 00:23:06 +02:00
										 |  |  |     @formula_at_revision = {} | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-29 00:16:50 -04:00
										 |  |  |   def rev_list(branch) | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |     repository.cd do | 
					
						
							| 
									
										
										
										
											2021-05-04 09:45:31 -04:00
										 |  |  |       rev_list_cmd = ["git", "rev-list", "--abbrev-commit", "--remove-empty"] | 
					
						
							| 
									
										
										
										
											2021-05-04 11:30:14 -04:00
										 |  |  |       rev_list_cmd << "--first-parent" if repository != CoreTap.instance.path | 
					
						
							| 
									
										
										
										
											2021-05-04 09:45:31 -04:00
										 |  |  |       Utils.popen_read(*rev_list_cmd, branch, "--", entry_name) do |io| | 
					
						
							| 
									
										
										
										
											2017-04-23 18:56:22 +01:00
										 |  |  |         yield io.readline.chomp until io.eof? | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def file_contents_at_revision(rev) | 
					
						
							| 
									
										
										
										
											2015-03-06 22:30:22 +08:00
										 |  |  |     repository.cd { Utils.popen_read("git", "cat-file", "blob", "#{rev}:#{entry_name}") } | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-04 14:29:00 -05:00
										 |  |  |   def formula_at_revision(rev) | 
					
						
							| 
									
										
										
										
											2017-06-03 00:23:06 +02:00
										 |  |  |     Homebrew.raise_deprecation_exceptions = true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     yield @formula_at_revision[rev] ||= begin | 
					
						
							|  |  |  |       contents = file_contents_at_revision(rev) | 
					
						
							| 
									
										
										
										
											2021-04-13 17:41:20 +01:00
										 |  |  |       nostdout { Formulary.from_contents(name, path, contents, ignore_errors: true) } | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-06-03 00:23:06 +02:00
										 |  |  |   rescue *IGNORED_EXCEPTIONS => e | 
					
						
							|  |  |  |     # We rescue these so that we can skip bad versions and | 
					
						
							|  |  |  |     # continue walking the history | 
					
						
							| 
									
										
										
										
											2020-07-06 15:29:15 -04:00
										 |  |  |     odebug "#{e} in #{name} at revision #{rev}", e.backtrace | 
					
						
							| 
									
										
										
										
											2017-06-03 00:23:06 +02:00
										 |  |  |   rescue FormulaUnavailableError | 
					
						
							| 
									
										
										
										
											2018-03-06 09:36:49 +00:00
										 |  |  |     nil | 
					
						
							| 
									
										
										
										
											2017-06-03 00:23:06 +02:00
										 |  |  |   ensure | 
					
						
							|  |  |  |     Homebrew.raise_deprecation_exceptions = false | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2023-03-02 16:56:50 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def nostdout(&block) | 
					
						
							|  |  |  |     if verbose? | 
					
						
							|  |  |  |       yield | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       redirect_stdout(File::NULL, &block) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  | end |