refactor(git): rework module around clearer Status and Repo split

This commit is contained in:
2026-05-06 00:45:56 +02:00
parent 1b43fa6a1c
commit 80d6d465cf
17 changed files with 821 additions and 775 deletions
+11 -9
View File
@@ -145,7 +145,7 @@ end
---@return integer
function M.buf_for(r, rev, content)
local buf = vim.fn.bufadd(M.format_uri(rev))
repo.attach(buf, r)
repo.bind(buf, r)
if content then
local state = r:state(buf) --[[@as -nil]]
state.pending_content = content
@@ -163,12 +163,12 @@ function M.read_uri(buf)
end
local rev_str = rev:format()
local r = repo.find(buf)
local r = repo.resolve(buf)
if not r then
util.error("git BufReadCmd %s: cannot resolve worktree", name)
return
end
repo.attach(buf, r)
repo.bind(buf, r)
local state = r:state(buf) --[[@as -nil]]
vim.bo[buf].swapfile = false
@@ -275,7 +275,7 @@ local function load_blob(r, blob, path, sha)
vim.api.nvim_set_current_buf(buf)
end
---@param s ow.Git.BufState
---@param s ow.Git.Repo.BufState
---@param section ow.Git.DiffSection
local function open_section(s, section)
if not section.blob_a or not section.blob_b then
@@ -300,13 +300,13 @@ local function open_section(s, section)
vim.api.nvim_set_current_buf(buf)
end
---@class ow.Git.OpenObjectOpts
---@class ow.Git.Object.OpenOpts
---@field split (false|"above"|"below"|"left"|"right")?
---@param r ow.Git.Repo
---@param rev string
---@param opts ow.Git.OpenObjectOpts?
function M.open_object(r, rev, opts)
---@param opts ow.Git.Object.OpenOpts?
function M.open(r, rev, opts)
local parsed = Revision.parse(rev)
if parsed.base then
local sha = r:rev_parse(parsed.base, true)
@@ -341,7 +341,7 @@ function M.open_under_cursor()
or line:match("^tree (%x+)$")
or line:match("^object (%x+)$")
if sha then
M.open_object(r, sha, { split = false })
M.open(r, sha, { split = false })
return true
end
@@ -351,7 +351,7 @@ function M.open_under_cursor()
local nav_rev = entry_type == "blob"
and Revision.new({ base = s.sha, path = entry_name }):format()
or entry_sha
M.open_object(r, nav_rev, { split = false })
M.open(r, nav_rev, { split = false })
return true
end
@@ -384,4 +384,6 @@ function M.open_under_cursor()
return false
end
repo.on_uri_refresh(M.URI_PREFIX, M.read_uri)
return M