perf(git): piggyback sidebar status on the indicator's git status call

This commit is contained in:
2026-04-27 14:09:33 +02:00
parent 26b12a4371
commit 2ef9cb7c9e
2 changed files with 173 additions and 125 deletions
+20 -8
View File
@@ -142,25 +142,33 @@ end
---@param repo ow.Git.Repo
local function do_refresh(repo)
-- `--branch` adds the `## branch...upstream [ahead/behind]` line that
-- the sidebar parses; the per-buffer indicator only needs the XY +
-- path lines, so it ignores `##` lines below. Running with `--branch`
-- lets the sidebar reuse this single subprocess via the GitRefresh
-- data payload instead of spawning its own.
vim.system({
"git",
"-c",
"core.quotePath=false",
"status",
"--porcelain=v1",
"--branch",
}, { cwd = repo.worktree, text = true }, function(obj)
vim.schedule(function()
local statuses = {}
if obj.code == 0 then
for line in (obj.stdout or ""):gmatch("[^\r\n]+") do
local code = line:sub(1, 2)
local path_part = line:sub(4)
local arrow = path_part:find(" -> ", 1, true)
if arrow then
path_part = path_part:sub(arrow + 4)
if line:sub(1, 2) ~= "##" then
local code = line:sub(1, 2)
local path_part = line:sub(4)
local arrow = path_part:find(" -> ", 1, true)
if arrow then
path_part = path_part:sub(arrow + 4)
end
statuses[vim.fs.joinpath(repo.worktree, path_part)] =
format(code)
end
statuses[vim.fs.joinpath(repo.worktree, path_part)] =
format(code)
end
else
log.warning("git status failed: %s", vim.trim(obj.stderr or ""))
@@ -182,7 +190,11 @@ local function do_refresh(repo)
end
vim.api.nvim_exec_autocmds("User", {
pattern = "GitRefresh",
data = { gitdir = repo.gitdir, worktree = repo.worktree },
data = {
gitdir = repo.gitdir,
worktree = repo.worktree,
porcelain_stdout = obj.code == 0 and obj.stdout or nil,
},
})
end)
end)