mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 14:08:32 +00:00
vim-patch:9.1.0740: incorrect internal diff with empty file (#30471)
Problem: incorrect internal diff with an empty file
Solution: Set pointer to NULL, instead of using an empty line file
(Yukihiro Nakadaira)
When using internal diff, empty file is read as one empty line file.
So result differs from external diff.
closes: vim/vim#15719
f1694b439b
Co-authored-by: Yukihiro Nakadaira <yukihiro.nakadaira@gmail.com>
This commit is contained in:
@@ -736,6 +736,12 @@ static void clear_diffout(diffout_T *dout)
|
|||||||
/// @return FAIL for failure.
|
/// @return FAIL for failure.
|
||||||
static int diff_write_buffer(buf_T *buf, mmfile_t *m, linenr_T start, linenr_T end)
|
static int diff_write_buffer(buf_T *buf, mmfile_t *m, linenr_T start, linenr_T end)
|
||||||
{
|
{
|
||||||
|
if (buf->b_ml.ml_flags & ML_EMPTY) {
|
||||||
|
m->ptr = NULL;
|
||||||
|
m->size = 0;
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
if (end < 0) {
|
if (end < 0) {
|
||||||
|
@@ -614,6 +614,34 @@ int main(int argc, char **argv)
|
|||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('Diff empty and non-empty file', function()
|
||||||
|
write_file(fname, '', false)
|
||||||
|
write_file(fname_2, 'foo\nbar\nbaz', false)
|
||||||
|
reread()
|
||||||
|
|
||||||
|
feed(':set diffopt=filler<cr>')
|
||||||
|
screen:expect([[
|
||||||
|
{7: }{23:------------------}│{7: }{22:foo }|
|
||||||
|
{7: }{23:------------------}│{7: }{22:bar }|
|
||||||
|
{7: }{23:------------------}│{7: }{22:baz }|
|
||||||
|
{7: }^ │{1:~ }|
|
||||||
|
{1:~ }│{1:~ }|*10
|
||||||
|
{3:<onal-diff-screen-1 }{2:<l-diff-screen-1.2 }|
|
||||||
|
:set diffopt=filler |
|
||||||
|
]])
|
||||||
|
|
||||||
|
feed(':set diffopt+=internal<cr>')
|
||||||
|
screen:expect([[
|
||||||
|
{7: }{23:------------------}│{7: }{22:foo }|
|
||||||
|
{7: }{23:------------------}│{7: }{22:bar }|
|
||||||
|
{7: }{23:------------------}│{7: }{22:baz }|
|
||||||
|
{7: }^ │{1:~ }|
|
||||||
|
{1:~ }│{1:~ }|*10
|
||||||
|
{3:<onal-diff-screen-1 }{2:<l-diff-screen-1.2 }|
|
||||||
|
:set diffopt+=internal |
|
||||||
|
]])
|
||||||
|
end)
|
||||||
|
|
||||||
it('diffopt+=icase', function()
|
it('diffopt+=icase', function()
|
||||||
write_file(fname, 'a\nb\ncd\n', false)
|
write_file(fname, 'a\nb\ncd\n', false)
|
||||||
write_file(fname_2, 'A\nb\ncDe\n', false)
|
write_file(fname_2, 'A\nb\ncDe\n', false)
|
||||||
|
@@ -596,13 +596,13 @@ describe('highlight', function()
|
|||||||
]])
|
]])
|
||||||
screen:expect(
|
screen:expect(
|
||||||
[[
|
[[
|
||||||
{1: }^ |
|
{1: }{5:^ }|
|
||||||
{1: }{2:01}{3:234 67}{2:89}{5: }|
|
{1: }{2:01}{3:234 67}{2:89}{5: }|
|
||||||
{4:~ }|*2
|
{4:~ }|*2
|
||||||
{7:[No Name] [+] }|
|
{7:[No Name] [+] }|
|
||||||
{1: } |
|
|
||||||
{1: }{6:-----------------------}|
|
{1: }{6:-----------------------}|
|
||||||
{4:~ }|
|
{1: }{6:-----------------------}|
|
||||||
|
{1: } |
|
||||||
{8:[No Name] }|
|
{8:[No Name] }|
|
||||||
|
|
|
|
||||||
]],
|
]],
|
||||||
|
@@ -997,9 +997,17 @@ func Test_diff_screen()
|
|||||||
call WriteDiffFiles(buf, ['a ', 'x', 'cd', 'ef', 'xx xx', 'foo', 'bar'], ['a', 'x', 'c d', ' ef', 'xx xx', 'foo', '', 'bar'])
|
call WriteDiffFiles(buf, ['a ', 'x', 'cd', 'ef', 'xx xx', 'foo', 'bar'], ['a', 'x', 'c d', ' ef', 'xx xx', 'foo', '', 'bar'])
|
||||||
call VerifyInternal(buf, 'Test_diff_19', " diffopt+=iwhiteeol")
|
call VerifyInternal(buf, 'Test_diff_19', " diffopt+=iwhiteeol")
|
||||||
|
|
||||||
" Test 19: test diffopt+=iwhiteall
|
" Test 20: test diffopt+=iwhiteall
|
||||||
call VerifyInternal(buf, 'Test_diff_20', " diffopt+=iwhiteall")
|
call VerifyInternal(buf, 'Test_diff_20', " diffopt+=iwhiteall")
|
||||||
|
|
||||||
|
" Test 21: Delete all lines
|
||||||
|
call WriteDiffFiles(buf, [0], [])
|
||||||
|
call VerifyBoth(buf, "Test_diff_21", "")
|
||||||
|
|
||||||
|
" Test 22: Add line to empty file
|
||||||
|
call WriteDiffFiles(buf, [], [0])
|
||||||
|
call VerifyBoth(buf, "Test_diff_22", "")
|
||||||
|
|
||||||
" clean up
|
" clean up
|
||||||
call StopVimInTerminal(buf)
|
call StopVimInTerminal(buf)
|
||||||
call delete('Xdifile1')
|
call delete('Xdifile1')
|
||||||
|
Reference in New Issue
Block a user