refactor(git): give URI buffer refresh a content-only path
This commit is contained in:
+42
-27
@@ -164,36 +164,19 @@ function M.buf_for(r, rev)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param buf integer
|
---@param buf integer
|
||||||
function M.read_uri(buf)
|
---@param r ow.Git.Repo
|
||||||
local name = vim.api.nvim_buf_get_name(buf)
|
---@param rev ow.Git.Revision
|
||||||
local rev = M.parse_uri(name)
|
---@param state ow.Git.Repo.BufState
|
||||||
if not rev then
|
---@param rev_sha string
|
||||||
return
|
---@return boolean ok
|
||||||
end
|
local function populate(buf, r, rev, state, rev_sha)
|
||||||
local rev_str = rev:format()
|
local rev_str = rev:format()
|
||||||
|
|
||||||
local r = repo.resolve(buf)
|
|
||||||
if not r then
|
|
||||||
util.error("git BufReadCmd %s: cannot resolve worktree", name)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
repo.bind(buf, r)
|
|
||||||
local state = r:state(buf) --[[@as -nil]]
|
|
||||||
|
|
||||||
vim.bo[buf].swapfile = false
|
|
||||||
vim.bo[buf].bufhidden = "hide"
|
|
||||||
|
|
||||||
local rev_sha = r:rev_parse(rev_str, true)
|
|
||||||
if not rev_sha then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local stdout = util.exec(
|
local stdout = util.exec(
|
||||||
{ "git", "cat-file", "-p", rev_str },
|
{ "git", "cat-file", "-p", rev_str },
|
||||||
{ cwd = r.worktree }
|
{ cwd = r.worktree }
|
||||||
)
|
)
|
||||||
if not stdout then
|
if not stdout then
|
||||||
return
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if rev.path == nil then
|
if rev.path == nil then
|
||||||
@@ -216,10 +199,43 @@ function M.read_uri(buf)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local was_modifiable = vim.bo[buf].modifiable
|
||||||
vim.bo[buf].modifiable = true
|
vim.bo[buf].modifiable = true
|
||||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, util.split_lines(stdout))
|
vim.api.nvim_buf_set_lines(buf, 0, -1, false, util.split_lines(stdout))
|
||||||
|
vim.bo[buf].modifiable = was_modifiable
|
||||||
|
vim.bo[buf].modified = false
|
||||||
state.sha = rev_sha
|
state.sha = rev_sha
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param buf integer
|
||||||
|
function M.read_uri(buf)
|
||||||
|
local name = vim.api.nvim_buf_get_name(buf)
|
||||||
|
local rev = M.parse_uri(name)
|
||||||
|
if not rev then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local r = repo.resolve(buf)
|
||||||
|
if not r then
|
||||||
|
util.error("git BufReadCmd %s: cannot resolve worktree", name)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
repo.bind(buf, r)
|
||||||
|
local state = r:state(buf) --[[@as -nil]]
|
||||||
|
|
||||||
|
vim.bo[buf].swapfile = false
|
||||||
|
vim.bo[buf].bufhidden = "hide"
|
||||||
|
|
||||||
|
local rev_sha = r:rev_parse(rev:format(), true)
|
||||||
|
if not rev_sha then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if not populate(buf, r, rev, state, rev_sha) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
state.immutable = is_immutable_rev(rev)
|
state.immutable = is_immutable_rev(rev)
|
||||||
|
|
||||||
if rev.stage == 0 and rev.path then
|
if rev.stage == 0 and rev.path then
|
||||||
@@ -232,7 +248,6 @@ function M.read_uri(buf)
|
|||||||
vim.bo[buf].buftype = "nofile"
|
vim.bo[buf].buftype = "nofile"
|
||||||
vim.bo[buf].modifiable = false
|
vim.bo[buf].modifiable = false
|
||||||
end
|
end
|
||||||
vim.bo[buf].modified = false
|
|
||||||
|
|
||||||
if rev.path then
|
if rev.path then
|
||||||
local ft = vim.filetype.match({ filename = rev.path, buf = buf })
|
local ft = vim.filetype.match({ filename = rev.path, buf = buf })
|
||||||
@@ -265,7 +280,7 @@ local function refresh(buf, r)
|
|||||||
if not rev_sha or rev_sha == state.sha then
|
if not rev_sha or rev_sha == state.sha then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
M.read_uri(buf)
|
populate(buf, r, rev, state, rev_sha)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param r ow.Git.Repo
|
---@param r ow.Git.Repo
|
||||||
|
|||||||
Reference in New Issue
Block a user