From cd58a30c7c29fb1a0cd4331eb7d1f36ce445bbc7 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Mon, 16 Jun 2014 16:41:58 +0200 Subject: [PATCH] Only cache strings, thanks --- lib/linguist/repository.rb | 37 ++++++++++++++----------------------- lib/linguist/version.rb | 2 +- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/lib/linguist/repository.rb b/lib/linguist/repository.rb index bbf32171..960ae3df 100644 --- a/lib/linguist/repository.rb +++ b/lib/linguist/repository.rb @@ -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,23 +96,14 @@ 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 - @old_stats - else - incremental_stats(@old_sha1, @current_sha1, @old_stats) - end + def cache + @cache ||= begin + if @old_sha1 == @current_sha1 + @old_stats + else + incremental_stats(@old_sha1, @current_sha1, @old_stats) + end + end end end end diff --git a/lib/linguist/version.rb b/lib/linguist/version.rb index 6704b3fb..ed7d57dc 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "2.12.0" + VERSION = "2.13.0.github2" end