only load blobs to check for <?php header for specific drupal file extensions

This commit is contained in:
Aman Gupta
2011-11-23 00:50:44 -08:00
parent 21488c84c3
commit 9994ac3a0c

View File

@@ -135,6 +135,13 @@ module Linguist
['.png', '.jpg', '.jpeg', '.gif'].include?(extname) ['.png', '.jpg', '.jpeg', '.gif'].include?(extname)
end end
# Public: Is the blob a possible drupal php file?
#
# Return true or false
def drupal_extname?
['.module', '.install', '.test', '.inc'].include?(extname)
end
MEGABYTE = 1024 * 1024 MEGABYTE = 1024 * 1024
# Public: Is the blob too big to load? # Public: Is the blob too big to load?
@@ -512,10 +519,13 @@ module Linguist
# Internal: Guess language from the first line. # Internal: Guess language from the first line.
# #
# Look for leading "<?php" # Look for leading "<?php" in Drupal files
# #
# Returns a Language. # Returns a Language.
def first_line_language def first_line_language
# Only check files with drupal php extensions
return unless drupal_extname?
# Fail fast if blob isn't viewable? # Fail fast if blob isn't viewable?
return unless viewable? return unless viewable?