refactor(git): rework module around clearer Status and Repo split
This commit is contained in:
+10
-8
@@ -12,7 +12,7 @@ local cr = vim.api.nvim_replace_termcodes("<CR>", true, false, true)
|
||||
---@param buf integer
|
||||
local function attach_dispatch(buf)
|
||||
vim.keymap.set("n", "<CR>", function()
|
||||
local r = repo.find(buf)
|
||||
local r = repo.resolve(buf)
|
||||
-- Anchor past the leading graph chars (matches the leading sha
|
||||
-- column, not any hex word that happens to appear later in the
|
||||
-- subject).
|
||||
@@ -22,7 +22,7 @@ local function attach_dispatch(buf)
|
||||
:match("^[*|/\\_ ]*(%x%x%x%x%x%x%x+)")
|
||||
if sha then
|
||||
---@cast r -nil
|
||||
require("git.object").open_object(r, sha, { split = false })
|
||||
require("git.object").open(r, sha, { split = false })
|
||||
else
|
||||
vim.api.nvim_feedkeys(cr, "n", false)
|
||||
end
|
||||
@@ -50,7 +50,7 @@ end
|
||||
|
||||
---@param buf integer
|
||||
local function populate(buf)
|
||||
local r = repo.find(buf)
|
||||
local r = repo.resolve(buf)
|
||||
local state = r and r:state(buf)
|
||||
if not r or not state then
|
||||
return
|
||||
@@ -100,7 +100,7 @@ function M.read_uri(buf)
|
||||
if not r then
|
||||
return
|
||||
end
|
||||
repo.attach(buf, r)
|
||||
repo.bind(buf, r)
|
||||
|
||||
vim.bo[buf].swapfile = false
|
||||
vim.bo[buf].bufhidden = "hide"
|
||||
@@ -113,7 +113,7 @@ function M.read_uri(buf)
|
||||
populate(buf)
|
||||
end
|
||||
|
||||
---@class ow.Git.LogOpts
|
||||
---@class ow.Git.Log.OpenOpts
|
||||
---@field max_count integer?
|
||||
|
||||
---@type table<string, fun(s: string): any>
|
||||
@@ -121,17 +121,17 @@ M.opt_parsers = {
|
||||
max_count = tonumber,
|
||||
}
|
||||
|
||||
---@param opts ow.Git.LogOpts?
|
||||
---@param opts ow.Git.Log.OpenOpts?
|
||||
function M.open(opts)
|
||||
opts = opts or {}
|
||||
local r = repo.find()
|
||||
local r = repo.resolve()
|
||||
if not r then
|
||||
util.warning("not in a git repository")
|
||||
return
|
||||
end
|
||||
|
||||
local buf = vim.fn.bufadd(M.URI_PREFIX .. r.worktree)
|
||||
repo.attach(buf, r)
|
||||
repo.bind(buf, r)
|
||||
local state = r:state(buf) --[[@as -nil]]
|
||||
state.log_max_count = opts.max_count
|
||||
local was_loaded = vim.api.nvim_buf_is_loaded(buf)
|
||||
@@ -183,4 +183,6 @@ function M.complete_glog(arg_lead)
|
||||
return matches
|
||||
end
|
||||
|
||||
repo.on_uri_refresh(M.URI_PREFIX, M.read_uri)
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user