refactor(git): minor structural cleanups
This commit is contained in:
+2
-2
@@ -188,7 +188,7 @@ end
|
||||
---@param arg_lead string
|
||||
---@param cmd_line string
|
||||
---@return string[]
|
||||
function M.complete(arg_lead, cmd_line, _)
|
||||
local function complete(arg_lead, cmd_line, _)
|
||||
local rest = cmd_line:gsub("^%s*%S+%s*", "", 1)
|
||||
local words = vim.split(rest, "%s+", { trimempty = false })
|
||||
if #words > 1 then
|
||||
@@ -208,7 +208,7 @@ function M.setup()
|
||||
M.run(opts.fargs)
|
||||
end, {
|
||||
nargs = "*",
|
||||
complete = M.complete,
|
||||
complete = complete,
|
||||
desc = "Run git",
|
||||
})
|
||||
end
|
||||
|
||||
+2
-3
@@ -78,11 +78,10 @@ function M.git_show_buf(worktree, ref, path, is_index)
|
||||
vim.bo[buf].buftype = is_index and "acwrite" or "nofile"
|
||||
vim.bo[buf].bufhidden = "wipe"
|
||||
vim.bo[buf].swapfile = false
|
||||
if not is_index then
|
||||
vim.bo[buf].modifiable = false
|
||||
end
|
||||
if is_index then
|
||||
attach_index_writer(buf, worktree, path)
|
||||
else
|
||||
vim.bo[buf].modifiable = false
|
||||
end
|
||||
vim.bo[buf].modified = false
|
||||
return buf
|
||||
|
||||
+13
-14
@@ -36,9 +36,6 @@ local function indicator(code)
|
||||
if y == "D" then
|
||||
return "D", "GitDeleted"
|
||||
end
|
||||
if y == "M" or y == "T" then
|
||||
return "M", "GitUnstaged"
|
||||
end
|
||||
return "M", "GitUnstaged"
|
||||
end
|
||||
|
||||
@@ -87,7 +84,7 @@ end
|
||||
---@class ow.Git.Repo
|
||||
---@field gitdir string
|
||||
---@field worktree string
|
||||
---@field buffers integer[]
|
||||
---@field buffers table<integer, true> set of registered buffer numbers
|
||||
---@field watcher? uv.uv_fs_event_t
|
||||
---@field refresh fun(self: ow.Git.Repo)
|
||||
---@field refresh_handle ow.Util.DebounceHandle
|
||||
@@ -116,17 +113,17 @@ end
|
||||
|
||||
---@param buf integer
|
||||
function Repo:add_buffer(buf)
|
||||
table.insert(self.buffers, buf)
|
||||
self.buffers[buf] = true
|
||||
end
|
||||
|
||||
---@param buf integer
|
||||
function Repo:remove_buffer(buf)
|
||||
for i, b in ipairs(self.buffers) do
|
||||
if b == buf then
|
||||
table.remove(self.buffers, i)
|
||||
break
|
||||
end
|
||||
end
|
||||
self.buffers[buf] = nil
|
||||
end
|
||||
|
||||
---@return boolean
|
||||
function Repo:has_buffers()
|
||||
return next(self.buffers) ~= nil
|
||||
end
|
||||
|
||||
---@param repo ow.Git.Repo
|
||||
@@ -152,8 +149,10 @@ local function do_refresh(repo)
|
||||
format(code)
|
||||
end
|
||||
end
|
||||
for _, buf in ipairs(repo.buffers) do
|
||||
if vim.api.nvim_buf_is_valid(buf) then
|
||||
for buf in pairs(repo.buffers) do
|
||||
if not vim.api.nvim_buf_is_valid(buf) then
|
||||
repo.buffers[buf] = nil
|
||||
else
|
||||
local status = statuses[vim.api.nvim_buf_get_name(buf)]
|
||||
if vim.b[buf].git_status ~= status then
|
||||
vim.b[buf].git_status = status
|
||||
@@ -222,7 +221,7 @@ local function unregister(buf)
|
||||
end
|
||||
repo_by_buf[buf] = nil
|
||||
repo:remove_buffer(buf)
|
||||
if #repo.buffers == 0 then
|
||||
if not repo:has_buffers() then
|
||||
repo:stop_watcher()
|
||||
repo_by_gitdir[repo.gitdir] = nil
|
||||
end
|
||||
|
||||
+19
-21
@@ -18,8 +18,8 @@ local SIDEBAR_WIDTH = 50
|
||||
---@field section string
|
||||
---@field path string
|
||||
---@field orig string?
|
||||
---@field x string?
|
||||
---@field y string?
|
||||
---@field x string porcelain v1 column 1 (always set; may be a literal space)
|
||||
---@field y string porcelain v1 column 2 (always set; may be a literal space)
|
||||
|
||||
---@class ow.Git.CommitEntry
|
||||
---@field section string
|
||||
@@ -61,11 +61,11 @@ local function entry_code(entry)
|
||||
if entry.section == "Untracked" then
|
||||
return "??"
|
||||
elseif entry.section == "Unmerged" then
|
||||
return (entry.x or " ") .. (entry.y or " ")
|
||||
return entry.x .. entry.y
|
||||
elseif entry.section == "Staged" then
|
||||
return (entry.x or " ") .. " "
|
||||
return entry.x .. " "
|
||||
elseif entry.section == "Unstaged" then
|
||||
return " " .. (entry.y or " ")
|
||||
return " " .. entry.y
|
||||
end
|
||||
end
|
||||
|
||||
@@ -174,24 +174,22 @@ local function fetch_status(worktree, callback)
|
||||
table.insert(groups.Unmerged, entry)
|
||||
else
|
||||
if x ~= " " then
|
||||
table.insert(
|
||||
groups.Staged,
|
||||
vim.tbl_extend(
|
||||
"force",
|
||||
entry,
|
||||
{ section = "Staged" }
|
||||
)
|
||||
)
|
||||
table.insert(groups.Staged, {
|
||||
section = "Staged",
|
||||
path = entry.path,
|
||||
orig = entry.orig,
|
||||
x = entry.x,
|
||||
y = entry.y,
|
||||
})
|
||||
end
|
||||
if y ~= " " then
|
||||
table.insert(
|
||||
groups.Unstaged,
|
||||
vim.tbl_extend(
|
||||
"force",
|
||||
entry,
|
||||
{ section = "Unstaged" }
|
||||
)
|
||||
)
|
||||
table.insert(groups.Unstaged, {
|
||||
section = "Unstaged",
|
||||
path = entry.path,
|
||||
orig = entry.orig,
|
||||
x = entry.x,
|
||||
y = entry.y,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user