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

View File

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