patch 9.1.0740: incorrect internal diff with empty file

Commit: 
https://github.com/vim/vim/commit/f1694b439bb175d956b49da620f1253462ec507b
Author: Yukihiro Nakadaira <yukihiro.nakada...@gmail.com>
Date:   Sun Sep 22 11:26:13 2024 +0200

    patch 9.1.0740: incorrect internal diff with empty file
    
    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: #15719
    
    Signed-off-by: Yukihiro Nakadaira <yukihiro.nakada...@gmail.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/diff.c b/src/diff.c
index c50670cdf..70e281439 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -760,6 +760,13 @@ diff_write_buffer(buf_T *buf, diffin_T *din)
     long       len = 0;
     char_u     *ptr;
 
+    if (buf->b_ml.ml_flags & ML_EMPTY)
+    {
+       din->din_mmfile.ptr = NULL;
+       din->din_mmfile.size = 0;
+       return OK;
+    }
+
     // xdiff requires one big block of memory with all the text.
     for (lnum = 1; lnum <= buf->b_ml.ml_line_count; ++lnum)
        len += ml_get_buf_len(buf, lnum) + 1;
diff --git a/src/testdir/dumps/Test_diff_21.dump 
b/src/testdir/dumps/Test_diff_21.dump
new file mode 100644
index 000000000..8fc8c6c08
--- /dev/null
+++ b/src/testdir/dumps/Test_diff_21.dump
@@ -0,0 +1,20 @@
+| +0#0000e05#a8a8a8255@1|0+0#0000000#5fd7ff255| @33||+1&#ffffff0| 
+0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34
+|~+0&#ffffff0| @35||+1#0000000&| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@34
+|~+0#4040ff13&| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|X+3#0000000&|d|i|f|i|l|e|1| @10|1|,|1| @11|A|l@1| |X+1&&|d|i|f|i|l|e|2| 
@10|0|,|0|-|1| @9|A|l@1
+|:+0&&> @73
diff --git a/src/testdir/dumps/Test_diff_22.dump 
b/src/testdir/dumps/Test_diff_22.dump
new file mode 100644
index 000000000..5ab9ae2bb
--- /dev/null
+++ b/src/testdir/dumps/Test_diff_22.dump
@@ -0,0 +1,20 @@
+| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@34||+1#0000000#ffffff0| 
+0#0000e05#a8a8a8255@1|0+0#0000000#5fd7ff255| @33
+| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@34||+1&&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|~| @35||+1#0000000&|~+0#4040ff13&| @35
+|X+3#0000000&|d|i|f|i|l|e|1| @10|0|,|0|-|1| @9|A|l@1| |X+1&&|d|i|f|i|l|e|2| 
@10|1|,|1| @11|A|l@1
+|:+0&&> @73
diff --git a/src/testdir/test_diffmode.vim b/src/testdir/test_diffmode.vim
index 098d5d0fc..c391f2dc8 100644
--- a/src/testdir/test_diffmode.vim
+++ b/src/testdir/test_diffmode.vim
@@ -1015,9 +1015,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 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")
 
+  " 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
   call StopVimInTerminal(buf)
   call delete('Xdifile1')
diff --git a/src/version.c b/src/version.c
index f4b755471..4669e37de 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    740,
 /**/
     739,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1ssIuu-00GZTw-Ca%40256bit.org.

Raspunde prin e-mail lui