From a66eca78c2082aca112125f759be2ef3aa7ef832 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 21 Aug 2017 12:10:15 -0400 Subject: vim-patch:8.0.0308 Problem: When using a symbolic link, the package path will not be inserted at the right position in 'runtimepath'. (Dugan Chen, Norio Takagi) Solution: Resolve symbolic links when finding the right position in 'runtimepath'. (Hirohito Higashi) https://github.com/vim/vim/commit/2f9e575583c2ad3978ee3d0f790eeff7df56bd6c --- src/nvim/ex_cmds2.c | 28 ++++++++++++++---------- src/nvim/version.c | 2 +- test/functional/legacy/packadd_spec.lua | 38 +++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 33fe30cd5a..f8c470f213 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -2498,6 +2498,7 @@ static int APP_BOTH; static void add_pack_plugin(char_u *fname, void *cookie) { char_u *p4, *p3, *p2, *p1, *p; + char_u *buf = NULL; char *const ffname = fix_fname((char *)fname); @@ -2525,26 +2526,30 @@ static void add_pack_plugin(char_u *fname, void *cookie) // Find "ffname" in "p_rtp", ignoring '/' vs '\' differences size_t fname_len = strlen(ffname); const char *insp = (const char *)p_rtp; - for (;;) { - if (path_fnamencmp(insp, ffname, fname_len) == 0) { - break; + buf = try_malloc(MAXPATHL); + if (buf == NULL) { + goto theend; + } + while (*insp != NUL) { + copy_option_part((char_u **)&insp, buf, MAXPATHL, ","); + add_pathsep((char *)buf); + char *const rtp_ffname = fix_fname((char *)buf); + if (rtp_ffname == NULL) { + goto theend; } - insp = strchr(insp, ','); - if (insp == NULL) { + bool match = path_fnamencmp(rtp_ffname, ffname, fname_len) == 0; + xfree(rtp_ffname); + if (match) { break; } - insp++; } - if (insp == NULL) { + if (*insp == NUL) { // not found, append at the end insp = (const char *)p_rtp + STRLEN(p_rtp); } else { // append after the matching directory. - insp += strlen(ffname); - while (*insp != NUL && *insp != ',') { - insp++; - } + insp--; } *p4 = c; @@ -2614,6 +2619,7 @@ static void add_pack_plugin(char_u *fname, void *cookie) } theend: + xfree(buf); xfree(ffname); } diff --git a/src/nvim/version.c b/src/nvim/version.c index 2a3fdbd70d..a190293d8e 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -644,7 +644,7 @@ static const int included_patches[] = { 311, // 310, // 309, - // 308, + 308, 307, // 306, // 305, diff --git a/test/functional/legacy/packadd_spec.lua b/test/functional/legacy/packadd_spec.lua index c280888dda..366a154f89 100644 --- a/test/functional/legacy/packadd_spec.lua +++ b/test/functional/legacy/packadd_spec.lua @@ -83,6 +83,39 @@ describe('packadd', function() call assert_equal(new_rtp, &rtp) endfunc + func Test_packadd_symlink_dir() + if !has('unix') + return + endif + let top2_dir = s:topdir . '/Xdir2' + let real_dir = s:topdir . '/Xsym' + silent !ln -s real_dir top2_dir + let &rtp = top2_dir . ',' . top2_dir . '/after' + let &packpath = &rtp + + let s:plugdir = top2_dir . '/pack/mine/opt/mytest' + call mkdir(s:plugdir . '/plugin', 'p') + + exe 'split ' . s:plugdir . '/plugin/test.vim' + call setline(1, 'let g:plugin_works = 44') + wq + let g:plugin_works = 0 + + packadd mytest + + " Must have been inserted in the middle, not at the end + call assert_true(&rtp =~ '/pack/mine/opt/mytest,') + call assert_equal(44, g:plugin_works) + + " No change when doing it again. + let rtp_before = &rtp + packadd mytest + call assert_equal(rtp_before, &rtp) + + set rtp& + let rtp = &rtp + endfunc + func Test_packloadall() " plugin foo with an autoload directory let fooplugindir = &packpath . '/pack/mine/start/foo/plugin' @@ -227,6 +260,11 @@ describe('packadd', function() expected_empty() end) + it('works with symlinks', function() + call('Test_packadd_symlink_dir') + expected_empty() + end) + it('works with :packloadall', function() call('Test_packloadall') expected_empty() -- cgit From 24a556419627d3369f0a55b95dce07cb5316cf8b Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 21 Aug 2017 12:37:24 -0400 Subject: vim-patch:8.0.0325 Problem: Packadd test does not clean up symlink. Solution: Delete the link. (Hirohito Higashi) https://github.com/vim/vim/commit/913727e56761d57aaba61197c2d3485418dea7eb --- src/nvim/version.c | 2 +- test/functional/legacy/packadd_spec.lua | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nvim/version.c b/src/nvim/version.c index a190293d8e..a0c46c0e3d 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -627,7 +627,7 @@ static const int included_patches[] = { // 328, // 327, // 326, - // 325, + 325, // 324, // 323, 322, diff --git a/test/functional/legacy/packadd_spec.lua b/test/functional/legacy/packadd_spec.lua index 366a154f89..ba6eba3ce3 100644 --- a/test/functional/legacy/packadd_spec.lua +++ b/test/functional/legacy/packadd_spec.lua @@ -114,6 +114,7 @@ describe('packadd', function() set rtp& let rtp = &rtp + silent !rm top2_dir endfunc func Test_packloadall() -- cgit From 651c6f9b6ebcd76fbf65045ab877fdf38b9d3db2 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 21 Aug 2017 12:38:24 -0400 Subject: vim-patch:8.0.0326 Problem: Packadd test uses wrong directory name. Solution: Use the variable name value. (Hirohito Higashi) https://github.com/vim/vim/commit/24f8f543d4036c5d2ce4ea6973a174cf2176cb72 --- src/nvim/version.c | 2 +- test/functional/legacy/packadd_spec.lua | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nvim/version.c b/src/nvim/version.c index a0c46c0e3d..92c776c1e8 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -626,7 +626,7 @@ static const int included_patches[] = { // 329, // 328, // 327, - // 326, + 326, 325, // 324, // 323, diff --git a/test/functional/legacy/packadd_spec.lua b/test/functional/legacy/packadd_spec.lua index ba6eba3ce3..620f2d7247 100644 --- a/test/functional/legacy/packadd_spec.lua +++ b/test/functional/legacy/packadd_spec.lua @@ -89,7 +89,7 @@ describe('packadd', function() endif let top2_dir = s:topdir . '/Xdir2' let real_dir = s:topdir . '/Xsym' - silent !ln -s real_dir top2_dir + exec "silent! !ln -s" real_dir top2_dir let &rtp = top2_dir . ',' . top2_dir . '/after' let &packpath = &rtp @@ -114,7 +114,7 @@ describe('packadd', function() set rtp& let rtp = &rtp - silent !rm top2_dir + exec "silent !rm" top2_dir endfunc func Test_packloadall() -- cgit From fc7bf1c71d41dae7b8ab7e82b92ec0e8253b5291 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 21 Aug 2017 12:46:07 -0400 Subject: vim-patch:8.0.0437 Problem: The packadd test does not create the symlink correctly and does not test the right thing. Solution: Create the directory and symlink correctly. https://github.com/vim/vim/commit/644df41c44cbdfacdedbba55ef77a6c6031eccd8 --- src/nvim/version.c | 2 +- test/functional/legacy/packadd_spec.lua | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/nvim/version.c b/src/nvim/version.c index 92c776c1e8..d4cbf32009 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -515,7 +515,7 @@ static const int included_patches[] = { // 440, // 439, // 438, - // 437, + 437, // 436, // 435, // 434, diff --git a/test/functional/legacy/packadd_spec.lua b/test/functional/legacy/packadd_spec.lua index 620f2d7247..7c44353aec 100644 --- a/test/functional/legacy/packadd_spec.lua +++ b/test/functional/legacy/packadd_spec.lua @@ -89,7 +89,8 @@ describe('packadd', function() endif let top2_dir = s:topdir . '/Xdir2' let real_dir = s:topdir . '/Xsym' - exec "silent! !ln -s" real_dir top2_dir + call mkdir(real_dir, 'p') + exec "silent! !ln -s Xsym" top2_dir let &rtp = top2_dir . ',' . top2_dir . '/after' let &packpath = &rtp -- cgit From 622c3454dff35cae7ec93383bbf49f16621dc778 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 21 Aug 2017 12:47:58 -0400 Subject: vim-patch:8.0.0612 Problem: Package directories are added to 'runtimepath' only after loading non-package plugins. Solution: Split off the code to add package directories to 'runtimepath'. (Ingo Karkat, closes vim/vim#1680) https://github.com/vim/vim/commit/ce876aaa9a250a5a0d0e34b3a2625e51cf9bf5bb --- src/nvim/ex_cmds2.c | 26 +++++++++++++++++--------- src/nvim/globals.h | 3 +++ src/nvim/main.c | 13 ++++++++++++- src/nvim/testdir/test_startup.vim | 32 ++++++++++++++++++++++++++++++++ src/nvim/version.c | 2 +- 5 files changed, 65 insertions(+), 11 deletions(-) diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index f8c470f213..df6b575c1c 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -2623,23 +2623,31 @@ theend: xfree(ffname); } -static bool did_source_packages = false; +/// Add all packages in the "start" directory to 'runtimepath'. +void add_pack_start_dirs(void) +{ + do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR, // NOLINT + add_pack_plugin, &APP_ADD_DIR); +} + +/// Load plugins from all packages in the "start" directory. +void load_start_packages(void) +{ + did_source_packages = true; + do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR, // NOLINT + add_pack_plugin, &APP_LOAD); +} // ":packloadall" // Find plugins in the package directories and source them. -// "eap" is NULL when invoked during startup. void ex_packloadall(exarg_T *eap) { - if (!did_source_packages || (eap != NULL && eap->forceit)) { - did_source_packages = true; - + if (!did_source_packages || eap->forceit) { // First do a round to add all directories to 'runtimepath', then load // the plugins. This allows for plugins to use an autoload directory // of another plugin. - do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR, // NOLINT - add_pack_plugin, &APP_ADD_DIR); - do_in_path(p_pp, (char_u *)"pack/*/start/*", DIP_ALL + DIP_DIR, // NOLINT - add_pack_plugin, &APP_LOAD); + add_pack_start_dirs(); + load_start_packages(); } } diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 13ecafcbe3..2ee72cdb6a 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -407,6 +407,9 @@ EXTERN int garbage_collect_at_exit INIT(= FALSE); /* ID of script being sourced or was sourced to define the current function. */ EXTERN scid_T current_SID INIT(= 0); + +EXTERN bool did_source_packages INIT(= false); + // Scope information for the code that indirectly triggered the current // provider function call EXTERN struct caller_scope { diff --git a/src/nvim/main.c b/src/nvim/main.c index a665ad1de2..6e85fbc130 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1291,10 +1291,21 @@ static void set_window_layout(mparm_T *paramp) static void load_plugins(void) { if (p_lpl) { + // First add all package directories to 'runtimepath', so that their + // autoload directories can be found. Only if not done already with a + // :packloadall command. + if (!did_source_packages) { + add_pack_start_dirs(); + } + source_runtime((char_u *)"plugin/**/*.vim", DIP_ALL | DIP_NOAFTER); // NOLINT TIME_MSG("loading plugins"); - ex_packloadall(NULL); + // Only source "start" packages if not done already with a :packloadall + // command. + if (!did_source_packages) { + load_start_packages(); + } TIME_MSG("loading packages"); source_runtime((char_u *)"plugin/**/*.vim", DIP_ALL | DIP_AFTER); diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index 5a38178bd5..2dce7faded 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -62,6 +62,38 @@ func Test_after_comes_later() call delete('Xafter', 'rf') endfunc +func Test_pack_in_rtp_when_plugins_run() + if !has('packages') + return + endif + let before = [ + \ 'set nocp viminfo+=nviminfo', + \ 'set guioptions+=M', + \ 'let $HOME = "/does/not/exist"', + \ 'set loadplugins', + \ 'set rtp=Xhere', + \ 'set packpath=Xhere', + \ 'set nomore', + \ ] + let after = [ + \ 'quit', + \ ] + call mkdir('Xhere/plugin', 'p') + call writefile(['redir! > Xtestout', 'silent set runtimepath?', 'silent! call foo#Trigger()', 'redir END'], 'Xhere/plugin/here.vim') + call mkdir('Xhere/pack/foo/start/foobar/autoload', 'p') + call writefile(['function! foo#Trigger()', 'echo "autoloaded foo"', 'endfunction'], 'Xhere/pack/foo/start/foobar/autoload/foo.vim') + + if RunVim(before, after, '') + + let lines = filter(readfile('Xtestout'), '!empty(v:val)') + call assert_match('Xhere[/\\]pack[/\\]foo[/\\]start[/\\]foobar', get(lines, 0)) + call assert_match('autoloaded foo', get(lines, 1)) + endif + + call delete('Xtestout') + call delete('Xhere', 'rf') +endfunc + func Test_help_arg() if !has('unix') && has('gui') " this doesn't work with gvim on MS-Windows diff --git a/src/nvim/version.c b/src/nvim/version.c index d4cbf32009..3313ffdfa9 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -340,7 +340,7 @@ static const int included_patches[] = { // 615, 614, // 613, - // 612, + 612, // 611, // 610, // 609, -- cgit From 41d180abb4693814be5833b0907e111ce46b3791 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 21 Aug 2017 12:54:22 -0400 Subject: vim-patch:8.0.0680 Problem: Plugins in start packages are sourced twice. (mseplowitz) Solution: Use the unmodified runtime path when loading plugins (test by Ingo Karkat, closes vim/vim#1801) https://github.com/vim/vim/commit/07ecfa64a18609a986f21d6132d04ee8934f3200 --- src/nvim/ex_cmds2.c | 43 +++++++++++++++++++++++++-------------- src/nvim/main.c | 10 ++++++++- src/nvim/testdir/test_startup.vim | 20 +++++++++++++----- src/nvim/version.c | 2 +- 4 files changed, 53 insertions(+), 22 deletions(-) diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index df6b575c1c..371f7b3bce 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -2319,16 +2319,6 @@ static void source_callback(char_u *fname, void *cookie) (void)do_source(fname, false, DOSO_NONE); } -/// Source the file "name" from all directories in 'runtimepath'. -/// "name" can contain wildcards. -/// When "flags" has DIP_ALL: source all files, otherwise only the first one. -/// -/// return FAIL when no file could be sourced, OK otherwise. -int source_runtime(char_u *name, int flags) -{ - return do_in_runtimepath(name, flags, source_callback, NULL); -} - /// Find the file "name" in all directories in "path" and invoke /// "callback(fname, cookie)". /// "name" can contain wildcards. @@ -2434,21 +2424,21 @@ int do_in_path(char_u *path, char_u *name, int flags, return did_one ? OK : FAIL; } -/// Find "name" in 'runtimepath'. When found, invoke the callback function for +/// Find "name" in "path". When found, invoke the callback function for /// it: callback(fname, "cookie") /// When "flags" has DIP_ALL repeat for all matches, otherwise only the first /// one is used. /// Returns OK when at least one match found, FAIL otherwise. -/// If "name" is NULL calls callback for each entry in runtimepath. Cookie is +/// If "name" is NULL calls callback for each entry in "path". Cookie is /// passed by reference in this case, setting it to NULL indicates that callback /// has done its job. -int do_in_runtimepath(char_u *name, int flags, DoInRuntimepathCB callback, - void *cookie) +int do_in_path_and_pp(char_u *path, char_u *name, int flags, + DoInRuntimepathCB callback, void *cookie) { int done = FAIL; if ((flags & DIP_NORTP) == 0) { - done = do_in_path(p_rtp, name, flags, callback, cookie); + done = do_in_path(path, name, flags, callback, cookie); } if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_START)) { @@ -2476,6 +2466,29 @@ int do_in_runtimepath(char_u *name, int flags, DoInRuntimepathCB callback, return done; } +/// Just like do_in_path_and_pp(), using 'runtimepath' for "path". +int do_in_runtimepath(char_u *name, int flags, DoInRuntimepathCB callback, + void *cookie) +{ + return do_in_path_and_pp(p_rtp, name, flags, callback, cookie); +} + +/// Source the file "name" from all directories in 'runtimepath'. +/// "name" can contain wildcards. +/// When "flags" has DIP_ALL: source all files, otherwise only the first one. +/// +/// return FAIL when no file could be sourced, OK otherwise. +int source_runtime(char_u *name, int flags) +{ + return source_in_path(p_rtp, name, flags); +} + +/// Just like source_runtime(), but use "path" instead of 'runtimepath'. +int source_in_path(char_u *path, char_u *name, int flags) +{ + return do_in_path_and_pp(path, name, flags, source_callback, NULL); +} + // Expand wildcards in "pat" and invoke do_source() for each match. static void source_all_matches(char_u *pat) { diff --git a/src/nvim/main.c b/src/nvim/main.c index 6e85fbc130..f601fd7ea3 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1291,15 +1291,23 @@ static void set_window_layout(mparm_T *paramp) static void load_plugins(void) { if (p_lpl) { + char_u *rtp_copy = NULL; + // First add all package directories to 'runtimepath', so that their // autoload directories can be found. Only if not done already with a // :packloadall command. + // Make a copy of 'runtimepath', so that source_runtime does not use the + // pack directories. if (!did_source_packages) { + rtp_copy = vim_strsave(p_rtp); add_pack_start_dirs(); } - source_runtime((char_u *)"plugin/**/*.vim", DIP_ALL | DIP_NOAFTER); // NOLINT + source_in_path(rtp_copy == NULL ? p_rtp : rtp_copy, + (char_u *)"plugin/**/*.vim", // NOLINT + DIP_ALL | DIP_NOAFTER); TIME_MSG("loading plugins"); + xfree(rtp_copy); // Only source "start" packages if not done already with a :packloadall // command. diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index 2dce7faded..11e26d03aa 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -24,28 +24,34 @@ func Test_after_comes_later() \ 'set guioptions+=M', \ 'let $HOME = "/does/not/exist"', \ 'set loadplugins', - \ 'set rtp=Xhere,Xafter', + \ 'set rtp=Xhere,Xafter,Xanother', \ 'set packpath=Xhere,Xafter', \ 'set nomore', + \ 'let g:sequence = ""', \ ] let after = [ \ 'redir! > Xtestout', \ 'scriptnames', \ 'redir END', + \ 'redir! > Xsequence', + \ 'echo g:sequence', + \ 'redir END', \ 'quit', \ ] call mkdir('Xhere/plugin', 'p') - call writefile(['let done = 1'], 'Xhere/plugin/here.vim') + call writefile(['let g:sequence .= "here "'], 'Xhere/plugin/here.vim') + call mkdir('Xanother/plugin', 'p') + call writefile(['let g:sequence .= "another "'], 'Xanother/plugin/another.vim') call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p') - call writefile(['let done = 1'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim') + call writefile(['let g:sequence .= "pack "'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim') call mkdir('Xafter/plugin', 'p') - call writefile(['let done = 1'], 'Xafter/plugin/later.vim') + call writefile(['let g:sequence .= "after "'], 'Xafter/plugin/later.vim') if RunVim(before, after, '') let lines = readfile('Xtestout') - let expected = ['Xbefore.vim', 'here.vim', 'foo.vim', 'later.vim', 'Xafter.vim'] + let expected = ['Xbefore.vim', 'here.vim', 'another.vim', 'foo.vim', 'later.vim', 'Xafter.vim'] let found = [] for line in lines for one in expected @@ -57,8 +63,12 @@ func Test_after_comes_later() call assert_equal(expected, found) endif + call assert_equal('here another pack after', substitute(join(readfile('Xsequence', 1), ''), '\s\+$', '', '')) + call delete('Xtestout') + call delete('Xsequence') call delete('Xhere', 'rf') + call delete('Xanother', 'rf') call delete('Xafter', 'rf') endfunc diff --git a/src/nvim/version.c b/src/nvim/version.c index 3313ffdfa9..598c3c3778 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -272,7 +272,7 @@ static const int included_patches[] = { // 683, // 682, // 681, - // 680, + 680, 679, 678, // 677, -- cgit