Skip to content

236 gitignored slowdown #274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all 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: 21 additions & 19 deletions lua/neo-tree/git/ignored.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,38 +48,35 @@ local get_root_for_item = function(item)
end

M.mark_ignored = function(state, items)
local git_roots = {}
local folders = {}
log.trace("================================================================================")
log.trace("IGNORED: mark_ignore BEGIN...")
for _, item in ipairs(items) do
local root = get_root_for_item(item)
if root then
if not git_roots[root] then
git_roots[root] = {}
local folder = utils.split_path(item.path)
if folder then
if not folders[folder] then
folders[folder] = {}
end
table.insert(git_roots[root], item.path)
table.insert(folders[folder], item.path)
end
end

local all_results = {}
for repo_root, repo_items in pairs(git_roots) do
local cmd = {"git", "-C", repo_root, "check-ignore"}
for _, item in ipairs(repo_items) do
for folder, folder_items in pairs(folders) do
local cmd = {"git", "-C", folder, "check-ignore"}
for _, item in ipairs(folder_items) do
table.insert(cmd, item)
end
log.trace("IGNORED: Running cmd: ", cmd)
local result = vim.fn.systemlist(cmd)
if vim.v.shell_error == 128 then
if type(result) == "table" then
if vim.startswith(result[1], "fatal:") then
-- These errors are all about not being in a repository
log.error("Error in git.mark_ignored: ", result[1])
result = {}
end
end
log.error("Failed to load ignored files for", state.path, ":", result)
log.debug("Failed to load ignored files for", state.path, ":", result)
result = {}
end

--check-ignore does not indicate directories the same as 'status' so we need to
--add the trailing slash to the path manually.
log.trace("IGNORED: Checking types of", #result, "items to see which ones are directories")
for i, item in ipairs(result) do
local stat = vim.loop.fs_stat(item)
if stat and stat.type == "directory" then
Expand All @@ -89,14 +86,19 @@ M.mark_ignored = function(state, items)
vim.list_extend(all_results, result)
end


log.trace("IGNORED: Comparing results to mark items as ignored")
local ignored, not_ignored = 0, 0
for _, item in ipairs(items) do
if M.is_ignored(all_results, item.path, item.type) then
item.filtered_by = item.filtered_by or {}
item.filtered_by.gitignored = true
ignored = ignored + 1
else
not_ignored = not_ignored + 1
end
end

log.trace("IGNORED: mark_ignored is complete, ignored:", ignored, ", not ignored:", not_ignored)
log.trace("================================================================================")
return all_results
end

Expand Down
2 changes: 1 addition & 1 deletion lua/neo-tree/git/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ M.get_repository_root = function(path)
git_root = utils.windowize_path(git_root)
end

log.trace("GIT ROOT is ", git_root)
log.trace("GIT ROOT for '", path, "' is '", git_root, "'")
return git_root
end

Expand Down