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
+16 -27
View File
@@ -74,13 +74,11 @@ end
---@param user_ref string
---@param path string
local function show_file_in_split(worktree, user_ref, path)
repo.rev_parse(worktree, user_ref, true, function(sha)
local label = sha or user_ref
local uri = "git://" .. label .. "//" .. path
local buf = vim.fn.bufadd(uri)
vim.b[buf].git_worktree = worktree
vim.cmd("split " .. vim.fn.fnameescape(uri))
end)
local label = repo.rev_parse(worktree, user_ref, true) or user_ref
local uri = "git://" .. label .. "//" .. path
local buf = vim.fn.bufadd(uri)
vim.b[buf].git_worktree = worktree
vim.cmd("split " .. vim.fn.fnameescape(uri))
end
---@param worktree string
@@ -105,27 +103,18 @@ local function run_in_split(worktree, args, conf)
vim.b[buf].git_worktree = worktree
if conf.needs_ref then
local user_ref = first_positional(args, 2) or "HEAD"
local function apply_name(label)
if not vim.api.nvim_buf_is_valid(buf) then
return
end
pcall(vim.api.nvim_buf_set_name, buf, "git://" .. label .. "//")
vim.bo[buf].filetype = conf.ft
local sha = repo.rev_parse(worktree, user_ref, true)
if sha then
vim.b[buf].git_ref = sha
vim.b[buf].git_parent_ref =
repo.rev_parse(worktree, user_ref .. "^", true)
end
repo.rev_parse(worktree, user_ref, true, function(sha)
if not sha then
apply_name(user_ref)
return
end
repo.rev_parse(worktree, user_ref .. "^", true, function(parent)
if not vim.api.nvim_buf_is_valid(buf) then
return
end
vim.b[buf].git_ref = sha
vim.b[buf].git_parent_ref = parent
apply_name(sha)
end)
end)
pcall(
vim.api.nvim_buf_set_name,
buf,
"git://" .. (sha or user_ref) .. "//"
)
vim.bo[buf].filetype = conf.ft
else
vim.bo[buf].filetype = conf.ft
end