Bust that cache

This commit is contained in:
Arfon Smith
2014-10-13 16:37:46 -05:00
parent 98e348ba5f
commit 653314448c
2 changed files with 24 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
require 'linguist/lazy_blob'
require 'rugged'
require 'pry'
module Linguist
# A Repository is an abstraction of a Grit::Repo or a basic file
# system tree. It holds a list of paths pointing to Blobish objects.
@@ -128,13 +128,23 @@ module Linguist
protected
def compute_stats(old_commit_oid, cache = nil)
file_map = cache ? cache.dup : {}
old_tree = old_commit_oid && Rugged::Commit.lookup(repository, old_commit_oid).tree
read_index
diff = Rugged::Tree.diff(repository, old_tree, current_tree)
# Clear file map and fetch full diff if any .gitattributes files are changed
if cache && diff.each_delta.any? { |delta| File.basename(delta.new_file[:path]) == ".gitattributes" }
diff = Rugged::Tree.diff(repository, old_tree = nil, current_tree)
file_map = {}
else
file_map = cache ? cache.dup : {}
end
# TODO - do we need to re-read the index?
# read_index
diff.each_delta do |delta|
old = delta.old_file[:path]
new = delta.new_file[:path]