Use bundled ack instead of grep

Our ack is slightly modified to use `'\0'` characters instead of `':'` in the --nogroup listing. This makes it easier to handle both `':'` characters and newlines in filenames, but we aren't really doing that yet.
This commit is contained in:
Nathan Sobo
2012-07-19 08:54:08 -06:00
parent 8534df28d5
commit f5e46e57fc
10 changed files with 2801 additions and 21 deletions

View File

@@ -139,6 +139,5 @@ describe "Project", ->
it "works on evil filenames", ->
project.setPath(require.resolve('fixtures/evil-files'))
waitsForPromise ->
project.scan /(a)+/, ({path, match, range}) ->
matches.push({path, match, range})
project.scan /evil/, ({path, match, range}) ->
#console.log path

View File

@@ -0,0 +1 @@
I am evil because there are spaces in my name

View File

@@ -1 +0,0 @@
you know how we do it

View File

@@ -0,0 +1 @@
I am evil because there's a newline in my name

View File

@@ -1 +0,0 @@
// I am evil because there's a " in my filename. Why you do that!?

1
spec/fixtures/evil-files/quote".txt vendored Normal file
View File

@@ -0,0 +1 @@
I am evil because there's a " in my filename. Why you do that!?

View File

@@ -1,3 +1 @@
# Hello Word
This is markdown.
I am evil because there's a UTF-8 character in my name

View File

@@ -138,20 +138,14 @@ class Project
scan: (regex, iterator) ->
regex = new RegExp(regex.source, 'g')
command = [
"find \"#{@getPath()}\" -type f -print0" # find all paths in the project's working directory
"grep --text --perl-regexp --invert-match --regexp=\"#{@ignorePathRegex()}\"" # accept only non-ignored paths, separated by \0 (find doesn't support pcre)
"perl -0pi -e 's/\\n\\z\//'" # delete grep's trailing newline because it screws up xargs
"xargs -0 grep --null --perl-regexp --with-filename --line-number --recursive --regexp=\"#{regex.source}\"" # run grep on each filtered file
].join(" | ")
ChildProcess.exec command, bufferLines: true, stdout: (data) ->
command = "#{require.resolve('ack')} --all-types --match \"#{regex.source}\" \"#{@getPath()}\""
ChildProcess.exec command , bufferLines: true, stdout: (data) ->
for grepLine in data.split('\n') when grepLine.length
nullCharIndex = grepLine.indexOf('\0')
colonIndex = grepLine.indexOf(':')
path = grepLine.substring(0, nullCharIndex)
row = parseInt(grepLine.substring(nullCharIndex + 1, colonIndex)) - 1
line = grepLine.substring(colonIndex + 1)
pathEndIndex = grepLine.indexOf('\0')
lineNumberEndIndex = grepLine.indexOf('\0', pathEndIndex + 1)
path = grepLine.substring(0, pathEndIndex)
row = parseInt(grepLine.substring(pathEndIndex + 1, lineNumberEndIndex)) - 1
line = grepLine.substring(lineNumberEndIndex + 1)
while match = regex.exec(line)
range = new Range([row, match.index], [row, match.index + match[0].length])
iterator({path, match, range})

View File

@@ -92,6 +92,7 @@ resolve = (file) ->
return file
__expand = (path) ->
return path if __isFile path
for ext, handler of exts
if __exists "#{path}.#{ext}"
return "#{path}.#{ext}"
@@ -104,6 +105,9 @@ __expand = (path) ->
__exists = (path) ->
$native.exists path
__isFile = (path) ->
$native.isFile path
__coffeeCache = (filePath) ->
{CoffeeScript} = require 'coffee-script'
tmpPath = "/tmp/atom-compiled-scripts"

2784
vendor/ack vendored Executable file

File diff suppressed because it is too large Load Diff