mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Only cache strings, thanks
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
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
|
|
||||||
@old_stats
|
@old_stats
|
||||||
else
|
else
|
||||||
incremental_stats(@old_sha1, @current_sha1, @old_stats)
|
incremental_stats(@old_sha1, @current_sha1, @old_stats)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module Linguist
|
module Linguist
|
||||||
VERSION = "2.12.0"
|
VERSION = "2.13.0.github2"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user