refactor(git): consolidate empty_buf with optional name + bufhidden
This commit is contained in:
+4
-14
@@ -77,19 +77,6 @@ local function is_zero(sha)
|
||||
return sha == nil or sha:match("^0+$") ~= nil
|
||||
end
|
||||
|
||||
---@param ref string buffer-name ref segment
|
||||
---@param path string
|
||||
---@return integer
|
||||
local function empty_buf(ref, path)
|
||||
local buf = vim.api.nvim_create_buf(false, true)
|
||||
vim.bo[buf].buftype = "nofile"
|
||||
vim.bo[buf].bufhidden = "hide"
|
||||
vim.bo[buf].swapfile = false
|
||||
vim.bo[buf].modifiable = false
|
||||
pcall(vim.api.nvim_buf_set_name, buf, "git://" .. ref .. "/" .. path)
|
||||
return buf
|
||||
end
|
||||
|
||||
---Build a buffer holding the file's content at a given blob, named after the
|
||||
---commit ref it corresponds to (so the name lines up with `git log` output
|
||||
---instead of an opaque blob hash).
|
||||
@@ -100,7 +87,10 @@ end
|
||||
---@return integer
|
||||
local function blob_buf(worktree, blob, path, ref)
|
||||
if is_zero(blob) then
|
||||
return empty_buf(ref, path)
|
||||
return diff.empty_buf({
|
||||
name = "git://" .. ref .. "/" .. path,
|
||||
bufhidden = "hide",
|
||||
})
|
||||
end
|
||||
---@cast blob string
|
||||
local buf = diff.git_show_blob(worktree, blob)
|
||||
|
||||
Reference in New Issue
Block a user