perf(git): run rev-parse and git show <commit> sync

This commit is contained in:
2026-04-28 08:03:05 +02:00
parent 01c0f82e18
commit d2633ae9c2
3 changed files with 68 additions and 107 deletions
+12 -21
View File
@@ -322,35 +322,26 @@ function M.head(path)
return nil
end
---Resolve a git revision to its object SHA. Calls `callback(sha?)` on the
---main loop with nil if the ref can't be parsed (root-commit's `^`, blob's
---`^`, malformed ref, etc.). When `short` is true, the result is abbreviated
---via `core.abbrev` (auto-extended by git to keep the prefix unique in the
---current repo).
---Resolve a git revision to its object SHA. Returns nil if the ref can't
---be parsed (root-commit's `^`, blob's `^`, malformed ref, etc.). When
---`short` is true, the result is abbreviated via `core.abbrev`
---(auto-extended by git to keep the prefix unique in the current repo).
---@param worktree string
---@param ref string
---@param short boolean
---@param callback fun(sha: string?)
function M.rev_parse(worktree, ref, short, callback)
---@return string?
function M.rev_parse(worktree, ref, short)
local cmd = { "git", "rev-parse", "--verify", "--quiet" }
if short then
table.insert(cmd, "--short")
end
table.insert(cmd, ref)
vim.system(
cmd,
{ cwd = worktree, text = true },
vim.schedule_wrap(function(result)
local sha
if result.code == 0 then
local trimmed = vim.trim(result.stdout or "")
if trimmed ~= "" then
sha = trimmed
end
end
callback(sha)
end)
)
local result = vim.system(cmd, { cwd = worktree, text = true }):wait()
if result.code ~= 0 then
return nil
end
local trimmed = vim.trim(result.stdout or "")
return trimmed ~= "" and trimmed or nil
end
return M