Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Use git ls-files for loading paths when available. #301

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions lib/load-paths-handler.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,45 @@ path = require 'path'
_ = require 'underscore-plus'
{GitRepository} = require 'atom'
{Minimatch} = require 'minimatch'
{GitProcess} = require 'dugite'

PathsChunkSize = 100

emittedPaths = new Set

class PathLoader
constructor: (@rootPath, ignoreVcsIgnores, @traverseSymlinkDirectories, @ignoredNames) ->
constructor: (@rootPath, @ignoreVcsIgnores, @traverseSymlinkDirectories, @ignoredNames) ->
@paths = []
@realPathCache = {}
@repo = null
if ignoreVcsIgnores
repo = GitRepository.open(@rootPath, refreshOnWindowFocus: false)
@repo = repo if repo?.relativize(path.join(@rootPath, 'test')) is 'test'

load: (done) ->
@loadPath @rootPath, true, =>
@flushPaths()
@repo?.destroy()
done()
repo = GitRepository.open(@rootPath, refreshOnWindowFocus: false)
if repo?.relativize(path.join(@rootPath, 'test')) is 'test'
args = ['ls-files', '-c', '-o', '-z']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind using the extended command args for clarity? Eg --cached, --others, etc.

if @ignoreVcsIgnores
args.push('--exclude-standard')
for ignoredName in @ignoredNames
args.push("-x")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. (Also it looks like these should be single quotes to match the other arg quotes?)

args.push(ignoredName.pattern)
output = ""
proc = GitProcess.spawn(args, @rootPath)
proc.stdout.on 'data', (chunk) ->
files = (output + chunk).split("\0")
output = files.pop()
emit('load-paths:paths-found', files)
proc.on "close", (code) ->
repo?.destroy()
done()
else
@loadPath @rootPath, true, =>
@flushPaths()
repo?.destroy()
done()

isIgnored: (loadedPath) ->
relativePath = path.relative(@rootPath, loadedPath)
if @repo?.isPathIgnored(relativePath)
true
else
for ignoredName in @ignoredNames
return true if ignoredName.match(relativePath)
for ignoredName in @ignoredNames
return true if ignoredName.match(relativePath)

pathLoaded: (loadedPath, done) ->
unless @isIgnored(loadedPath) or emittedPaths.has(loadedPath)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dependencies": {
"async": "0.2.6",
"atom-select-list": "^0.1.0",
"dugite": "^1.35.0",
"fs-plus": "^3.0.0",
"fuzzaldrin": "^2.0",
"fuzzaldrin-plus": "^0.4.1",
Expand Down