perf(git/repo): cache ref/file lookups, invalidate on status refresh
This commit is contained in:
+17
-12
@@ -317,22 +317,26 @@ end
|
||||
---@param dir string
|
||||
---@return string[]
|
||||
local function list_files(r, dir)
|
||||
local cmd = { "git", "ls-files" }
|
||||
if dir ~= "" then
|
||||
table.insert(cmd, dir)
|
||||
end
|
||||
local out = util.exec(cmd, { cwd = r.worktree, silent = true })
|
||||
return out and util.split_lines(out) or {}
|
||||
return r:get_cached("files:" .. dir, function(self)
|
||||
local cmd = { "git", "ls-files" }
|
||||
if dir ~= "" then
|
||||
table.insert(cmd, dir)
|
||||
end
|
||||
local out = util.exec(cmd, { cwd = self.worktree, silent = true })
|
||||
return out and util.split_lines(out) or {}
|
||||
end)
|
||||
end
|
||||
|
||||
---@param r ow.Git.Repo
|
||||
---@return string[]
|
||||
local function list_remotes(r)
|
||||
local out = util.exec(
|
||||
{ "git", "remote" },
|
||||
{ cwd = r.worktree, silent = true }
|
||||
)
|
||||
return out and util.split_lines(out) or {}
|
||||
return r:get_cached("remotes", function(self)
|
||||
local out = util.exec(
|
||||
{ "git", "remote" },
|
||||
{ cwd = self.worktree, silent = true }
|
||||
)
|
||||
return out and util.split_lines(out) or {}
|
||||
end)
|
||||
end
|
||||
|
||||
---@type table<string, string[]>
|
||||
@@ -469,7 +473,8 @@ function M.complete_rev(arg_lead)
|
||||
|
||||
local colon = arg_lead:find(":", 1, true)
|
||||
if not colon then
|
||||
local refs = r:list_refs()
|
||||
local refs = {}
|
||||
vim.list_extend(refs, r:list_refs())
|
||||
vim.list_extend(refs, r:list_pseudo_refs())
|
||||
vim.list_extend(refs, r:list_stash_refs())
|
||||
return prefix_filter(refs, arg_lead)
|
||||
|
||||
Reference in New Issue
Block a user