Only cache strings, thanks

This commit is contained in:
Vicent Marti
2014-06-16 16:41:58 +02:00
parent c4260ae681
commit cd58a30c7c
2 changed files with 15 additions and 24 deletions

View File

@@ -31,7 +31,7 @@ module Linguist
def languages def languages
@sizes ||= begin @sizes ||= begin
sizes = Hash.new { 0 } sizes = Hash.new { 0 }
file_map.each do |_, (language, size)| cache.each do |_, (language, size)|
sizes[language] += size sizes[language] += size
end end
sizes sizes
@@ -59,15 +59,15 @@ module Linguist
def breakdown_by_file def breakdown_by_file
@file_breakdown ||= begin @file_breakdown ||= begin
breakdown = Hash.new { |h,k| h[k] = Array.new } breakdown = Hash.new { |h,k| h[k] = Array.new }
file_map.each do |filename, (language, _)| cache.each do |filename, (language, _)|
breakdown[language.name] << filename breakdown[language] << filename
end end
breakdown breakdown
end end
end end
def incremental_stats(old_sha1, new_sha1, file_map = nil) def incremental_stats(old_sha1, new_sha1, cache = nil)
file_map = file_map ? file_map.dup : {} file_map = cache ? cache.dup : {}
old_commit = old_sha1 && Rugged::Commit.lookup(repository, old_sha1) old_commit = old_sha1 && Rugged::Commit.lookup(repository, old_sha1)
new_commit = Rugged::Commit.lookup(repository, new_sha1) new_commit = Rugged::Commit.lookup(repository, new_sha1)
@@ -88,7 +88,7 @@ module Linguist
# Only include programming languages and acceptable markup languages # Only include programming languages and acceptable markup languages
if blob.language.type == :programming || Language.detectable_markup.include?(blob.language.name) if blob.language.type == :programming || Language.detectable_markup.include?(blob.language.name)
file_map[new] = [blob.language.group, blob.size] file_map[new] = [blob.language.group.name, blob.size]
end end
end end
end end
@@ -96,23 +96,14 @@ module Linguist
file_map file_map
end end
def load_stats(file) def cache
@old_sha1, @old_stats = JSON.load(file) @cache ||= begin
end if @old_sha1 == @current_sha1
@old_stats
def dump_stats(file) else
JSON.dump([@current_sha1, file_map], file) incremental_stats(@old_sha1, @current_sha1, @old_stats)
end end
end
# Internal: Compute language breakdown for each blob in the Repository.
#
# Returns nothing
def file_map
@file_map ||= if @old_sha1 == @current_sha1
@old_stats
else
incremental_stats(@old_sha1, @current_sha1, @old_stats)
end
end end
end end
end end

View File

@@ -1,3 +1,3 @@
module Linguist module Linguist
VERSION = "2.12.0" VERSION = "2.13.0.github2"
end end