refactor(git): older-on-left placement, drop empty placeholders
This commit is contained in:
+10
-7
@@ -275,19 +275,24 @@ function M.read_uri(buf)
|
||||
vim.api.nvim_exec_autocmds("BufReadPost", { buffer = buf })
|
||||
end
|
||||
|
||||
---Buffer for the file at `<ref>:<path>`. A zero/nil blob (file absent on
|
||||
---this side of the diff) yields an empty placeholder.
|
||||
---Buffer for the file at `<ref>:<path>`. A zero/nil blob (file absent
|
||||
---on this side of the diff) maps to `/dev/null`, mirroring git's diff
|
||||
---headers.
|
||||
---@param worktree string
|
||||
---@param blob string?
|
||||
---@param path string
|
||||
---@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 revspec = ref .. ":" .. path
|
||||
if is_zero(blob) then
|
||||
return util.empty_buf({ name = util.uri(revspec) })
|
||||
local buf = vim.fn.bufnr("/dev/null")
|
||||
if buf == -1 then
|
||||
buf = vim.api.nvim_create_buf(true, true)
|
||||
pcall(vim.api.nvim_buf_set_name, buf, "/dev/null")
|
||||
end
|
||||
return buf
|
||||
end
|
||||
return M.buf_for(worktree, revspec)
|
||||
return M.buf_for(worktree, ref .. ":" .. path)
|
||||
end
|
||||
|
||||
---@param worktree string
|
||||
@@ -308,8 +313,6 @@ local function open_section(ctx, section)
|
||||
return
|
||||
end
|
||||
local parent = ctx.parent_ref or "0"
|
||||
-- An empty buffer for zero blobs keeps `:diffsplit` from
|
||||
-- BufReadCmd-loading a non-existent revspec.
|
||||
local left =
|
||||
blob_buf(ctx.worktree, section.pre_blob, section.pre_path, parent)
|
||||
local right =
|
||||
|
||||
Reference in New Issue
Block a user