From 01be9e68ee7fa8169aab805f0b6db5840549c106 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Tue, 20 Jan 2015 14:34:36 -0600 Subject: [PATCH 1/6] Revert "Revert "Use path for Generated?"" --- lib/linguist/blob_helper.rb | 6 +++--- lib/linguist/file_blob.rb | 27 +++++++++++++++++---------- lib/linguist/lazy_blob.rb | 8 +++++--- test/test_blob.rb | 14 ++++++++++++-- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb index c368b4d0..07e1ee52 100644 --- a/lib/linguist/blob_helper.rb +++ b/lib/linguist/blob_helper.rb @@ -99,7 +99,7 @@ module Linguist elsif name.nil? "attachment" else - "attachment; filename=#{EscapeUtils.escape_url(File.basename(name))}" + "attachment; filename=#{EscapeUtils.escape_url(name)}" end end @@ -233,7 +233,7 @@ module Linguist # # Return true or false def vendored? - name =~ VendoredRegexp ? true : false + path =~ VendoredRegexp ? true : false end # Public: Get each line of data @@ -301,7 +301,7 @@ module Linguist # # Return true or false def generated? - @_generated ||= Generated.generated?(name, lambda { data }) + @_generated ||= Generated.generated?(path, lambda { data }) end # Public: Detects the Language of the blob. diff --git a/lib/linguist/file_blob.rb b/lib/linguist/file_blob.rb index 04441935..2ca74c2d 100644 --- a/lib/linguist/file_blob.rb +++ b/lib/linguist/file_blob.rb @@ -3,7 +3,7 @@ require 'linguist/blob_helper' module Linguist # A FileBlob is a wrapper around a File object to make it quack # like a Grit::Blob. It provides the basic interface: `name`, - # `data`, and `size`. + # `data`, `path` and `size`. class FileBlob include BlobHelper @@ -14,43 +14,50 @@ module Linguist # # Returns a FileBlob. def initialize(path, base_path = nil) - @path = path - @name = base_path ? path.sub("#{base_path}/", '') : path + @fullpath = path + @path = base_path ? path.sub("#{base_path}/", '') : path end # Public: Filename # # Examples # - # FileBlob.new("/path/to/linguist/lib/linguist.rb").name + # FileBlob.new("/path/to/linguist/lib/linguist.rb").path # # => "/path/to/linguist/lib/linguist.rb" # # FileBlob.new("/path/to/linguist/lib/linguist.rb", - # "/path/to/linguist").name + # "/path/to/linguist").path # # => "lib/linguist.rb" # # Returns a String - attr_reader :name + attr_reader :path # Public: Read file permissions # # Returns a String like '100644' def mode - File.stat(@path).mode.to_s(8) + File.stat(@fullpath).mode.to_s(8) + end + + # Public: File name + # + # Returns a String + def name + File.basename(@fullpath) end # Public: Read file contents. # # Returns a String. def data - File.read(@path) + File.read(@fullpath) end # Public: Get byte size # # Returns an Integer. def size - File.size(@path) + File.size(@fullpath) end # Public: Get file extension. @@ -67,7 +74,7 @@ module Linguist # # Returns an Array def extensions - basename, *segments = File.basename(name).split(".") + basename, *segments = name.split(".") segments.map.with_index do |segment, index| "." + segments[index..-1].join(".") diff --git a/lib/linguist/lazy_blob.rb b/lib/linguist/lazy_blob.rb index 9691bca5..ab6c4bee 100644 --- a/lib/linguist/lazy_blob.rb +++ b/lib/linguist/lazy_blob.rb @@ -14,13 +14,15 @@ module Linguist attr_reader :repository attr_reader :oid - attr_reader :name + attr_reader :path attr_reader :mode - def initialize(repo, oid, name, mode = nil) + alias :name :path + + def initialize(repo, oid, path, mode = nil) @repository = repo @oid = oid - @name = name + @path = path @mode = mode end diff --git a/test/test_blob.rb b/test/test_blob.rb index 372ff13f..4c4f7978 100644 --- a/test/test_blob.rb +++ b/test/test_blob.rb @@ -251,8 +251,7 @@ class TestBlob < Minitest::Test assert sample_blob("Zephir/filenames/exception.zep.php").generated? assert !sample_blob("Zephir/Router.zep").generated? - - assert Linguist::Generated.generated?("node_modules/grunt/lib/grunt.js", nil) + assert sample_blob("node_modules/grunt/lib/grunt.js").generated? # Godep saved dependencies assert sample_blob("Godeps/Godeps.json").generated? @@ -292,6 +291,8 @@ class TestBlob < Minitest::Test assert sample_blob("deps/http_parser/http_parser.c").vendored? assert sample_blob("deps/v8/src/v8.h").vendored? + assert sample_blob("tools/something/else.c").vendored? + # Chart.js assert sample_blob("some/vendored/path/Chart.js").vendored? assert !sample_blob("some/vendored/path/chart.js").vendored? @@ -302,6 +303,9 @@ class TestBlob < Minitest::Test # Debian packaging assert sample_blob("debian/cron.d").vendored? + # Erlang + assert sample_blob("rebar").vendored? + # Minified JavaScript and CSS assert sample_blob("foo.min.js").vendored? assert sample_blob("foo.min.css").vendored? @@ -310,6 +314,9 @@ class TestBlob < Minitest::Test assert !sample_blob("foomin.css").vendored? assert !sample_blob("foo.min.txt").vendored? + #.osx + assert sample_blob(".osx").vendored? + # Prototype assert !sample_blob("public/javascripts/application.js").vendored? assert sample_blob("public/javascripts/prototype.js").vendored? @@ -317,6 +324,9 @@ class TestBlob < Minitest::Test assert sample_blob("public/javascripts/controls.js").vendored? assert sample_blob("public/javascripts/dragdrop.js").vendored? + # Samples + assert sample_blob("Samples/Ruby/foo.rb").vendored? + # jQuery assert sample_blob("jquery.js").vendored? assert sample_blob("public/javascripts/jquery.js").vendored? From 496b3e5a781b56862b381befc0027edfa94bde8f Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Tue, 20 Jan 2015 14:48:12 -0600 Subject: [PATCH 2/6] Bumping to 4.3.0 beta --- 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 73b6c63a..d0b2ad38 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "4.2.7" + VERSION = "4.3.0b1" end From 94be1ab2774ca68c841c4747495d8df7c4bfe8cf Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Tue, 24 Feb 2015 15:20:58 -0600 Subject: [PATCH 3/6] documentation? should use path too --- lib/linguist/blob_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb index a959d398..01a567e0 100644 --- a/lib/linguist/blob_helper.rb +++ b/lib/linguist/blob_helper.rb @@ -248,7 +248,7 @@ module Linguist # # Return true or false def documentation? - name =~ DocumentationRegexp ? true : false + path =~ DocumentationRegexp ? true : false end # Public: Get each line of data From 5ed0da7b08ce5ab0b3ef41c2c0c713bdc5f59972 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Sat, 14 Mar 2015 13:06:55 -0500 Subject: [PATCH 4/6] v4.5.0 --- 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 37ffbe58..eff270d7 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "4.5.0b2" + VERSION = "4.5.0" end From 01deb07ae9334253a55147591e804047b7782d19 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Sat, 14 Mar 2015 20:19:11 -0500 Subject: [PATCH 5/6] Return false for empty file. --- lib/linguist/generated.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/linguist/generated.rb b/lib/linguist/generated.rb index 4a67fabd..a87bbc90 100644 --- a/lib/linguist/generated.rb +++ b/lib/linguist/generated.rb @@ -281,6 +281,7 @@ module Linguist # Return true or false def compiled_cython_file? return false unless ['.c', '.cpp'].include? extname + return false unless lines.count > 1 return lines[0].include?("Generated by Cython") end end From 840bdf95e328e4070bc415f9030e93d881f8a7a2 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Sat, 14 Mar 2015 20:32:18 -0500 Subject: [PATCH 6/6] v4.5.1 --- 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 eff270d7..55ba47e1 100644 --- a/lib/linguist/version.rb +++ b/lib/linguist/version.rb @@ -1,3 +1,3 @@ module Linguist - VERSION = "4.5.0" + VERSION = "4.5.1" end