vim-patch:8.0.1554: custom plugins loaded with --clean

Problem:    Custom plugins loaded with --clean.
Solution:   Do not include the home directory in 'runtimepath'.
0726870326
This commit is contained in:
Jan Edmund Lazo 2020-06-07 13:13:52 -04:00
parent 70d4b31b83
commit a5bde56b37
No known key found for this signature in database
GPG Key ID: 64915E6E9F735B15
6 changed files with 71 additions and 45 deletions

View File

@ -90,6 +90,7 @@ argument.
--clean Equivalent to "-u NONE -i NONE":
- Skips initializations from files and environment variables.
- No 'shada' file is read or written.
- Excludes user directories from 'runtimepath'
*--noplugin*
--noplugin Skip loading plugins. Resets the 'loadplugins' option.

View File

@ -84,44 +84,11 @@
#endif
#include "nvim/api/vim.h"
// Maximum number of commands from + or -c arguments.
#define MAX_ARG_CMDS 10
// values for "window_layout"
#define WIN_HOR 1 // "-o" horizontally split windows
#define WIN_VER 2 // "-O" vertically split windows
#define WIN_TABS 3 // "-p" windows on tab pages
// Struct for various parameters passed between main() and other functions.
typedef struct {
int argc;
char **argv;
char *use_vimrc; // vimrc from -u argument
int n_commands; // no. of commands from + or -c
char *commands[MAX_ARG_CMDS]; // commands from + or -c arg
char_u cmds_tofree[MAX_ARG_CMDS]; // commands that need free()
int n_pre_commands; // no. of commands from --cmd
char *pre_commands[MAX_ARG_CMDS]; // commands from --cmd argument
int edit_type; // type of editing to do
char_u *tagname; // tag from -t argument
char_u *use_ef; // 'errorfile' from -q argument
bool input_isatty; // stdin is a terminal
bool output_isatty; // stdout is a terminal
bool err_isatty; // stderr is a terminal
int no_swap_file; // "-n" argument used
int use_debug_break_level;
int window_count; // number of windows to use
int window_layout; // 0, WIN_HOR, WIN_VER or WIN_TABS
int diff_mode; // start with 'diff' set
char *listen_addr; // --listen {address}
} mparm_T;
// Values for edit_type.
#define EDIT_NONE 0 // no edit type yet
#define EDIT_FILE 1 // file name argument[s] given, use argument list
@ -188,7 +155,7 @@ bool event_teardown(void)
/// Performs early initialization.
///
/// Needed for unit tests. Must be called after `time_init()`.
void early_init(void)
void early_init(mparm_T *paramp)
{
env_init();
fs_init();
@ -222,7 +189,7 @@ void early_init(void)
// msg_outtrans_len_attr().
// First find out the home directory, needed to expand "~" in options.
init_homedir(); // find real value of $HOME
set_init_1();
set_init_1(paramp != NULL ? paramp->clean : false);
log_init();
TIME_MSG("inits 1");
@ -265,9 +232,17 @@ int main(int argc, char **argv)
init_startuptime(&params);
// Need to find "--clean" before actually parsing arguments.
for (int i = 1; i < params.argc; i++) {
if (STRICMP(params.argv[i], "--clean") == 0) {
params.clean = true;
break;
}
}
event_init();
early_init();
early_init(&params);
set_argv_var(argv, argc); // set v:argv
@ -862,6 +837,7 @@ static void command_line_scan(mparm_T *parmp)
argv_idx += 11;
} else if (STRNICMP(argv[0] + argv_idx, "clean", 5) == 0) {
parmp->use_vimrc = "NONE";
parmp->clean = true;
set_option_value("shadafile", 0L, "NONE", 0);
} else {
if (argv[0][argv_idx])
@ -1277,9 +1253,8 @@ static void init_params(mparm_T *paramp, int argc, char **argv)
/// Initialize global startuptime file if "--startuptime" passed as an argument.
static void init_startuptime(mparm_T *paramp)
{
for (int i = 1; i < paramp->argc; i++) {
if (STRICMP(paramp->argv[i], "--startuptime") == 0
&& i + 1 < paramp->argc) {
for (int i = 1; i < paramp->argc - 1; i++) {
if (STRICMP(paramp->argv[i], "--startuptime") == 0) {
time_fd = os_fopen(paramp->argv[i + 1], "a");
time_start("--- NVIM STARTING ---");
break;

View File

@ -4,8 +4,42 @@
#include "nvim/normal.h"
#include "nvim/event/loop.h"
// Maximum number of commands from + or -c arguments.
#define MAX_ARG_CMDS 10
extern Loop main_loop;
// Struct for various parameters passed between main() and other functions.
typedef struct {
int argc;
char **argv;
char *use_vimrc; // vimrc from -u argument
bool clean; // --clean argument
int n_commands; // no. of commands from + or -c
char *commands[MAX_ARG_CMDS]; // commands from + or -c arg
char_u cmds_tofree[MAX_ARG_CMDS]; // commands that need free()
int n_pre_commands; // no. of commands from --cmd
char *pre_commands[MAX_ARG_CMDS]; // commands from --cmd argument
int edit_type; // type of editing to do
char_u *tagname; // tag from -t argument
char_u *use_ef; // 'errorfile' from -q argument
bool input_isatty; // stdin is a terminal
bool output_isatty; // stdout is a terminal
bool err_isatty; // stderr is a terminal
int no_swap_file; // "-n" argument used
int use_debug_break_level;
int window_count; // number of windows to use
int window_layout; // 0, WIN_HOR, WIN_VER or WIN_TABS
int diff_mode; // start with 'diff' set
char *listen_addr; // --listen {address}
} mparm_T;
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "main.h.generated.h"
#endif

View File

@ -524,11 +524,17 @@ char *get_lib_dir(void)
///
/// Windows: Uses "…/nvim-data" for kXDGDataHome to avoid storing
/// configuration and data files in the same path. #4403
static void set_runtimepath_default(void)
///
/// If "clean_arg" is true, Nvim was started with --clean.
static void set_runtimepath_default(bool clean_arg)
{
size_t rtp_size = 0;
char *const data_home = stdpaths_get_xdg_var(kXDGDataHome);
char *const config_home = stdpaths_get_xdg_var(kXDGConfigHome);
char *const data_home = clean_arg
? NULL
: stdpaths_get_xdg_var(kXDGDataHome);
char *const config_home = clean_arg
? NULL
: stdpaths_get_xdg_var(kXDGConfigHome);
char *const vimruntime = vim_getenv("VIMRUNTIME");
char *const libdir = get_lib_dir();
char *const data_dirs = stdpaths_get_xdg_var(kXDGDataDirs);
@ -622,7 +628,8 @@ static void set_runtimepath_default(void)
/// Initialize the options, first part.
///
/// Called only once from main(), just after creating the first buffer.
void set_init_1(void)
/// If "clean_arg" is true, Nvim was started with --clean.
void set_init_1(bool clean_arg)
{
int opt_idx;
@ -765,7 +772,7 @@ void set_init_1(void)
true);
// Set default for &runtimepath. All necessary expansions are performed in
// this function.
set_runtimepath_default();
set_runtimepath_default(clean_arg);
/*
* Set all the options (except the terminal options) to their default

View File

@ -3,6 +3,7 @@ local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
local command = helpers.command
local ok = helpers.ok
local eq = helpers.eq
local matches = helpers.matches
local eval = helpers.eval
@ -17,6 +18,7 @@ local rmdir = helpers.rmdir
local sleep = helpers.sleep
local iswin = helpers.iswin
local write_file = helpers.write_file
local meths = helpers.meths
describe('startup', function()
before_each(function()
@ -357,3 +359,10 @@ describe('sysinit', function()
eval('printf("loaded %d xdg %d vim %d", g:loaded, get(g:, "xdg", 0), get(g:, "vim", 0))'))
end)
end)
describe('clean', function()
clear()
ok(string.match(meths.get_option('runtimepath'), funcs.stdpath('config')) ~= nil)
clear('--clean')
ok(string.match(meths.get_option('runtimepath'), funcs.stdpath('config')) == nil)
end)

View File

@ -96,8 +96,8 @@ local init = only_separate(function()
c.func(unpack(c.args))
end
libnvim.time_init()
libnvim.early_init()
libnvim.event_init()
libnvim.early_init(nil)
if child_calls_mod then
for _, c in ipairs(child_calls_mod) do
c.func(unpack(c.args))