summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames McCoy <jamessan@jamessan.com>2021-12-17 20:52:57 +0000
committerBram Moolenaar <Bram@vim.org>2021-12-17 20:52:57 +0000
commit647ab4cede4dbf412d24748f8e0a64d1cb9239f4 (patch)
tree0c2968d46f26a02dbf2f8aaba7c50cea26b1f614
parent422085f1c87cb6bea879158b8b05c4a5cf7ab48b (diff)
downloadvim-git-647ab4cede4dbf412d24748f8e0a64d1cb9239f4.tar.gz
patch 8.2.3843: dep3patch files are not recognizedv8.2.3843
Problem: Dep3patch files are not recognized. Solution: Recognize dep3patch files by their location and content. (James McCoy, closes #9367)
-rw-r--r--runtime/autoload/dist/ft.vim17
-rw-r--r--runtime/filetype.vim3
-rw-r--r--src/testdir/test_filetype.vim40
-rw-r--r--src/version.c2
4 files changed, 62 insertions, 0 deletions
diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim
index a3db4ae87..366d7b009 100644
--- a/runtime/autoload/dist/ft.vim
+++ b/runtime/autoload/dist/ft.vim
@@ -811,6 +811,23 @@ func dist#ft#Redif()
endwhile
endfunc
+" This function is called for all files under */debian/patches/*, make sure not
+" to non-dep3patch files, such as README and other text files.
+func dist#ft#Dep3patch()
+ if expand('%:t') ==# 'series'
+ return
+ endif
+
+ for ln in getline(1, 100)
+ if ln =~# '^\%(Description\|Subject\|Origin\|Bug\|Forwarded\|Author\|From\|Reviewed-by\|Acked-by\|Last-Updated\|Applied-Upstream\):'
+ setf dep3patch
+ return
+ elseif ln =~# '^---'
+ " end of headers found. stop processing
+ return
+ endif
+ endfor
+endfunc
" Restore 'cpoptions'
let &cpo = s:cpo_save
diff --git a/runtime/filetype.vim b/runtime/filetype.vim
index d99527f17..7740d8faa 100644
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -490,6 +490,9 @@ au BufNewFile,BufRead dict.conf,.dictrc setf dictconf
" Dictd config
au BufNewFile,BufRead dictd*.conf setf dictdconf
+" DEP3 formatted patch files
+au BufNewFile,BufRead */debian/patches/* call dist#ft#Dep3patch()
+
" Diff files
au BufNewFile,BufRead *.diff,*.rej setf diff
au BufNewFile,BufRead *.patch
diff --git a/src/testdir/test_filetype.vim b/src/testdir/test_filetype.vim
index f4204f7e8..cd82e3814 100644
--- a/src/testdir/test_filetype.vim
+++ b/src/testdir/test_filetype.vim
@@ -1029,4 +1029,44 @@ func Test_fs_file()
filetype off
endfunc
+func Test_dep3patch_file()
+ filetype on
+
+ call assert_true(mkdir('debian/patches', 'p'))
+
+ " series files are not patches
+ call writefile(['Description: some awesome patch'], 'debian/patches/series')
+ split debian/patches/series
+ call assert_notequal('dep3patch', &filetype)
+ bwipe!
+
+ " diff/patch files without the right headers should still show up as ft=diff
+ call writefile([], 'debian/patches/foo.diff')
+ split debian/patches/foo.diff
+ call assert_equal('diff', &filetype)
+ bwipe!
+
+ " Files with the right headers are detected as dep3patch, even if they don't
+ " have a diff/patch extension
+ call writefile(['Subject: dep3patches'], 'debian/patches/bar')
+ split debian/patches/bar
+ call assert_equal('dep3patch', &filetype)
+ bwipe!
+
+ " Files in sub-directories are detected
+ call assert_true(mkdir('debian/patches/s390x', 'p'))
+ call writefile(['Subject: dep3patches'], 'debian/patches/s390x/bar')
+ split debian/patches/s390x/bar
+ call assert_equal('dep3patch', &filetype)
+ bwipe!
+
+ " The detection stops when seeing the "header end" marker
+ call writefile(['---', 'Origin: the cloud'], 'debian/patches/baz')
+ split debian/patches/baz
+ call assert_notequal('dep3patch', &filetype)
+ bwipe!
+
+ call delete('debian/patches', 'rf')
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index d90560f9b..0e2a2298f 100644
--- a/src/version.c
+++ b/src/version.c
@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 3843,
+/**/
3842,
/**/
3841,