aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott J. Goldman <scottjg@github.com>2012-09-02 00:09:51 -0700
committerScott J. Goldman <scottjg@github.com>2012-09-02 00:09:51 -0700
commit5443dc50a3379cbe10619b713c31a7e12d6a2f47 (patch)
treeb0f0bdf9e5198d7ef60b7c27837d4441e84eddfc
parent6ec907a915bf3d18d8f7debb58e9e859cb9de16c (diff)
parentfc435a254171ff7ac8ff1291fc03a071add3c346 (diff)
Merge pull request #247 from github/check-size-first
When testing if a blob is indexable or safe to colorize, check size first
-rw-r--r--github-linguist.gemspec3
-rw-r--r--lib/linguist/blob_helper.rb8
-rw-r--r--test/test_blob.rb7
3 files changed, 13 insertions, 5 deletions
diff --git a/github-linguist.gemspec b/github-linguist.gemspec
index 246824a..14590ce 100644
--- a/github-linguist.gemspec
+++ b/github-linguist.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'github-linguist'
- s.version = '2.3.1'
+ s.version = '2.3.2'
s.summary = "GitHub Language detection"
s.authors = "GitHub"
@@ -12,6 +12,7 @@ Gem::Specification.new do |s|
s.add_dependency 'escape_utils', '~> 0.2.3'
s.add_dependency 'mime-types', '~> 1.19'
s.add_dependency 'pygments.rb', '>= 0.2.13'
+ s.add_development_dependency 'mocha'
s.add_development_dependency 'json'
s.add_development_dependency 'rake'
s.add_development_dependency 'yajl-ruby'
diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb
index b2d72f1..04c3f0a 100644
--- a/lib/linguist/blob_helper.rb
+++ b/lib/linguist/blob_helper.rb
@@ -160,7 +160,7 @@ module Linguist
#
# Return true or false
def safe_to_colorize?
- text? && !large? && !high_ratio_of_long_lines?
+ !large? && text? && !high_ratio_of_long_lines?
end
# Internal: Does the blob have a ratio of long lines?
@@ -250,7 +250,9 @@ module Linguist
#
# Return true or false
def indexable?
- if binary?
+ if size > 100 * 1024
+ false
+ elsif binary?
false
elsif extname == '.txt'
true
@@ -260,8 +262,6 @@ module Linguist
false
elsif generated?
false
- elsif size > 100 * 1024
- false
else
true
end
diff --git a/test/test_blob.rb b/test/test_blob.rb
index 0832b8f..17e9ef8 100644
--- a/test/test_blob.rb
+++ b/test/test_blob.rb
@@ -2,6 +2,7 @@ require 'linguist/file_blob'
require 'linguist/samples'
require 'test/unit'
+require 'mocha'
require 'mime/types'
require 'pygments'
@@ -261,6 +262,12 @@ class TestBlob < Test::Unit::TestCase
assert !blob("Text/dump.sql").indexable?
assert !blob("Binary/github.po").indexable?
assert !blob("Binary/linguist.gem").indexable?
+
+ # large binary blobs should fail on size check first, not call
+ # into charlock_holmes and alloc big buffers for testing encoding
+ b = blob("Binary/octocat.ai")
+ b.expects(:binary?).never
+ assert !b.indexable?
end
def test_language