feat: use vim.iconv

This commit is contained in:
Lewis Russell 2022-12-16 11:57:55 +00:00 committed by Lewis Russell
parent 947811c7d3
commit ee61b323e1
4 changed files with 27 additions and 9 deletions

3
lua/gitsigns.lua generated
View File

@ -222,6 +222,9 @@ local attach_throttled = throttle_by_id(function(cbuf, aucmd)
local file, commit = get_buf_path(cbuf)
local encoding = vim.bo[cbuf].fileencoding
if encoding == '' then
encoding = 'utf-8'
end
local file_dir = util.dirname(file)

14
lua/gitsigns/git.lua generated
View File

@ -359,11 +359,17 @@ function Repo:get_show_text(object, encoding)
local stdout, stderr = self:command({ 'show', object }, { suppress_stderr = true })
if encoding ~= 'utf-8' then
scheduler()
for i, l in ipairs(stdout) do
if vim.iconv then
for i, l in ipairs(stdout) do
stdout[i] = vim.iconv(l, encoding, 'utf-8')
end
else
scheduler()
for i, l in ipairs(stdout) do
if vim.fn.type(l) == vim.v.t_string then
stdout[i] = vim.fn.iconv(l, encoding, 'utf-8')
if vim.fn.type(l) == vim.v.t_string then
stdout[i] = vim.fn.iconv(l, encoding, 'utf-8')
end
end
end
end

View File

@ -222,6 +222,9 @@ local attach_throttled = throttle_by_id(function(cbuf: integer, aucmd: string)
local file, commit = get_buf_path(cbuf)
local encoding = vim.bo[cbuf].fileencoding
if encoding == '' then
encoding = 'utf-8'
end
local file_dir = util.dirname(file)

View File

@ -359,11 +359,17 @@ function Repo:get_show_text(object: string, encoding: string): {string}, string
local stdout, stderr = self:command({'show', object}, {suppress_stderr = true})
if encoding ~= 'utf-8' then
scheduler()
for i, l in ipairs(stdout) do
-- TODO(lewis6991): How should we handle blob types?
if vim.fn.type(l) == vim.v.t_string then
stdout[i] = vim.fn.iconv(l, encoding, 'utf-8')
if vim.iconv then
for i, l in ipairs(stdout) do
stdout[i] = vim.iconv(l, encoding, 'utf-8')
end
else
scheduler()
for i, l in ipairs(stdout) do
-- vimscript will interpret strings containing NUL as blob type
if vim.fn.type(l) == vim.v.t_string then
stdout[i] = vim.fn.iconv(l, encoding, 'utf-8')
end
end
end
end