| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-19 17:57:36 -05:00
										 |  |  | require "formula" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  | class FormulaVersions | 
					
						
							|  |  |  |   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 | 
					
						
							| 
									
										
										
										
											2014-07-05 13:50:54 -05:00
										 |  |  |       Utils.popen_read("git", "rev-list", "--abbrev-commit", "--remove-empty", 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) | 
					
						
							|  |  |  |       nostdout { Formulary.from_contents(name, path, contents) } | 
					
						
							| 
									
										
										
										
											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-05-23 14:03:43 +01:00
										 |  |  |     odebug "#{e} in #{name} at revision #{rev}", e.backtrace if Homebrew.args.debug? | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-29 00:20:05 -04:00
										 |  |  |   def bottle_version_map(branch) | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |     map = Hash.new { |h, k| h[k] = [] } | 
					
						
							| 
									
										
										
										
											2017-04-23 18:56:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     versions_seen = 0
 | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |     rev_list(branch) do |rev| | 
					
						
							|  |  |  |       formula_at_revision(rev) do |f| | 
					
						
							| 
									
										
										
										
											2015-01-20 22:25:24 -05:00
										 |  |  |         bottle = f.bottle_specification | 
					
						
							| 
									
										
										
										
											2016-09-23 11:01:40 +02:00
										 |  |  |         map[f.pkg_version] << bottle.rebuild unless bottle.checksums.empty? | 
					
						
							| 
									
										
										
										
											2017-04-23 18:56:22 +01:00
										 |  |  |         versions_seen = (map.keys + [f.pkg_version]).uniq.length | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2017-04-23 18:56:22 +01:00
										 |  |  |       return map if versions_seen > MAX_VERSIONS_DEPTH | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |     end | 
					
						
							|  |  |  |     map | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |