perf(git): fold revspec validation into the cat-file -p the loader needs anyway

This commit is contained in:
2026-04-29 09:53:48 +02:00
parent 5c5da7a854
commit 590651e9d8
3 changed files with 42 additions and 28 deletions
+19 -8
View File
@@ -157,13 +157,17 @@ local function uri_split(opts, cur_buf, cur_revspec)
local cur_writable = cur.stage == 0
if opts.revspec ~= "" and opts.revspec:find(":", 1, true) then
if not repo.object_exists(worktree, opts.revspec) then
local content = util.exec(
{ "git", "cat-file", "-p", opts.revspec },
{ cwd = worktree, silent = true }
)
if not content then
util.warning("invalid revspec: %s", opts.revspec)
return
end
place_pair(
cur_buf,
object.buf_for(worktree, opts.revspec),
object.buf_for(worktree, opts.revspec, content),
cur_writable,
opts.vertical
)
@@ -192,13 +196,17 @@ local function uri_split(opts, cur_buf, cur_revspec)
else
other_revspec = ":0:" .. cur.path
end
if not repo.object_exists(worktree, other_revspec) then
local content = util.exec(
{ "git", "cat-file", "-p", other_revspec },
{ cwd = worktree, silent = true }
)
if not content then
util.warning("invalid revspec: %s", other_revspec)
return
end
place_pair(
cur_buf,
object.buf_for(worktree, other_revspec),
object.buf_for(worktree, other_revspec, content),
cur.stage ~= nil,
opts.vertical
)
@@ -248,13 +256,16 @@ function M.split(opts)
else
revspec = opts.revspec .. ":" .. rel
end
if not repo.object_exists(worktree, revspec) then
local content = util.exec(
{ "git", "cat-file", "-p", revspec },
{ cwd = worktree, silent = true }
)
if not content then
util.warning("invalid revspec: %s", revspec)
return
end
local buf = vim.fn.bufadd("git://" .. revspec)
vim.b[buf].git_worktree = worktree
local object = require("git.object")
local buf = object.buf_for(worktree, revspec, content)
local other_writable = util.parse_revspec(revspec).stage == 0
place_pair(buf, cur_buf, other_writable, opts.vertical)
end