mirror of
https://github.com/lewis6991/gitsigns.nvim
synced 2025-02-23 08:16:53 +00:00
fix: use iconv for non-utf-8 encodings
Neovim appears to be built with iconv. We can access this to convert non-utf-8 command outputs (e.g. from 'git show <file>'). Fixes #522
This commit is contained in:
parent
e899189c36
commit
9e0cc25cbe
2
lua/gitsigns.lua
generated
2
lua/gitsigns.lua
generated
@ -241,7 +241,7 @@ local attach0 = function(cbuf, aucmd)
|
||||
return
|
||||
end
|
||||
|
||||
local git_obj = git.Obj.new(file)
|
||||
local git_obj = git.Obj.new(file, vim.bo[cbuf].fileencoding)
|
||||
if not git_obj then
|
||||
dprint('Empty git obj')
|
||||
return
|
||||
|
11
lua/gitsigns/git.lua
generated
11
lua/gitsigns/git.lua
generated
@ -108,6 +108,7 @@ local M = {BlameInfo = {}, Version = {}, Repo = {}, FileProps = {}, Obj = {}, }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
local in_git_dir = function(file)
|
||||
@ -392,6 +393,13 @@ Obj.get_show_text = function(self, revision)
|
||||
end
|
||||
end
|
||||
|
||||
if self.encoding ~= 'utf-8' then
|
||||
scheduler()
|
||||
for i, l in ipairs(stdout) do
|
||||
stdout[i] = vim.fn.iconv(l, self.encoding, 'utf-8')
|
||||
end
|
||||
end
|
||||
|
||||
return stdout, stderr
|
||||
end
|
||||
|
||||
@ -508,7 +516,7 @@ Obj.has_moved = function(self)
|
||||
end
|
||||
end
|
||||
|
||||
Obj.new = function(file)
|
||||
Obj.new = function(file, encoding)
|
||||
if in_git_dir(file) then
|
||||
dprint('In git dir')
|
||||
return nil
|
||||
@ -516,6 +524,7 @@ Obj.new = function(file)
|
||||
local self = setmetatable({}, { __index = Obj })
|
||||
|
||||
self.file = file
|
||||
self.encoding = encoding
|
||||
self.repo = Repo.new(util.dirname(file))
|
||||
|
||||
if not self.repo.gitdir then
|
||||
|
@ -11,11 +11,15 @@ end
|
||||
|
||||
local record ffi
|
||||
cdef: function(string)
|
||||
new: function(string, ...:any)
|
||||
load: function(string): any
|
||||
new: function(string, ...:any): any
|
||||
string: function(any, number): string
|
||||
gc: function(any, any): any
|
||||
gc: function<T>(T, function): T
|
||||
C: Cdefs
|
||||
cast: function(string, function): CCB
|
||||
cast: function(string, any): CCB
|
||||
errno: function(): integer
|
||||
copy: function
|
||||
metatype: function(string, any)
|
||||
end
|
||||
|
||||
return ffi
|
||||
|
@ -241,7 +241,7 @@ local attach0 = function(cbuf: integer, aucmd: string)
|
||||
return
|
||||
end
|
||||
|
||||
local git_obj = git.Obj.new(file)
|
||||
local git_obj = git.Obj.new(file, vim.bo[cbuf].fileencoding)
|
||||
if not git_obj then
|
||||
dprint('Empty git obj')
|
||||
return
|
||||
|
@ -94,6 +94,7 @@ local record M
|
||||
has_conflicts : boolean
|
||||
i_crlf : boolean -- Object has crlf
|
||||
w_crlf : boolean -- Working copy has crlf
|
||||
encoding : string
|
||||
|
||||
command : function(Obj, {string}, GJobSpec): {string}, string
|
||||
update_file_info : function(Obj, boolean): boolean
|
||||
@ -105,7 +106,7 @@ local record M
|
||||
stage_hunks : function(Obj, {Hunk}, boolean)
|
||||
stage_lines : function(Obj, {string})
|
||||
has_moved : function(Obj): string
|
||||
new : function(string): Obj
|
||||
new : function(string, string): Obj
|
||||
end
|
||||
|
||||
end
|
||||
@ -392,6 +393,13 @@ Obj.get_show_text = function(self: Obj, revision: string): {string}, string
|
||||
end
|
||||
end
|
||||
|
||||
if self.encoding ~= 'utf-8' then
|
||||
scheduler()
|
||||
for i, l in ipairs(stdout) do
|
||||
stdout[i] = vim.fn.iconv(l, self.encoding, 'utf-8')
|
||||
end
|
||||
end
|
||||
|
||||
return stdout, stderr
|
||||
end
|
||||
|
||||
@ -508,7 +516,7 @@ Obj.has_moved = function(self: Obj): string
|
||||
end
|
||||
end
|
||||
|
||||
Obj.new = function(file: string): Obj
|
||||
Obj.new = function(file: string, encoding: string): Obj
|
||||
if in_git_dir(file) then
|
||||
dprint('In git dir')
|
||||
return nil
|
||||
@ -516,6 +524,7 @@ Obj.new = function(file: string): Obj
|
||||
local self = setmetatable({} as Obj, {__index = Obj})
|
||||
|
||||
self.file = file
|
||||
self.encoding = encoding
|
||||
self.repo = Repo.new(util.dirname(file))
|
||||
|
||||
if not self.repo.gitdir then
|
||||
|
@ -216,6 +216,7 @@ end
|
||||
global record vim
|
||||
api: api
|
||||
record fn
|
||||
iconv: function(string, string, string): string
|
||||
line: function(string): integer
|
||||
join: function({any}, string): string
|
||||
getpos: function(string): {integer}
|
||||
@ -307,6 +308,7 @@ global record vim
|
||||
record BufOption
|
||||
{BufOption}
|
||||
fileformat: string
|
||||
fileencoding: string
|
||||
filetype: string
|
||||
modifiable: boolean
|
||||
modified: boolean
|
||||
|
Loading…
Reference in New Issue
Block a user