From f79430e2ce2e952dc9a9e1ff54826ed4e45360da Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 10 Aug 2025 07:27:53 +0800 Subject: [PATCH] vim-patch:9.1.1615: diff format erroneously detected (#35276) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: diff format erroneously detected (Tomáš Janoušek) Solution: Make the regex to detect normal diff format a bit stricter, while at it, fix wrong test content from patch v9.1.1606 fixes: vim/vim#17946 https://github.com/vim/vim/commit/887b4981e7e929ce8676b1b524e47a7fb5a8288b Co-authored-by: Christian Brabandt --- runtime/lua/vim/filetype/detect.lua | 3 ++- test/old/testdir/test_filetype.vim | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index 2ace52f4fc..f20f2a0ecd 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -2063,6 +2063,7 @@ local patterns_text = { -- Diff file: -- - "diff" in first line (context diff) -- - "Only in " in first line + -- - "34,35c34,35" normal diff format output -- - "--- " in first line and "+++ " in second line (unified diff). -- - "*** " in first line and "--- " in second line (context diff). -- - "# It was generated by makepatch " in the second line (makepatch diff). @@ -2071,7 +2072,7 @@ local patterns_text = { -- - "=== ", "--- ", "+++ " (bzr diff, common case) -- - "=== (removed|added|renamed|modified)" (bzr diff, alternative) -- - "# HG changeset patch" in first line (Mercurial export format) - ['^\\(diff\\>\\|Only in \\|\\d\\+\\(,\\d\\+\\)\\=[cda]\\d\\+\\>\\|# It was generated by makepatch \\|Index:\\s\\+\\f\\+\\r\\=$\\|===== \\f\\+ \\d\\+\\.\\d\\+ vs edited\\|==== //\\f\\+#\\d\\+\\|# HG changeset patch\\)'] = { + ['^\\(diff\\>\\|Only in \\|\\d\\+\\(,\\d\\+\\)\\=[cda]\\d\\+\\(,\\d\\+\\)\\=\\>$\\|# It was generated by makepatch \\|Index:\\s\\+\\f\\+\\r\\=$\\|===== \\f\\+ \\d\\+\\.\\d\\+ vs edited\\|==== //\\f\\+#\\d\\+\\|# HG changeset patch\\)'] = { 'diff', { vim_regex = true }, }, diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim index d38c4a45d9..f1c84718bf 100644 --- a/test/old/testdir/test_filetype.vim +++ b/test/old/testdir/test_filetype.vim @@ -2993,7 +2993,7 @@ endfunc func Test_info_file() filetype on - call writefile(['File: coreutils.info, Node: Top, Next: Introduction, Up: (dir)', 'D'], 'Xfile', 'D') + call writefile(['File: coreutils.info, Node: Top, Next: Introduction, Up: (dir)'], 'Xfile', 'D') split Xfile call assert_equal('info', &filetype) bwipe! @@ -3004,7 +3004,7 @@ endfunc func Test_mail_file() filetype on - call writefile(['Return-path: ', 'D'], 'Xfile', 'D') + call writefile(['Return-path: '], 'Xfile', 'D') split Xfile call assert_equal('mail', &filetype) bwipe! @@ -3015,7 +3015,7 @@ endfunc func Test_terminfo_file() filetype on - call writefile(['# Reconstructed via infocmp from file: /etc/terminfo/x/xterm', 'D'], 'Xfile', 'D') + call writefile(['# Reconstructed via infocmp from file: /etc/terminfo/x/xterm'], 'Xfile', 'D') split Xfile call assert_equal('terminfo', &filetype) bwipe! @@ -3035,4 +3035,15 @@ func Test_pacmanlog() filetype off endfunc +func Test_diff_format() + filetype on + + call writefile(['0d555557 1 (John John 2025-01-01 00:00:00 +0000 1) foo'], 'Xdiff', 'D') + split Xdiff + call assert_true(empty(&filetype)) + bwipe! + + filetype off +endfunc + " vim: shiftwidth=2 sts=2 expandtab