mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
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:
@@ -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
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
I am evil because there are spaces in my name
|
||||
|
||||
1
spec/fixtures/evil-files/goddam
linefeeds
vendored
1
spec/fixtures/evil-files/goddam
linefeeds
vendored
@@ -1 +0,0 @@
|
||||
you know how we do it
|
||||
1
spec/fixtures/evil-files/goddam
newlines
vendored
Normal file
1
spec/fixtures/evil-files/goddam
newlines
vendored
Normal file
@@ -0,0 +1 @@
|
||||
I am evil because there's a newline in my name
|
||||
1
spec/fixtures/evil-files/quote".js
vendored
1
spec/fixtures/evil-files/quote".js
vendored
@@ -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
1
spec/fixtures/evil-files/quote".txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
I am evil because there's a " in my filename. Why you do that!?
|
||||
4
spec/fixtures/evil-files/utfă.md
vendored
4
spec/fixtures/evil-files/utfă.md
vendored
@@ -1,3 +1 @@
|
||||
# Hello Word
|
||||
|
||||
This is markdown.
|
||||
I am evil because there's a UTF-8 character in my name
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -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
2784
vendor/ack
vendored
Executable file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user