vim-patch:8.2.4754: using cached values after unsetting some environment variables (#19872)

Problem:    Still using cached values after unsetting some known environment
            variables.
Solution:   Take care of the side effects. (closes vim/vim#10194)
7714231bb5

Cherry-pick vim_setenv_ext() from patch 8.2.0200.
This commit is contained in:
zeertzjq
2022-08-21 11:37:13 +08:00
committed by GitHub
parent 506a3ec913
commit 6b9852cc41
5 changed files with 54 additions and 17 deletions

View File

@@ -1229,3 +1229,29 @@ bool os_shell_is_cmdexe(const char *sh)
}
return striequal("cmd.exe", path_tail(sh));
}
/// Removes environment variable "name" and take care of side effects.
void vim_unsetenv_ext(const char *var)
{
os_unsetenv(var);
// "homedir" is not cleared, keep using the old value until $HOME is set.
if (STRICMP(var, "VIM") == 0) {
didset_vim = false;
} else if (STRICMP(var, "VIMRUNTIME") == 0) {
didset_vimruntime = false;
}
}
/// Set environment variable "name" and take care of side effects.
void vim_setenv_ext(const char *name, const char *val)
{
os_setenv(name, val, 1);
if (STRICMP(name, "HOME") == 0) {
init_homedir();
} else if (didset_vim && STRICMP(name, "VIM") == 0) {
didset_vim = false;
} else if (didset_vimruntime && STRICMP(name, "VIMRUNTIME") == 0) {
didset_vimruntime = false;
}
}