From 653314448c7c6f6ec2f93de346896895f786773f Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Mon, 13 Oct 2014 16:37:46 -0500 Subject: [PATCH 1/8] Bust that cache --- lib/linguist/repository.rb | 14 ++++++++++++-- test/test_repository.rb | 12 ++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/linguist/repository.rb b/lib/linguist/repository.rb index 1f9e09c4..9998ee61 100644 --- a/lib/linguist/repository.rb +++ b/lib/linguist/repository.rb @@ -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] diff --git a/test/test_repository.rb b/test/test_repository.rb index 8e10e9b6..5dfcefcb 100644 --- a/test/test_repository.rb +++ b/test/test_repository.rb @@ -68,6 +68,18 @@ class TestRepository < Test::Unit::TestCase assert !repo.breakdown_by_file["Ruby"].empty? end + def test_commit_with_git_attributes_data + old_commit = '3d7364877d6794f6cc2a86b493e893968a597332' + old_repo = linguist_repo(old_commit) + + attr_commit = '7ee006cbcb2d7261f9e648510a684ee9ac64126b' + new_repo = Linguist::Repository.incremental(rugged_repository, attr_commit, old_commit, old_repo.cache) + + Rugged::Tree.expects(:diff).twice + + new_repo.send(:compute_stats, old_commit, old_repo.cache) + end + def test_linguist_override_vendored? attr_commit = '351c1cc8fd57340839bdb400d7812332af80e9bd' repo = linguist_repo(attr_commit).read_index From 5cc053694abb213f3d167b2f2dc61bd869144081 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Mon, 13 Oct 2014 16:38:21 -0500 Subject: [PATCH 2/8] Remove pry --- lib/linguist/repository.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/repository.rb b/lib/linguist/repository.rb index 9998ee61..288d7f34 100644 --- a/lib/linguist/repository.rb +++ b/lib/linguist/repository.rb @@ -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. From 7aabc6a5ad2a4739074308de0e9dbd25cc48c1bb Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Mon, 13 Oct 2014 17:01:53 -0500 Subject: [PATCH 3/8] A different approach --- test/test_repository.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/test_repository.rb b/test/test_repository.rb index 5dfcefcb..1fba9b57 100644 --- a/test/test_repository.rb +++ b/test/test_repository.rb @@ -69,15 +69,16 @@ class TestRepository < Test::Unit::TestCase end def test_commit_with_git_attributes_data - old_commit = '3d7364877d6794f6cc2a86b493e893968a597332' + # Before we had any .gitattributes data + old_commit = '4a017d9033f91b2776eb85275463f9613cc371ef' old_repo = linguist_repo(old_commit) + # With some .gitattributes data attr_commit = '7ee006cbcb2d7261f9e648510a684ee9ac64126b' + # It's incremental but should bust the cache new_repo = Linguist::Repository.incremental(rugged_repository, attr_commit, old_commit, old_repo.cache) - Rugged::Tree.expects(:diff).twice - - new_repo.send(:compute_stats, old_commit, old_repo.cache) + assert new_repo.breakdown_by_file["Java"].include?("lib/linguist.rb") end def test_linguist_override_vendored? From e87b89ab5b0e3dbbcf21bea8142e6cfe807baa95 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Mon, 13 Oct 2014 18:52:27 -0500 Subject: [PATCH 4/8] Removing todo --- lib/linguist/repository.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/linguist/repository.rb b/lib/linguist/repository.rb index 288d7f34..41e829c5 100644 --- a/lib/linguist/repository.rb +++ b/lib/linguist/repository.rb @@ -142,9 +142,6 @@ module Linguist 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] From 3087d640a33b84e3a449b5f77d06f4876fc6bafb Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Mon, 13 Oct 2014 19:33:03 -0500 Subject: [PATCH 5/8] 3.2.2b1 --- lib/linguist/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/version.rb b/lib/linguist/version.rb index 9c3344f1..a9c61cd4 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "3.2.1" + VERSION = "3.2.2b1" end From d7b19d577b7eee4f757812cba689998d59451237 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Tue, 14 Oct 2014 19:44:35 -0500 Subject: [PATCH 6/8] Bumping version --- lib/linguist/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/version.rb b/lib/linguist/version.rb index 43dabaf5..837a7968 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "3.3.0.b2" + VERSION = "3.4.0b1" end From 8dd2ddcbf70a719832b39fb8cc56af2812bd1501 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Tue, 14 Oct 2014 20:18:32 -0500 Subject: [PATCH 7/8] CI --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3fba928a..241b4aee 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ The repository stats API, accessed through `#languages`, can be used on a direct ***API UPDATE*** -Since [Version 3.0.0](https://github.com/github/linguist/releases/tag/v3.0.0) Linguist requires a git repository (in the form of a [Rugged::Repository](https://github.com/libgit2/rugged#repositories)) to be passed when initializing `Linguist::Repository`. +Since [Version 3.0.0](https://github.com/github/linguist/releases/tag/v3.0.0) Linguist expects a git repository (in the form of a [Rugged::Repository](https://github.com/libgit2/rugged#repositories)) to be passed when initializing `Linguist::Repository`. ```ruby From fd9d63d60549a081201be3ccf8f5a4040c19de21 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Thu, 16 Oct 2014 14:05:36 -0500 Subject: [PATCH 8/8] Removing beta label --- lib/linguist/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/version.rb b/lib/linguist/version.rb index 837a7968..12d2ceb3 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "3.4.0b1" + VERSION = "3.4.0" end