Add support for stats breakdown by file per repo

This commit is contained in:
Ted Nyman
2013-12-28 19:22:13 -08:00
parent f7b7a89709
commit e660442e2e
2 changed files with 21 additions and 0 deletions

View File

@@ -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?

View File

@@ -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