mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Add support for stats breakdown by file per repo
This commit is contained in:
		| @@ -15,6 +15,12 @@ if File.directory?(path) | ||||
|     percentage = sprintf '%.2f' % percentage | ||||
|     puts "%-7s %s" % ["#{percentage}%", language] | ||||
|   end | ||||
|   puts | ||||
|   breakdown = repo.breakdown_by_file | ||||
|   breakdown.each do |lang, files| | ||||
|     puts "#{lang}: #{files}" | ||||
|     puts | ||||
|   end | ||||
| elsif File.file?(path) | ||||
|   blob = Linguist::FileBlob.new(path, Dir.pwd) | ||||
|   type = if blob.text? | ||||
|   | ||||
| @@ -29,6 +29,7 @@ module Linguist | ||||
|       @computed_stats = false | ||||
|       @language = @size = nil | ||||
|       @sizes = Hash.new { 0 } | ||||
|       @file_breakdown = {} | ||||
|     end | ||||
|  | ||||
|     # Public: Returns a breakdown of language stats. | ||||
| @@ -60,6 +61,12 @@ module Linguist | ||||
|       @size | ||||
|     end | ||||
|  | ||||
|     # Public: Return the language breakdown of this repository by file | ||||
|     def breakdown_by_file | ||||
|       compute_stats unless @computed_stats | ||||
|       @file_breakdown | ||||
|     end | ||||
|  | ||||
|     # Internal: Compute language breakdown for each blob in the Repository. | ||||
|     # | ||||
|     # Returns nothing | ||||
| @@ -75,6 +82,14 @@ module Linguist | ||||
|  | ||||
|         # Only include programming languages and acceptable markup languages | ||||
|         if blob.language.type == :programming || Language.detectable_markup.include?(blob.language.name) | ||||
|  | ||||
|           # Build up the per-file breakdown stats if asked | ||||
|           if @file_breakdown[blob.language.group.name] | ||||
|             @file_breakdown[blob.language.group.name] << blob.name | ||||
|           else | ||||
|             @file_breakdown[blob.language.group.name] = [blob.name] | ||||
|           end | ||||
|  | ||||
|           @sizes[blob.language.group] += blob.size | ||||
|         end | ||||
|       end | ||||
|   | ||||
		Reference in New Issue
	
	Block a user