refactor(git): URI scheme is now a git revspec, loaded via cat-file -p
This commit is contained in:
+10
-6
@@ -87,11 +87,14 @@ end
|
||||
---@param ref string the commit ref the blob represents (e.g. `<sha>` or `<sha>^`)
|
||||
---@return integer
|
||||
local function blob_buf(worktree, blob, path, ref)
|
||||
local name = "git://" .. ref .. "//" .. path
|
||||
local revspec = ref .. ":" .. path
|
||||
if is_zero(blob) then
|
||||
return diff.empty_buf({ name = name, bufhidden = "hide" })
|
||||
return diff.empty_buf({
|
||||
name = "git://" .. revspec,
|
||||
bufhidden = "hide",
|
||||
})
|
||||
end
|
||||
return diff.git_show_buf(worktree, ref, path)
|
||||
return diff.git_show_buf(worktree, revspec)
|
||||
end
|
||||
|
||||
---@param worktree string
|
||||
@@ -142,7 +145,7 @@ end
|
||||
function M.open_commit(worktree, ref, opts)
|
||||
local split = opts and opts.split
|
||||
local sha = repo.rev_parse(worktree, ref, true) or ref
|
||||
local name = "git://" .. sha .. "//"
|
||||
local name = "git://" .. sha
|
||||
local existing = vim.fn.bufnr(name)
|
||||
if existing ~= -1 and vim.api.nvim_buf_is_loaded(existing) then
|
||||
if split == false then
|
||||
@@ -218,7 +221,7 @@ function M.open_object(worktree, ref, opts)
|
||||
|
||||
local split = opts and opts.split
|
||||
local sha = repo.rev_parse(worktree, ref, true) or ref
|
||||
local name = "git://" .. sha .. "//"
|
||||
local name = "git://" .. sha
|
||||
local existing = vim.fn.bufnr(name)
|
||||
if existing ~= -1 and vim.api.nvim_buf_is_loaded(existing) then
|
||||
if split == false then
|
||||
@@ -279,7 +282,8 @@ function M.open_under_cursor()
|
||||
line:match("^%d+ (%w+) (%x+)\t(.+)$")
|
||||
if entry_sha then
|
||||
if entry_type == "blob" then
|
||||
local buf = diff.git_show_buf(ctx.worktree, ctx.ref, entry_name)
|
||||
local buf =
|
||||
diff.git_show_buf(ctx.worktree, ctx.ref .. ":" .. entry_name)
|
||||
vim.cmd.normal({ "m'", bang = true })
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user