mirror of
https://github.com/lewis6991/gitsigns.nvim
synced 2025-04-07 01:52:08 +00:00
- Simplify external diff code and make it's api consistent with FFI diff. - Move diff code into separate modules diff_ext and diff_ffi.
83 lines
1.3 KiB
Lua
Generated
83 lines
1.3 KiB
Lua
Generated
local git = require('gitsigns.git')
|
|
|
|
local gs_hunks = require("gitsigns.hunks")
|
|
local Hunk = gs_hunks.Hunk
|
|
local util = require('gitsigns.util')
|
|
local a = require('plenary.async')
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
|
|
local function write_to_file(path, text)
|
|
local f, err = io.open(path, 'wb')
|
|
if f == nil then
|
|
error(err)
|
|
end
|
|
for _, l in ipairs(text) do
|
|
f:write(l)
|
|
f:write('\n')
|
|
end
|
|
f:close()
|
|
end
|
|
|
|
M.run_diff = function(
|
|
text_cmp,
|
|
text_buf,
|
|
diff_algo)
|
|
|
|
local results = {}
|
|
|
|
if not util.is_unix then
|
|
|
|
a.util.scheduler()
|
|
end
|
|
|
|
local file_buf = util.tmpname() .. '_buf'
|
|
local file_cmp = util.tmpname() .. '_cmp'
|
|
|
|
write_to_file(file_buf, text_buf)
|
|
write_to_file(file_cmp, text_cmp)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
git.command({
|
|
'-c', 'core.safecrlf=false',
|
|
'diff',
|
|
'--color=never',
|
|
'--diff-algorithm=' .. diff_algo,
|
|
'--patch-with-raw',
|
|
'--unified=0',
|
|
file_cmp,
|
|
file_buf,
|
|
}, {
|
|
on_stdout = function(_, line)
|
|
if vim.startswith(line, '@@') then
|
|
table.insert(results, gs_hunks.parse_diff_line(line))
|
|
elseif #results > 0 then
|
|
table.insert(results[#results].lines, line)
|
|
end
|
|
end,
|
|
})
|
|
os.remove(file_buf)
|
|
os.remove(file_cmp)
|
|
return results
|
|
end
|
|
|
|
return M
|