| 
									
										
										
										
											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, | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     ErrorDuringExecution, LoadError | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |   ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-01 21:06:03 -04:00
										 |  |  |   attr_reader :name, :repository, :entry_name | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-01 21:06:03 -04:00
										 |  |  |   def initialize(formula) | 
					
						
							|  |  |  |     @name = formula.name | 
					
						
							|  |  |  |     @repository = formula.tap? ? HOMEBREW_LIBRARY.join("Taps", formula.tap) : HOMEBREW_REPOSITORY | 
					
						
							|  |  |  |     @entry_name = formula.path.relative_path_from(repository).to_s | 
					
						
							| 
									
										
										
										
											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| | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |         yield io.readline.chomp until io.eof? | 
					
						
							|  |  |  |       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-04-01 21:06:03 -04:00
										 |  |  |     FileUtils.mktemp(name) do | 
					
						
							|  |  |  |       path = Pathname.pwd.join("#{name}.rb") | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |       path.write file_contents_at_revision(rev) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       begin | 
					
						
							| 
									
										
										
										
											2014-06-22 15:00:15 -05:00
										 |  |  |         nostdout { yield Formulary.factory(path.to_s) } | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |       rescue *IGNORED_EXCEPTIONS => e | 
					
						
							|  |  |  |         # We rescue these so that we can skip bad versions and | 
					
						
							|  |  |  |         # continue walking the history | 
					
						
							| 
									
										
										
										
											2015-04-01 21:06:03 -04:00
										 |  |  |         ohai "#{e} in #{name} at revision #{rev}", e.backtrace if ARGV.debug? | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |       rescue FormulaUnavailableError | 
					
						
							|  |  |  |         # Suppress this error | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     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 | 
					
						
							| 
									
										
										
										
											2014-05-28 16:23:33 -05:00
										 |  |  |         unless bottle.checksums.empty? | 
					
						
							|  |  |  |           map[f.pkg_version] << bottle.revision | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     map | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |