refactor(git): split status code parsing into status.lua
This commit is contained in:
@@ -2,45 +2,6 @@ local util = require("git.util")
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.UNMERGED = {
|
|
||||||
DD = true,
|
|
||||||
AU = true,
|
|
||||||
UD = true,
|
|
||||||
UA = true,
|
|
||||||
DU = true,
|
|
||||||
AA = true,
|
|
||||||
UU = true,
|
|
||||||
}
|
|
||||||
|
|
||||||
---@param code string
|
|
||||||
---@return string? char
|
|
||||||
---@return string? hl_group
|
|
||||||
function M.indicator(code)
|
|
||||||
if code == "" then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
if code == "??" then
|
|
||||||
return "?", "GitUntracked"
|
|
||||||
end
|
|
||||||
if code == "!!" then
|
|
||||||
return "!", "GitIgnored"
|
|
||||||
end
|
|
||||||
if M.UNMERGED[code] then
|
|
||||||
return "U", "GitUnmerged"
|
|
||||||
end
|
|
||||||
local x, y = code:sub(1, 1), code:sub(2, 2)
|
|
||||||
if x == "R" or y == "R" then
|
|
||||||
return "R", "GitRenamed"
|
|
||||||
end
|
|
||||||
if y == " " and x ~= " " then
|
|
||||||
return x, "GitStaged"
|
|
||||||
end
|
|
||||||
if y == "D" then
|
|
||||||
return "D", "GitDeleted"
|
|
||||||
end
|
|
||||||
return "M", "GitUnstaged"
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param path string
|
---@param path string
|
||||||
---@return string? gitdir
|
---@return string? gitdir
|
||||||
---@return string? worktree
|
---@return string? worktree
|
||||||
|
|||||||
+3
-2
@@ -2,6 +2,7 @@ local Revision = require("git.revision")
|
|||||||
local diff = require("git.diff")
|
local diff = require("git.diff")
|
||||||
local object = require("git.object")
|
local object = require("git.object")
|
||||||
local repo = require("git.repo")
|
local repo = require("git.repo")
|
||||||
|
local status = require("git.status")
|
||||||
local util = require("git.util")
|
local util = require("git.util")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
@@ -99,7 +100,7 @@ local function format_entry(entry)
|
|||||||
if not code then
|
if not code then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
local char, hl = repo.indicator(code)
|
local char, hl = status.indicator(code)
|
||||||
if not char then
|
if not char then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@@ -177,7 +178,7 @@ local function parse_porcelain(stdout)
|
|||||||
if x == "?" and y == "?" then
|
if x == "?" and y == "?" then
|
||||||
entry.section = "Untracked"
|
entry.section = "Untracked"
|
||||||
table.insert(groups.Untracked, entry)
|
table.insert(groups.Untracked, entry)
|
||||||
elseif repo.UNMERGED[x .. y] then
|
elseif status.UNMERGED[x .. y] then
|
||||||
entry.section = "Unmerged"
|
entry.section = "Unmerged"
|
||||||
table.insert(groups.Unmerged, entry)
|
table.insert(groups.Unmerged, entry)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
M.UNMERGED = {
|
||||||
|
DD = true,
|
||||||
|
AU = true,
|
||||||
|
UD = true,
|
||||||
|
UA = true,
|
||||||
|
DU = true,
|
||||||
|
AA = true,
|
||||||
|
UU = true,
|
||||||
|
}
|
||||||
|
|
||||||
|
---@param code string
|
||||||
|
---@return string? char
|
||||||
|
---@return string? hl_group
|
||||||
|
function M.indicator(code)
|
||||||
|
if code == "" then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
if code == "??" then
|
||||||
|
return "?", "GitUntracked"
|
||||||
|
end
|
||||||
|
if code == "!!" then
|
||||||
|
return "!", "GitIgnored"
|
||||||
|
end
|
||||||
|
if M.UNMERGED[code] then
|
||||||
|
return "U", "GitUnmerged"
|
||||||
|
end
|
||||||
|
local x, y = code:sub(1, 1), code:sub(2, 2)
|
||||||
|
if x == "R" or y == "R" then
|
||||||
|
return "R", "GitRenamed"
|
||||||
|
end
|
||||||
|
if y == " " and x ~= " " then
|
||||||
|
return x, "GitStaged"
|
||||||
|
end
|
||||||
|
if y == "D" then
|
||||||
|
return "D", "GitDeleted"
|
||||||
|
end
|
||||||
|
return "M", "GitUnstaged"
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param code string
|
||||||
|
---@return string?
|
||||||
|
function M.format(code)
|
||||||
|
local char, hl = M.indicator(code)
|
||||||
|
if not char then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return string.format("%%#%s#%s%%*", hl, char)
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
+2
-11
@@ -1,18 +1,9 @@
|
|||||||
local repo = require("git.repo")
|
local repo = require("git.repo")
|
||||||
|
local status = require("git.status")
|
||||||
local util = require("git.util")
|
local util = require("git.util")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
---@param code string
|
|
||||||
---@return string?
|
|
||||||
local function format(code)
|
|
||||||
local char, hl = repo.indicator(code)
|
|
||||||
if not char then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
return string.format("%%#%s#%s%%*", hl, char)
|
|
||||||
end
|
|
||||||
|
|
||||||
---@class ow.Git.Repo
|
---@class ow.Git.Repo
|
||||||
---@field gitdir string
|
---@field gitdir string
|
||||||
---@field worktree string
|
---@field worktree string
|
||||||
@@ -89,7 +80,7 @@ local function do_refresh(r)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
statuses[vim.fs.joinpath(r.worktree, path_part)] =
|
statuses[vim.fs.joinpath(r.worktree, path_part)] =
|
||||||
format(code)
|
status.format(code)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user