perf(git): fold revspec validation into the cat-file -p the loader needs anyway
This commit is contained in:
+19
-8
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user