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