From 0e86ab90448ffdd5a3ec2f3c0a6b22afaff933c1 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Thu, 11 Sep 2014 15:05:36 -0500 Subject: [PATCH 01/27] Version beta bump and some notes --- lib/linguist/version.rb | 2 +- test/test_repository.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/linguist/version.rb b/lib/linguist/version.rb index b5bd50de..390e0f86 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "3.1.5" + VERSION = "3.2.0b0" end diff --git a/test/test_repository.rb b/test/test_repository.rb index 4f7b938e..f2636871 100644 --- a/test/test_repository.rb +++ b/test/test_repository.rb @@ -1,5 +1,4 @@ require 'linguist/repository' - require 'test/unit' class TestRepository < Test::Unit::TestCase @@ -49,6 +48,11 @@ class TestRepository < Test::Unit::TestCase end def test_git_attributes + # See https://github.com/github/linguist/blob/525304738ebdb7ab3b7d2bf9a7514cc428faa273/.gitattributes + # + # It looks like this: + # test/*.rb linguist-ignore + # lib/linguist.rb linguist-lang=Java attr_commit = '525304738ebdb7ab3b7d2bf9a7514cc428faa273' repo = linguist_repo(attr_commit) From c49ce557144d855d85647f50ed342e04507b6939 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Wed, 17 Sep 2014 09:54:41 -0500 Subject: [PATCH 02/27] Bumping Rugged --- Gemfile | 2 +- lib/linguist/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index ac877cb6..4d7b99c2 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ source 'https://rubygems.org' gemspec -gem 'rugged', '0.21.1b0' +gem 'rugged', '0.21.1b1' diff --git a/lib/linguist/version.rb b/lib/linguist/version.rb index 390e0f86..82b1cf0d 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "3.2.0b0" + VERSION = "3.2.0b1" end From 178d4756efb647d5f8607d74fe47a852329d7516 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Wed, 24 Sep 2014 17:20:38 -0500 Subject: [PATCH 03/27] Changing up .gitattributes keys for testing --- .gitattributes | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..b524aadd --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +test/*.rb linguist-vendored +lib/linguist.rb linguist-language=Java +lib/linguist/classifier.rb linguist-generated From f87436d4990ea0b01d90c4634b19d238026bbdb0 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Wed, 24 Sep 2014 19:57:30 -0500 Subject: [PATCH 04/27] Adding linguist_vendored? and linguist_generated? to include overrides from .gitattributes --- lib/linguist/lazy_blob.rb | 12 ++++++++---- lib/linguist/repository.rb | 2 +- test/test_repository.rb | 37 ++++++++++++++++++++++++++++++------- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/lib/linguist/lazy_blob.rb b/lib/linguist/lazy_blob.rb index c7031283..26e1ae88 100644 --- a/lib/linguist/lazy_blob.rb +++ b/lib/linguist/lazy_blob.rb @@ -4,7 +4,7 @@ require 'rugged' module Linguist class LazyBlob - GIT_ATTR = ['linguist-ignore', 'linguist-lang'] + GIT_ATTR = ['linguist-language', 'linguist-vendored', 'linguist-generated'] GIT_ATTR_OPTS = { :priority => [:index], :skip_system => true } GIT_ATTR_FLAGS = Rugged::Repository::Attributes.parse_opts(GIT_ATTR_OPTS) @@ -29,12 +29,16 @@ module Linguist name, GIT_ATTR, GIT_ATTR_FLAGS) end - def ignored? - !!git_attributes['linguist-ignore'] + def linguist_vendored? + vendored? || !!git_attributes['linguist-vendored'] + end + + def linguist_generated? + generated? || !!git_attributes['linguist-generated'] end def overriden_language - if lang = git_attributes['linguist-lang'] + if lang = git_attributes['linguist-language'] Language.find_by_name(lang) end end diff --git a/lib/linguist/repository.rb b/lib/linguist/repository.rb index 9e0b7f1e..ae3dd1f3 100644 --- a/lib/linguist/repository.rb +++ b/lib/linguist/repository.rb @@ -142,7 +142,7 @@ module Linguist blob = Linguist::LazyBlob.new(repository, delta.new_file[:oid], new, mode.to_s(8)) # Skip vendored or generated blobs - next if blob.ignored? || blob.vendored? || blob.generated? || blob.language.nil? + next if blob.linguist_vendored? || blob.linguist_generated? || blob.language.nil? # Only include programming languages and acceptable markup languages if blob.language.type == :programming || Language.detectable_markup.include?(blob.language.name) diff --git a/test/test_repository.rb b/test/test_repository.rb index f2636871..39bec41a 100644 --- a/test/test_repository.rb +++ b/test/test_repository.rb @@ -1,6 +1,7 @@ require 'linguist/repository' +require 'linguist/lazy_blob' require 'test/unit' - +require 'pry' class TestRepository < Test::Unit::TestCase def rugged_repository @rugged ||= Rugged::Repository.new(File.expand_path("../../.git", __FILE__)) @@ -47,13 +48,15 @@ class TestRepository < Test::Unit::TestCase assert_equal linguist_repo.cache, new_repo.cache end - def test_git_attributes - # See https://github.com/github/linguist/blob/525304738ebdb7ab3b7d2bf9a7514cc428faa273/.gitattributes + def test_repo_git_attributes + # See https://github.com/github/linguist/blob/3770a90251c8a940367300c9f6f97bb64b369bf8/.gitattributes # # It looks like this: - # test/*.rb linguist-ignore - # lib/linguist.rb linguist-lang=Java - attr_commit = '525304738ebdb7ab3b7d2bf9a7514cc428faa273' + # test/*.rb linguist-vendored + # lib/linguist.rb linguist-language=Java + # lib/linguist/classifier.rb linguist-generated + + attr_commit = '178d4756efb647d5f8607d74fe47a852329d7516' repo = linguist_repo(attr_commit) assert repo.breakdown_by_file.has_key?("Java") @@ -62,7 +65,27 @@ class TestRepository < Test::Unit::TestCase assert repo.breakdown_by_file.has_key?("Ruby") assert !repo.breakdown_by_file["Ruby"].empty? repo.breakdown_by_file["Ruby"].each do |file| - assert !file.start_with?("test/") + assert !file.start_with?("test/"), "Failing for #{file}" end end + + def test_linguist_generated? + attr_commit = '178d4756efb647d5f8607d74fe47a852329d7516' + file = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'lib/linguist/classifier.rb') + + # overridden in .gitattributes + assert file.linguist_generated? + # from lib/linguist/generated.rb + assert !file.generated? + end + + def test_linguist_vendored? + attr_commit = '178d4756efb647d5f8607d74fe47a852329d7516' + file = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'test/test_md5.rb') + + # overridden .gitattributes + assert file.linguist_vendored? + # from lib/linguist/vendor.yml + assert !file.vendored? + end end From b533b682d5d4012ca42f4fc998b45169ec41fe33 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Thu, 25 Sep 2014 11:00:22 -0500 Subject: [PATCH 05/27] Test files for .gitattributes --- .gitattributes | 6 ++++-- test/fixtures/foo.rb | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/foo.rb diff --git a/.gitattributes b/.gitattributes index b524aadd..28e9d297 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,5 @@ -test/*.rb linguist-vendored +Gemfile linguist-vendored=true lib/linguist.rb linguist-language=Java -lib/linguist/classifier.rb linguist-generated +test/*.rb linguist-language=Java +Rakefile linguist-generated +test/fixtures/* linguist-vendored=false diff --git a/test/fixtures/foo.rb b/test/fixtures/foo.rb new file mode 100644 index 00000000..799c84bd --- /dev/null +++ b/test/fixtures/foo.rb @@ -0,0 +1,3 @@ +def foo + return "BAR" +end From 3ff1e38f6c3830827507b700e9ad27bf45ad038a Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Thu, 25 Sep 2014 12:50:42 -0500 Subject: [PATCH 06/27] Adding support for overriding configurations in vendor.yml and generated? --- lib/linguist/lazy_blob.rb | 23 +++++++++++++++--- test/test_repository.rb | 50 +++++++++++++++++++++++++++------------ 2 files changed, 55 insertions(+), 18 deletions(-) diff --git a/lib/linguist/lazy_blob.rb b/lib/linguist/lazy_blob.rb index 26e1ae88..1f16999d 100644 --- a/lib/linguist/lazy_blob.rb +++ b/lib/linguist/lazy_blob.rb @@ -1,7 +1,7 @@ require 'linguist/blob_helper' require 'linguist/language' require 'rugged' - +require 'pry' module Linguist class LazyBlob GIT_ATTR = ['linguist-language', 'linguist-vendored', 'linguist-generated'] @@ -30,11 +30,28 @@ module Linguist end def linguist_vendored? - vendored? || !!git_attributes['linguist-vendored'] + if git_attributes['linguist-vendored'] + return result_for_key('linguist-vendored') + else + return vendored? + end end def linguist_generated? - generated? || !!git_attributes['linguist-generated'] + if git_attributes['linguist-generated'] + return result_for_key('linguist-generated') + else + return generated? + end + end + + def result_for_key(keyname) + key = git_attributes[keyname] + if key == "false" + return false + else + return true + end end def overriden_language diff --git a/test/test_repository.rb b/test/test_repository.rb index 39bec41a..c0269d5d 100644 --- a/test/test_repository.rb +++ b/test/test_repository.rb @@ -49,14 +49,17 @@ class TestRepository < Test::Unit::TestCase end def test_repo_git_attributes - # See https://github.com/github/linguist/blob/3770a90251c8a940367300c9f6f97bb64b369bf8/.gitattributes + # See https://github.com/github/linguist/blob/b533b682d5d4012ca42f4fc998b45169ec41fe33/.gitattributes # # It looks like this: - # test/*.rb linguist-vendored + # Gemfile linguist-vendored=true # lib/linguist.rb linguist-language=Java - # lib/linguist/classifier.rb linguist-generated + # test/*.rb linguist-language=Java + # Rakefile linguist-generated + # test/fixtures/* linguist-vendored=false - attr_commit = '178d4756efb647d5f8607d74fe47a852329d7516' + + attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33' repo = linguist_repo(attr_commit) assert repo.breakdown_by_file.has_key?("Java") @@ -64,28 +67,45 @@ class TestRepository < Test::Unit::TestCase assert repo.breakdown_by_file.has_key?("Ruby") assert !repo.breakdown_by_file["Ruby"].empty? - repo.breakdown_by_file["Ruby"].each do |file| - assert !file.start_with?("test/"), "Failing for #{file}" - end end - def test_linguist_generated? - attr_commit = '178d4756efb647d5f8607d74fe47a852329d7516' - file = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'lib/linguist/classifier.rb') + def test_linguist_generated? + attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33' + file = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'Rakefile') + + + # check we're getting the correct assignment back from .gitattributes + assert file.result_for_key('linguist-generated') # overridden in .gitattributes assert file.linguist_generated? # from lib/linguist/generated.rb assert !file.generated? end - def test_linguist_vendored? - attr_commit = '178d4756efb647d5f8607d74fe47a852329d7516' - file = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'test/test_md5.rb') + def test_linguist_override_vendored? + attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33' + override_vendored = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'Gemfile') + # check we're getting the correct assignment back from .gitattributes + assert override_vendored.result_for_key('linguist-vendored') # overridden .gitattributes - assert file.linguist_vendored? + assert override_vendored.linguist_vendored? # from lib/linguist/vendor.yml - assert !file.vendored? + assert !override_vendored.vendored? + end + + def test_linguist_override_unvendored? + attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33' + + # lib/linguist/vendor.yml defines this as vendored. + override_unvendored = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'test/fixtures/foo.rb') + + # check we're getting the correct assignment back from .gitattributes + assert !override_unvendored.result_for_key('linguist-vendored') + # overridden .gitattributes + assert !override_unvendored.linguist_vendored? + # from lib/linguist/vendor.yml + assert override_unvendored.vendored? end end From b0db064d092e0903a0d35d3ab4cf948b4b3564db Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Thu, 25 Sep 2014 12:57:21 -0500 Subject: [PATCH 07/27] Updating .gitattributes for real usage --- .gitattributes | 6 +----- .gitignore | 1 - Gemfile.lock | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 Gemfile.lock diff --git a/.gitattributes b/.gitattributes index 28e9d297..00d664d9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1 @@ -Gemfile linguist-vendored=true -lib/linguist.rb linguist-language=Java -test/*.rb linguist-language=Java -Rakefile linguist-generated -test/fixtures/* linguist-vendored=false +Gemfile.lock linguist-generated=false diff --git a/.gitignore b/.gitignore index 391e05a0..fab9f4bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -Gemfile.lock .bundle/ vendor/ benchmark/ diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..20f5eadb --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,45 @@ +PATH + remote: . + specs: + github-linguist (3.2.0b1) + charlock_holmes (~> 0.7.3) + escape_utils (~> 1.0.1) + mime-types (~> 1.19) + pygments.rb (~> 0.6.0) + +GEM + remote: https://rubygems.org/ + specs: + charlock_holmes (0.7.3) + coderay (1.1.0) + escape_utils (1.0.1) + json (1.8.1) + metaclass (0.0.4) + method_source (0.8.2) + mime-types (1.25.1) + mocha (1.1.0) + metaclass (~> 0.0.1) + posix-spawn (0.3.9) + pry (0.10.1) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + pygments.rb (0.6.0) + posix-spawn (~> 0.3.6) + yajl-ruby (~> 1.1.0) + rake (10.3.2) + rugged (0.21.1b1) + slop (3.6.0) + yajl-ruby (1.1.0) + +PLATFORMS + ruby + +DEPENDENCIES + github-linguist! + json + mocha + pry + rake + rugged (= 0.21.1b1) + yajl-ruby From 5284608942d21ff7040848ca200308470d9a5df7 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Thu, 25 Sep 2014 13:37:20 -0500 Subject: [PATCH 09/27] Stubbing git attributes (for now) --- lib/linguist/lazy_blob.rb | 2 +- test/test_repository.rb | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/linguist/lazy_blob.rb b/lib/linguist/lazy_blob.rb index 1f16999d..dd9e94ab 100644 --- a/lib/linguist/lazy_blob.rb +++ b/lib/linguist/lazy_blob.rb @@ -47,7 +47,7 @@ module Linguist def result_for_key(keyname) key = git_attributes[keyname] - if key == "false" + if key == "false" || key.nil? return false else return true diff --git a/test/test_repository.rb b/test/test_repository.rb index c0269d5d..d2ce510a 100644 --- a/test/test_repository.rb +++ b/test/test_repository.rb @@ -1,7 +1,7 @@ require 'linguist/repository' require 'linguist/lazy_blob' require 'test/unit' -require 'pry' + class TestRepository < Test::Unit::TestCase def rugged_repository @rugged ||= Rugged::Repository.new(File.expand_path("../../.git", __FILE__)) @@ -58,7 +58,6 @@ class TestRepository < Test::Unit::TestCase # Rakefile linguist-generated # test/fixtures/* linguist-vendored=false - attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33' repo = linguist_repo(attr_commit) @@ -72,8 +71,15 @@ class TestRepository < Test::Unit::TestCase def test_linguist_generated? attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33' + file = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'Rakefile') + git_attrs = { "linguist-language" => nil, + "linguist-vendored" => nil, + "linguist-generated"=> true } + + # TODO: get rid of this (would like this to come from git data) + file.stubs(:git_attributes).returns(git_attrs) # check we're getting the correct assignment back from .gitattributes assert file.result_for_key('linguist-generated') @@ -87,6 +93,13 @@ class TestRepository < Test::Unit::TestCase attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33' override_vendored = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'Gemfile') + git_attrs = { "linguist-language" => nil, + "linguist-vendored" => true, + "linguist-generated"=> nil } + + # TODO: get rid of this (would like this to come from git data) + override_vendored.stubs(:git_attributes).returns(git_attrs) + # check we're getting the correct assignment back from .gitattributes assert override_vendored.result_for_key('linguist-vendored') # overridden .gitattributes @@ -101,6 +114,13 @@ class TestRepository < Test::Unit::TestCase # lib/linguist/vendor.yml defines this as vendored. override_unvendored = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'test/fixtures/foo.rb') + git_attrs = { "linguist-language" => nil, + "linguist-vendored" => "false", + "linguist-generated"=> nil } + + # TODO: get rid of this (would like this to come from git data) + override_unvendored.stubs(:git_attributes).returns(git_attrs) + # check we're getting the correct assignment back from .gitattributes assert !override_unvendored.result_for_key('linguist-vendored') # overridden .gitattributes From 2e3e8c5b8958b89e103a5084e35256bc144d9c88 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Thu, 25 Sep 2014 13:55:14 -0500 Subject: [PATCH 10/27] Removing pry --- lib/linguist/lazy_blob.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/lazy_blob.rb b/lib/linguist/lazy_blob.rb index dd9e94ab..131cafcf 100644 --- a/lib/linguist/lazy_blob.rb +++ b/lib/linguist/lazy_blob.rb @@ -1,7 +1,7 @@ require 'linguist/blob_helper' require 'linguist/language' require 'rugged' -require 'pry' + module Linguist class LazyBlob GIT_ATTR = ['linguist-language', 'linguist-vendored', 'linguist-generated'] From b160a396789549c65f6366e3cbf5647348793377 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Mon, 29 Sep 2014 13:48:40 -0400 Subject: [PATCH 11/27] Remove linguist_* prefix from vendored? and generated? --- lib/linguist/lazy_blob.rb | 8 ++++---- lib/linguist/repository.rb | 2 +- test/test_repository.rb | 14 ++++---------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/lib/linguist/lazy_blob.rb b/lib/linguist/lazy_blob.rb index 131cafcf..3ece29f2 100644 --- a/lib/linguist/lazy_blob.rb +++ b/lib/linguist/lazy_blob.rb @@ -29,19 +29,19 @@ module Linguist name, GIT_ATTR, GIT_ATTR_FLAGS) end - def linguist_vendored? + def vendored? if git_attributes['linguist-vendored'] return result_for_key('linguist-vendored') else - return vendored? + return super end end - def linguist_generated? + def generated? if git_attributes['linguist-generated'] return result_for_key('linguist-generated') else - return generated? + return super end end diff --git a/lib/linguist/repository.rb b/lib/linguist/repository.rb index ae3dd1f3..f2bcb785 100644 --- a/lib/linguist/repository.rb +++ b/lib/linguist/repository.rb @@ -142,7 +142,7 @@ module Linguist blob = Linguist::LazyBlob.new(repository, delta.new_file[:oid], new, mode.to_s(8)) # Skip vendored or generated blobs - next if blob.linguist_vendored? || blob.linguist_generated? || blob.language.nil? + next if blob.vendored? || blob.generated? || blob.language.nil? # Only include programming languages and acceptable markup languages if blob.language.type == :programming || Language.detectable_markup.include?(blob.language.name) diff --git a/test/test_repository.rb b/test/test_repository.rb index d2ce510a..dbd7e3a9 100644 --- a/test/test_repository.rb +++ b/test/test_repository.rb @@ -69,7 +69,7 @@ class TestRepository < Test::Unit::TestCase end - def test_linguist_generated? + def test_linguist_override_generated? attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33' file = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'Rakefile') @@ -84,9 +84,7 @@ class TestRepository < Test::Unit::TestCase # check we're getting the correct assignment back from .gitattributes assert file.result_for_key('linguist-generated') # overridden in .gitattributes - assert file.linguist_generated? - # from lib/linguist/generated.rb - assert !file.generated? + assert file.generated? end def test_linguist_override_vendored? @@ -103,9 +101,7 @@ class TestRepository < Test::Unit::TestCase # check we're getting the correct assignment back from .gitattributes assert override_vendored.result_for_key('linguist-vendored') # overridden .gitattributes - assert override_vendored.linguist_vendored? - # from lib/linguist/vendor.yml - assert !override_vendored.vendored? + assert override_vendored.vendored? end def test_linguist_override_unvendored? @@ -124,8 +120,6 @@ class TestRepository < Test::Unit::TestCase # check we're getting the correct assignment back from .gitattributes assert !override_unvendored.result_for_key('linguist-vendored') # overridden .gitattributes - assert !override_unvendored.linguist_vendored? - # from lib/linguist/vendor.yml - assert override_unvendored.vendored? + assert !override_unvendored.vendored? end end From 6edf4498ce53bcb057191d02c5df92731b311da2 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Mon, 29 Sep 2014 14:12:36 -0400 Subject: [PATCH 12/27] Move overridden_language to just #language --- lib/linguist/lazy_blob.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/linguist/lazy_blob.rb b/lib/linguist/lazy_blob.rb index 3ece29f2..6b2e5e47 100644 --- a/lib/linguist/lazy_blob.rb +++ b/lib/linguist/lazy_blob.rb @@ -53,15 +53,14 @@ module Linguist return true end end - - def overriden_language - if lang = git_attributes['linguist-language'] - Language.find_by_name(lang) - end - end - def language - @language ||= (overriden_language || Language.detect(self)) + return @language if defined?(@language) + + @language = if lang = git_attributes['linguist-language'] + Language.find_by_name(lang) + else + super + end end def data From 1c6483a499aa6374c2b11ade558e54f0873fd92e Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Mon, 29 Sep 2014 14:13:44 -0400 Subject: [PATCH 13/27] Simplify boolean attribute handling --- lib/linguist/lazy_blob.rb | 22 ++++++++++------------ test/test_repository.rb | 6 ------ 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/lib/linguist/lazy_blob.rb b/lib/linguist/lazy_blob.rb index 6b2e5e47..807312f9 100644 --- a/lib/linguist/lazy_blob.rb +++ b/lib/linguist/lazy_blob.rb @@ -30,29 +30,21 @@ module Linguist end def vendored? - if git_attributes['linguist-vendored'] - return result_for_key('linguist-vendored') + if attr = git_attributes['linguist-vendored'] + return boolean_attribute(attr) else return super end end def generated? - if git_attributes['linguist-generated'] - return result_for_key('linguist-generated') + if attr = git_attributes['linguist-generated'] + return boolean_attribute(attr) else return super end end - def result_for_key(keyname) - key = git_attributes[keyname] - if key == "false" || key.nil? - return false - else - return true - end - end def language return @language if defined?(@language) @@ -74,6 +66,12 @@ module Linguist end protected + + # Returns true if the attribute is present and not the string "false". + def boolean_attribute(attr) + attr != "false" + end + def load_blob! @data, @size = Rugged::Blob.to_buffer(repository, oid, MAX_SIZE) if @data.nil? end diff --git a/test/test_repository.rb b/test/test_repository.rb index dbd7e3a9..3401d655 100644 --- a/test/test_repository.rb +++ b/test/test_repository.rb @@ -81,8 +81,6 @@ class TestRepository < Test::Unit::TestCase # TODO: get rid of this (would like this to come from git data) file.stubs(:git_attributes).returns(git_attrs) - # check we're getting the correct assignment back from .gitattributes - assert file.result_for_key('linguist-generated') # overridden in .gitattributes assert file.generated? end @@ -98,8 +96,6 @@ class TestRepository < Test::Unit::TestCase # TODO: get rid of this (would like this to come from git data) override_vendored.stubs(:git_attributes).returns(git_attrs) - # check we're getting the correct assignment back from .gitattributes - assert override_vendored.result_for_key('linguist-vendored') # overridden .gitattributes assert override_vendored.vendored? end @@ -117,8 +113,6 @@ class TestRepository < Test::Unit::TestCase # TODO: get rid of this (would like this to come from git data) override_unvendored.stubs(:git_attributes).returns(git_attrs) - # check we're getting the correct assignment back from .gitattributes - assert !override_unvendored.result_for_key('linguist-vendored') # overridden .gitattributes assert !override_unvendored.vendored? end From 2b411aad90b1b296b55eb39a4c1ad75c9a49b7ba Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Mon, 29 Sep 2014 15:04:48 -0400 Subject: [PATCH 14/27] Extract #read_index for tests --- lib/linguist/repository.rb | 22 +++++++++++++++------- test/test_repository.rb | 26 ++++---------------------- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/lib/linguist/repository.rb b/lib/linguist/repository.rb index f2bcb785..1f9e09c4 100644 --- a/lib/linguist/repository.rb +++ b/lib/linguist/repository.rb @@ -110,22 +110,30 @@ module Linguist if @old_commit_oid == @commit_oid @old_stats else - compute_stats(@old_commit_oid, @commit_oid, @old_stats) + compute_stats(@old_commit_oid, @old_stats) end end end + def read_index + attr_index = Rugged::Index.new + attr_index.read_tree(current_tree) + repository.index = attr_index + end + + def current_tree + @tree ||= Rugged::Commit.lookup(repository, @commit_oid).tree + end + protected - def compute_stats(old_commit_oid, commit_oid, cache = nil) + + 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 - new_tree = Rugged::Commit.lookup(repository, commit_oid).tree - diff = Rugged::Tree.diff(repository, old_tree, new_tree) + read_index - attr_index = Rugged::Index.new - attr_index.read_tree(new_tree) - repository.index = attr_index + diff = Rugged::Tree.diff(repository, old_tree, current_tree) diff.each_delta do |delta| old = delta.old_file[:path] diff --git a/test/test_repository.rb b/test/test_repository.rb index 3401d655..13155796 100644 --- a/test/test_repository.rb +++ b/test/test_repository.rb @@ -68,51 +68,33 @@ class TestRepository < Test::Unit::TestCase assert !repo.breakdown_by_file["Ruby"].empty? end - def test_linguist_override_generated? attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33' + linguist_repo(attr_commit).read_index file = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'Rakefile') - git_attrs = { "linguist-language" => nil, - "linguist-vendored" => nil, - "linguist-generated"=> true } - - # TODO: get rid of this (would like this to come from git data) - file.stubs(:git_attributes).returns(git_attrs) - # overridden in .gitattributes assert file.generated? end def test_linguist_override_vendored? attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33' + repo = linguist_repo(attr_commit).read_index + override_vendored = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'Gemfile') - git_attrs = { "linguist-language" => nil, - "linguist-vendored" => true, - "linguist-generated"=> nil } - - # TODO: get rid of this (would like this to come from git data) - override_vendored.stubs(:git_attributes).returns(git_attrs) - # overridden .gitattributes assert override_vendored.vendored? end def test_linguist_override_unvendored? attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33' + repo = linguist_repo(attr_commit).read_index # lib/linguist/vendor.yml defines this as vendored. override_unvendored = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'test/fixtures/foo.rb') - git_attrs = { "linguist-language" => nil, - "linguist-vendored" => "false", - "linguist-generated"=> nil } - - # TODO: get rid of this (would like this to come from git data) - override_unvendored.stubs(:git_attributes).returns(git_attrs) - # overridden .gitattributes assert !override_unvendored.vendored? end From 0cd7d85ec46638c5050005c769960ad38703c98a Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Mon, 29 Sep 2014 15:10:01 -0500 Subject: [PATCH 15/27] Using .gitattributes from test branch --- test/test_repository.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/test_repository.rb b/test/test_repository.rb index 13155796..55ba91ad 100644 --- a/test/test_repository.rb +++ b/test/test_repository.rb @@ -49,7 +49,7 @@ class TestRepository < Test::Unit::TestCase end def test_repo_git_attributes - # See https://github.com/github/linguist/blob/b533b682d5d4012ca42f4fc998b45169ec41fe33/.gitattributes + # See https://github.com/github/linguist/blob/7ee006cbcb2d7261f9e648510a684ee9ac64126b/.gitattributes # # It looks like this: # Gemfile linguist-vendored=true @@ -58,7 +58,7 @@ class TestRepository < Test::Unit::TestCase # Rakefile linguist-generated # test/fixtures/* linguist-vendored=false - attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33' + attr_commit = '7ee006cbcb2d7261f9e648510a684ee9ac64126b' repo = linguist_repo(attr_commit) assert repo.breakdown_by_file.has_key?("Java") @@ -69,7 +69,7 @@ class TestRepository < Test::Unit::TestCase end def test_linguist_override_generated? - attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33' + attr_commit = '7ee006cbcb2d7261f9e648510a684ee9ac64126b' linguist_repo(attr_commit).read_index file = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'Rakefile') @@ -79,7 +79,7 @@ class TestRepository < Test::Unit::TestCase end def test_linguist_override_vendored? - attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33' + attr_commit = '7ee006cbcb2d7261f9e648510a684ee9ac64126b' repo = linguist_repo(attr_commit).read_index override_vendored = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'Gemfile') @@ -89,7 +89,7 @@ class TestRepository < Test::Unit::TestCase end def test_linguist_override_unvendored? - attr_commit = 'b533b682d5d4012ca42f4fc998b45169ec41fe33' + attr_commit = '7ee006cbcb2d7261f9e648510a684ee9ac64126b' repo = linguist_repo(attr_commit).read_index # lib/linguist/vendor.yml defines this as vendored. From 9d0ba5801b8acebb0b318eb0405aff2e895f10c0 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Mon, 29 Sep 2014 15:11:44 -0500 Subject: [PATCH 16/27] Reverting b0db064d092e0903a0d35d3ab4cf948b4b3564db now we have a better way to test these attributes --- .gitattributes | 1 - .gitignore | 1 + Gemfile.lock | 45 --------------------------------------------- 3 files changed, 1 insertion(+), 46 deletions(-) delete mode 100644 Gemfile.lock diff --git a/.gitattributes b/.gitattributes index 00d664d9..e69de29b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +0,0 @@ -Gemfile.lock linguist-generated=false diff --git a/.gitignore b/.gitignore index fab9f4bc..391e05a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +Gemfile.lock .bundle/ vendor/ benchmark/ diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 20f5eadb..00000000 --- a/Gemfile.lock +++ /dev/null @@ -1,45 +0,0 @@ -PATH - remote: . - specs: - github-linguist (3.2.0b1) - charlock_holmes (~> 0.7.3) - escape_utils (~> 1.0.1) - mime-types (~> 1.19) - pygments.rb (~> 0.6.0) - -GEM - remote: https://rubygems.org/ - specs: - charlock_holmes (0.7.3) - coderay (1.1.0) - escape_utils (1.0.1) - json (1.8.1) - metaclass (0.0.4) - method_source (0.8.2) - mime-types (1.25.1) - mocha (1.1.0) - metaclass (~> 0.0.1) - posix-spawn (0.3.9) - pry (0.10.1) - coderay (~> 1.1.0) - method_source (~> 0.8.1) - slop (~> 3.4) - pygments.rb (0.6.0) - posix-spawn (~> 0.3.6) - yajl-ruby (~> 1.1.0) - rake (10.3.2) - rugged (0.21.1b1) - slop (3.6.0) - yajl-ruby (1.1.0) - -PLATFORMS - ruby - -DEPENDENCIES - github-linguist! - json - mocha - pry - rake - rugged (= 0.21.1b1) - yajl-ruby From 2e4e6027870a5c1b253a1a0361d6a6fd7e5401eb Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Mon, 29 Sep 2014 15:20:11 -0500 Subject: [PATCH 17/27] Housekeeping --- Rakefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Rakefile b/Rakefile index 9c3aa2ee..bd5788f6 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,6 @@ require 'json' require 'rake/clean' require 'rake/testtask' require 'yaml' -require 'pry' task :default => :test From 09323c8bbc3a39f2a8c5bb51c2677f8e83f6e8f1 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Mon, 29 Sep 2014 15:28:00 -0500 Subject: [PATCH 18/27] Version bump --- 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 82b1cf0d..8612cf1d 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "3.2.0b1" + VERSION = "3.2.0b2" end From d1d5c61df5043fe909cee5975fc254e70e8b9f56 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Mon, 29 Sep 2014 16:27:20 -0500 Subject: [PATCH 19/27] Updating ref for gitattribute testing --- test/test_repository.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/test_repository.rb b/test/test_repository.rb index 55ba91ad..9cd54598 100644 --- a/test/test_repository.rb +++ b/test/test_repository.rb @@ -49,7 +49,7 @@ class TestRepository < Test::Unit::TestCase end def test_repo_git_attributes - # See https://github.com/github/linguist/blob/7ee006cbcb2d7261f9e648510a684ee9ac64126b/.gitattributes + # See https://github.com/github/linguist/blob/351c1cc8fd57340839bdb400d7812332af80e9bd/.gitattributes # # It looks like this: # Gemfile linguist-vendored=true @@ -58,7 +58,7 @@ class TestRepository < Test::Unit::TestCase # Rakefile linguist-generated # test/fixtures/* linguist-vendored=false - attr_commit = '7ee006cbcb2d7261f9e648510a684ee9ac64126b' + attr_commit = '351c1cc8fd57340839bdb400d7812332af80e9bd' repo = linguist_repo(attr_commit) assert repo.breakdown_by_file.has_key?("Java") @@ -69,7 +69,7 @@ class TestRepository < Test::Unit::TestCase end def test_linguist_override_generated? - attr_commit = '7ee006cbcb2d7261f9e648510a684ee9ac64126b' + attr_commit = '351c1cc8fd57340839bdb400d7812332af80e9bd' linguist_repo(attr_commit).read_index file = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'Rakefile') @@ -79,7 +79,7 @@ class TestRepository < Test::Unit::TestCase end def test_linguist_override_vendored? - attr_commit = '7ee006cbcb2d7261f9e648510a684ee9ac64126b' + attr_commit = '351c1cc8fd57340839bdb400d7812332af80e9bd' repo = linguist_repo(attr_commit).read_index override_vendored = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'Gemfile') @@ -89,7 +89,7 @@ class TestRepository < Test::Unit::TestCase end def test_linguist_override_unvendored? - attr_commit = '7ee006cbcb2d7261f9e648510a684ee9ac64126b' + attr_commit = '351c1cc8fd57340839bdb400d7812332af80e9bd' repo = linguist_repo(attr_commit).read_index # lib/linguist/vendor.yml defines this as vendored. From 77126e9e1783655516a270fdab560f0842b1bdec Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Mon, 29 Sep 2014 16:28:23 -0500 Subject: [PATCH 20/27] Removing fixture file --- test/fixtures/foo.rb | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 test/fixtures/foo.rb diff --git a/test/fixtures/foo.rb b/test/fixtures/foo.rb deleted file mode 100644 index 799c84bd..00000000 --- a/test/fixtures/foo.rb +++ /dev/null @@ -1,3 +0,0 @@ -def foo - return "BAR" -end From 03bb48cf2870e6f52644ae55dafe471f3c6b9514 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Tue, 30 Sep 2014 08:42:08 -0500 Subject: [PATCH 21/27] Version bump --- 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 8612cf1d..6d80c2a1 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "3.2.0b2" + VERSION = "3.2.0b3" end From 332d97b57f538dca007ab4bf9108b5aead1d5515 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Fri, 10 Oct 2014 15:32:08 -0500 Subject: [PATCH 22/27] Removing generated override for now. --- lib/linguist/lazy_blob.rb | 8 -------- test/test_repository.rb | 10 ---------- 2 files changed, 18 deletions(-) diff --git a/lib/linguist/lazy_blob.rb b/lib/linguist/lazy_blob.rb index 807312f9..9db67c76 100644 --- a/lib/linguist/lazy_blob.rb +++ b/lib/linguist/lazy_blob.rb @@ -37,14 +37,6 @@ module Linguist end end - def generated? - if attr = git_attributes['linguist-generated'] - return boolean_attribute(attr) - else - return super - end - end - def language return @language if defined?(@language) diff --git a/test/test_repository.rb b/test/test_repository.rb index 9cd54598..8e10e9b6 100644 --- a/test/test_repository.rb +++ b/test/test_repository.rb @@ -68,16 +68,6 @@ class TestRepository < Test::Unit::TestCase assert !repo.breakdown_by_file["Ruby"].empty? end - def test_linguist_override_generated? - attr_commit = '351c1cc8fd57340839bdb400d7812332af80e9bd' - linguist_repo(attr_commit).read_index - - file = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'Rakefile') - - # overridden in .gitattributes - assert file.generated? - end - def test_linguist_override_vendored? attr_commit = '351c1cc8fd57340839bdb400d7812332af80e9bd' repo = linguist_repo(attr_commit).read_index From c8cb7b7cabb74124f433328bca596c36c9f41839 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Fri, 10 Oct 2014 15:33:47 -0500 Subject: [PATCH 23/27] Git attr --- lib/linguist/lazy_blob.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/lazy_blob.rb b/lib/linguist/lazy_blob.rb index 9db67c76..9691bca5 100644 --- a/lib/linguist/lazy_blob.rb +++ b/lib/linguist/lazy_blob.rb @@ -4,7 +4,7 @@ require 'rugged' module Linguist class LazyBlob - GIT_ATTR = ['linguist-language', 'linguist-vendored', 'linguist-generated'] + GIT_ATTR = ['linguist-language', 'linguist-vendored'] GIT_ATTR_OPTS = { :priority => [:index], :skip_system => true } GIT_ATTR_FLAGS = Rugged::Repository::Attributes.parse_opts(GIT_ATTR_OPTS) From ffc0be191e3b6c0665c801b9aa0df2df6283833c Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Mon, 13 Oct 2014 08:42:46 -0500 Subject: [PATCH 24/27] 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 6d80c2a1..c9f2cea6 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "3.2.0b3" + VERSION = "3.2.0" end From df703ef997dd84d74d013dcc8c659d060fa67a0c Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Mon, 13 Oct 2014 09:09:33 -0500 Subject: [PATCH 25/27] Rugged bump --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 4d7b99c2..fd049899 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ source 'https://rubygems.org' gemspec -gem 'rugged', '0.21.1b1' +gem 'rugged', '0.21.1b2' From f7386fcd727518c962e9ecc6535a705506cda283 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Mon, 13 Oct 2014 09:09:33 -0500 Subject: [PATCH 26/27] Rugged bump --- Gemfile | 2 +- lib/linguist/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 4d7b99c2..fd049899 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ source 'https://rubygems.org' gemspec -gem 'rugged', '0.21.1b1' +gem 'rugged', '0.21.1b2' diff --git a/lib/linguist/version.rb b/lib/linguist/version.rb index c9f2cea6..3751ff02 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "3.2.0" + VERSION = "3.2.0b4" end From bcb016a9383428957373c53264ac50419a57b7e7 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Mon, 13 Oct 2014 09:30:09 -0500 Subject: [PATCH 27/27] 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 3751ff02..c9f2cea6 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "3.2.0b4" + VERSION = "3.2.0" end