avoid load_blob and shebang check on files with extensions

previously, any file with an unrecognized file extension was loaded to
check for a shebang. now, this only occurs if the file has a generic
name with no file extension (like ./script)

it is possible this will no longer match certain scripts with esoteric
extensions (if we find these we can add them to the shebang_extname?
method). however, most common script extensions (.sh, .rb, .pl, etc)
will continue to work since the file extension takes precedence over the
shebang line.
This commit is contained in:
Aman Gupta
2011-11-23 00:51:33 -08:00
parent 9994ac3a0c
commit 61a59c8e84
2 changed files with 47 additions and 31 deletions

View File

@@ -142,6 +142,13 @@ module Linguist
['.module', '.install', '.test', '.inc'].include?(extname)
end
# Public: Is the blob likely to have a shebang?
#
# Return true or false
def shebang_extname?
extname.empty?
end
MEGABYTE = 1024 * 1024
# Public: Is the blob too big to load?
@@ -592,6 +599,9 @@ module Linguist
#
# Returns the Language or nil
def shebang_language
# Skip file extensions unlikely to have shebangs
return unless shebang_extname?
if script = shebang_script
Language[script]
end