Refactor git part

This commit is contained in:
Olivier Roques
2021-05-21 11:31:37 +02:00
parent 680cfeb074
commit 88beb047ea
2 changed files with 31 additions and 31 deletions

View File

@@ -2,7 +2,9 @@ local fn, vim = vim.fn, vim
local fmt = string.format
local function is_excluded(bufnr, settings)
local excluded = fn.buflisted(bufnr) == 0 or fn.getbufvar(bufnr, '&filetype') == 'qf'
local excluded = true
excluded = excluded and fn.buflisted(bufnr) == 0
excluded = excluded or fn.getbufvar(bufnr, '&filetype') == 'qf'
if settings.exclude_terminal then
excluded = excluded or fn.getbufvar(bufnr, '&buftype') == 'terminal'
end

View File

@@ -3,33 +3,33 @@ local g = vim.g
local b = vim.b
local fmt = string.format
local function get_hunks()
local summary
if g.loaded_gitgutter then
summary = fn.GitGutterGetHunkSummary()
elseif g.loaded_signify then
summary = fn['sy#repo#get_stats']()
if (summary[1] == -1) then -- signify returns {-1, -1, -1} in empty buffer
return ''
end
elseif b.gitsigns_status_dict ~= nil then
local status_dict = b.gitsigns_status_dict
if status_dict.added == nil then
return ''
end
summary = {status_dict.added, status_dict.changed, status_dict.removed}
else
return ''
end
return table.concat({
fmt('+%d', summary[1]),
fmt('~%d', summary[2]),
fmt('-%d', summary[3]),
local function concat_hunks(hunks)
return vim.tbl_isempty(hunks) and '' or table.concat({
fmt('+%d', hunks[1]),
fmt('~%d', hunks[2]),
fmt('-%d', hunks[3]),
}, ' ')
end
local function get_hunks()
local hunks = {}
if g.loaded_gitgutter then
hunks = fn.GitGutterGetHunkSummary()
elseif g.loaded_signify then
hunks = fn['sy#repo#get_stats']()
hunks = hunks[1] == -1 and {} or hunks
elseif b.gitsigns_status_dict then
hunks = {
b.gitsigns_status_dict.added,
b.gitsigns_status_dict.changed,
b.gitsigns_status_dict.removed,
}
end
return concat_hunks(hunks)
end
local function get_branch()
local branch
local branch = ''
if g.loaded_fugitive then
branch = fn.FugitiveHead()
elseif g.loaded_gina then
@@ -44,14 +44,12 @@ end
local function get_item()
local hunks, branch = get_hunks(), get_branch()
if branch == '' then
if hunks == '+0 ~0 -0' then
return ''
else
return hunks
end
if hunks == concat_hunks({0, 0, 0}) and branch == '' then
hunks = ''
end
if hunks ~= '' and branch ~= '' then
branch = ' ' .. branch
end
branch = not branch and '' or ' ' .. branch
return table.concat({hunks, branch})
end