Skip to content

Commit 07ecfa6

Browse files
committed
patch 8.0.0680: plugins in start packages are sourced twice
Problem: Plugins in start packages are sourced twice. (mseplowitz) Solution: Use the unmodified runtime path when loading plugins (test by Ingo Karkat, closes #1801)
1 parent 41cc038 commit 07ecfa6

5 files changed

Lines changed: 74 additions & 27 deletions

File tree

src/ex_cmds2.c

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3285,19 +3285,6 @@ source_callback(char_u *fname, void *cookie UNUSED)
32853285
(void)do_source(fname, FALSE, DOSO_NONE);
32863286
}
32873287

3288-
/*
3289-
* Source the file "name" from all directories in 'runtimepath'.
3290-
* "name" can contain wildcards.
3291-
* When "flags" has DIP_ALL: source all files, otherwise only the first one.
3292-
*
3293-
* return FAIL when no file could be sourced, OK otherwise.
3294-
*/
3295-
int
3296-
source_runtime(char_u *name, int flags)
3297-
{
3298-
return do_in_runtimepath(name, flags, source_callback, NULL);
3299-
}
3300-
33013288
/*
33023289
* Find the file "name" in all directories in "path" and invoke
33033290
* "callback(fname, cookie)".
@@ -3435,18 +3422,19 @@ do_in_path(
34353422
}
34363423

34373424
/*
3438-
* Find "name" in 'runtimepath'. When found, invoke the callback function for
3425+
* Find "name" in "path". When found, invoke the callback function for
34393426
* it: callback(fname, "cookie")
34403427
* When "flags" has DIP_ALL repeat for all matches, otherwise only the first
34413428
* one is used.
34423429
* Returns OK when at least one match found, FAIL otherwise.
34433430
*
3444-
* If "name" is NULL calls callback for each entry in runtimepath. Cookie is
3431+
* If "name" is NULL calls callback for each entry in "path". Cookie is
34453432
* passed by reference in this case, setting it to NULL indicates that callback
34463433
* has done its job.
34473434
*/
3448-
int
3449-
do_in_runtimepath(
3435+
static int
3436+
do_in_path_and_pp(
3437+
char_u *path,
34503438
char_u *name,
34513439
int flags,
34523440
void (*callback)(char_u *fname, void *ck),
@@ -3459,7 +3447,7 @@ do_in_runtimepath(
34593447
char *opt_dir = "pack/*/opt/*/%s";
34603448

34613449
if ((flags & DIP_NORTP) == 0)
3462-
done = do_in_path(p_rtp, name, flags, callback, cookie);
3450+
done = do_in_path(path, name, flags, callback, cookie);
34633451

34643452
if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_START))
34653453
{
@@ -3486,6 +3474,42 @@ do_in_runtimepath(
34863474
return done;
34873475
}
34883476

3477+
/*
3478+
* Just like do_in_path_and_pp(), using 'runtimepath' for "path".
3479+
*/
3480+
int
3481+
do_in_runtimepath(
3482+
char_u *name,
3483+
int flags,
3484+
void (*callback)(char_u *fname, void *ck),
3485+
void *cookie)
3486+
{
3487+
return do_in_path_and_pp(p_rtp, name, flags, callback, cookie);
3488+
}
3489+
3490+
/*
3491+
* Source the file "name" from all directories in 'runtimepath'.
3492+
* "name" can contain wildcards.
3493+
* When "flags" has DIP_ALL: source all files, otherwise only the first one.
3494+
*
3495+
* return FAIL when no file could be sourced, OK otherwise.
3496+
*/
3497+
int
3498+
source_runtime(char_u *name, int flags)
3499+
{
3500+
return source_in_path(p_rtp, name, flags);
3501+
}
3502+
3503+
/*
3504+
* Just like source_runtime(), but use "path" instead of 'runtimepath'.
3505+
*/
3506+
int
3507+
source_in_path(char_u *path, char_u *name, int flags)
3508+
{
3509+
return do_in_path_and_pp(path, name, flags, source_callback, NULL);
3510+
}
3511+
3512+
34893513
/*
34903514
* Expand wildcards in "pat" and invoke do_source() for each match.
34913515
*/

src/main.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,18 +449,28 @@ vim_main2(void)
449449
*/
450450
if (p_lpl)
451451
{
452+
char_u *rtp_copy = NULL;
453+
452454
/* First add all package directories to 'runtimepath', so that their
453455
* autoload directories can be found. Only if not done already with a
454-
* :packloadall command. */
456+
* :packloadall command.
457+
* Make a copy of 'runtimepath', so that source_runtime does not use
458+
* the pack directories. */
455459
if (!did_source_packages)
460+
{
461+
rtp_copy = vim_strsave(p_rtp);
456462
add_pack_start_dirs();
463+
}
457464

465+
source_in_path(rtp_copy == NULL ? p_rtp : rtp_copy,
458466
# ifdef VMS /* Somehow VMS doesn't handle the "**". */
459-
source_runtime((char_u *)"plugin/*.vim", DIP_ALL | DIP_NOAFTER);
467+
(char_u *)"plugin/*.vim",
460468
# else
461-
source_runtime((char_u *)"plugin/**/*.vim", DIP_ALL | DIP_NOAFTER);
469+
(char_u *)"plugin/**/*.vim",
462470
# endif
471+
DIP_ALL | DIP_NOAFTER);
463472
TIME_MSG("loading plugins");
473+
vim_free(rtp_copy);
464474

465475
/* Only source "start" packages if not done already with a :packloadall
466476
* command. */

src/proto/ex_cmds2.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ void ex_argdelete(exarg_T *eap);
6969
void ex_listdo(exarg_T *eap);
7070
void ex_compiler(exarg_T *eap);
7171
void ex_runtime(exarg_T *eap);
72-
int source_runtime(char_u *name, int flags);
7372
int do_in_path(char_u *path, char_u *name, int flags, void (*callback)(char_u *fname, void *ck), void *cookie);
7473
int do_in_runtimepath(char_u *name, int flags, void (*callback)(char_u *fname, void *ck), void *cookie);
74+
int source_runtime(char_u *name, int flags);
75+
int source_in_path(char_u *path, char_u *name, int flags);
7576
void add_pack_start_dirs(void);
7677
void load_start_packages(void);
7778
void ex_packloadall(exarg_T *eap);

src/testdir/test_startup.vim

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,34 @@ func Test_after_comes_later()
2323
\ 'set guioptions+=M',
2424
\ 'let $HOME = "/does/not/exist"',
2525
\ 'set loadplugins',
26-
\ 'set rtp=Xhere,Xafter',
26+
\ 'set rtp=Xhere,Xafter,Xanother',
2727
\ 'set packpath=Xhere,Xafter',
2828
\ 'set nomore',
29+
\ 'let g:sequence = ""',
2930
\ ]
3031
let after = [
3132
\ 'redir! > Xtestout',
3233
\ 'scriptnames',
3334
\ 'redir END',
35+
\ 'redir! > Xsequence',
36+
\ 'echo g:sequence',
37+
\ 'redir END',
3438
\ 'quit',
3539
\ ]
3640
call mkdir('Xhere/plugin', 'p')
37-
call writefile(['let done = 1'], 'Xhere/plugin/here.vim')
41+
call writefile(['let g:sequence .= "here "'], 'Xhere/plugin/here.vim')
42+
call mkdir('Xanother/plugin', 'p')
43+
call writefile(['let g:sequence .= "another "'], 'Xanother/plugin/another.vim')
3844
call mkdir('Xhere/pack/foo/start/foobar/plugin', 'p')
39-
call writefile(['let done = 1'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim')
45+
call writefile(['let g:sequence .= "pack "'], 'Xhere/pack/foo/start/foobar/plugin/foo.vim')
4046

4147
call mkdir('Xafter/plugin', 'p')
42-
call writefile(['let done = 1'], 'Xafter/plugin/later.vim')
48+
call writefile(['let g:sequence .= "after "'], 'Xafter/plugin/later.vim')
4349

4450
if RunVim(before, after, '')
4551

4652
let lines = readfile('Xtestout')
47-
let expected = ['Xbefore.vim', 'here.vim', 'foo.vim', 'later.vim', 'Xafter.vim']
53+
let expected = ['Xbefore.vim', 'here.vim', 'another.vim', 'foo.vim', 'later.vim', 'Xafter.vim']
4854
let found = []
4955
for line in lines
5056
for one in expected
@@ -56,8 +62,12 @@ func Test_after_comes_later()
5662
call assert_equal(expected, found)
5763
endif
5864

65+
call assert_equal('here another pack after', substitute(join(readfile('Xsequence', 1), ''), '\s\+$', '', ''))
66+
5967
call delete('Xtestout')
68+
call delete('Xsequence')
6069
call delete('Xhere', 'rf')
70+
call delete('Xanother', 'rf')
6171
call delete('Xafter', 'rf')
6272
endfunc
6373

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
680,
767769
/**/
768770
679,
769771
/**/

0 commit comments

Comments
 (0)