| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-02 16:42:54 +08:00
										 |  |  |   attr_reader :name, :path, :repository, :entry_name | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-16 23:18:04 +08:00
										 |  |  |   def initialize(formula, options = {}) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2016-01-16 23:18:04 +08:00
										 |  |  |     @max_depth = options[:max_depth] | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2016-01-16 23:18:04 +08:00
										 |  |  |       depth = 0
 | 
					
						
							| 
									
										
										
										
											2014-07-05 13:50:54 -05:00
										 |  |  |       Utils.popen_read("git", "rev-list", "--abbrev-commit", "--remove-empty", branch, "--", entry_name) do |io| | 
					
						
							| 
									
										
										
										
											2016-01-16 23:18:04 +08:00
										 |  |  |         yield io.readline.chomp until io.eof? || (@max_depth && (depth += 1) > @max_depth) | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							| 
									
										
										
										
											2015-09-02 16:42:54 +08:00
										 |  |  |     contents = file_contents_at_revision(rev) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     begin | 
					
						
							| 
									
										
										
										
											2016-08-12 21:06:51 +01:00
										 |  |  |       Homebrew.raise_deprecation_exceptions = true | 
					
						
							| 
									
										
										
										
											2016-08-11 17:07:31 +01:00
										 |  |  |       nostdout { yield Formulary.from_contents(name, path, contents) } | 
					
						
							| 
									
										
										
										
											2015-09-02 16:42:54 +08:00
										 |  |  |     rescue *IGNORED_EXCEPTIONS => e | 
					
						
							|  |  |  |       # We rescue these so that we can skip bad versions and | 
					
						
							|  |  |  |       # continue walking the history | 
					
						
							|  |  |  |       ohai "#{e} in #{name} at revision #{rev}", e.backtrace if ARGV.debug? | 
					
						
							|  |  |  |     rescue FormulaUnavailableError | 
					
						
							|  |  |  |       # Suppress this error | 
					
						
							| 
									
										
										
										
											2016-08-12 21:06:51 +01:00
										 |  |  |     ensure | 
					
						
							|  |  |  |       Homebrew.raise_deprecation_exceptions = false | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |     end | 
					
						
							|  |  |  |   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] = [] } | 
					
						
							|  |  |  |     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? | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     map | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-01-14 13:33:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 12:52:25 +01:00
										 |  |  |   def version_attributes_map(attributes, branch) | 
					
						
							|  |  |  |     attributes_map = {} | 
					
						
							|  |  |  |     return attributes_map if attributes.empty? | 
					
						
							| 
									
										
										
										
											2016-11-13 13:35:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 12:52:25 +01:00
										 |  |  |     attributes.each do |attribute| | 
					
						
							| 
									
										
										
										
											2016-11-13 13:35:25 +00:00
										 |  |  |       attributes_map[attribute] ||= {} | 
					
						
							| 
									
										
										
										
											2016-08-18 12:52:25 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-14 13:33:56 +08:00
										 |  |  |     rev_list(branch) do |rev| | 
					
						
							|  |  |  |       formula_at_revision(rev) do |f| | 
					
						
							| 
									
										
										
										
											2016-08-18 12:52:25 +01:00
										 |  |  |         attributes.each do |attribute| | 
					
						
							|  |  |  |           map = attributes_map[attribute] | 
					
						
							| 
									
										
										
										
											2016-11-13 13:35:25 +00:00
										 |  |  |           if f.stable | 
					
						
							|  |  |  |             map[:stable] ||= {} | 
					
						
							|  |  |  |             map[:stable][f.stable.version] ||= [] | 
					
						
							|  |  |  |             map[:stable][f.stable.version] << f.send(attribute) | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |           next unless f.devel | 
					
						
							|  |  |  |           map[:devel] ||= {} | 
					
						
							| 
									
										
										
										
											2016-11-13 22:27:45 -05:00
										 |  |  |           map[:devel][f.devel.version] ||= [] | 
					
						
							| 
									
										
										
										
											2016-11-13 13:35:25 +00:00
										 |  |  |           map[:devel][f.devel.version] << f.send(attribute) | 
					
						
							| 
									
										
										
										
											2016-08-18 12:52:25 +01:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-01-14 13:33:56 +08:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-11-13 13:35:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 12:52:25 +01:00
										 |  |  |     attributes_map | 
					
						
							| 
									
										
										
										
											2016-01-14 13:33:56 +08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  | end |