Merge pull request #16734 from zeertzjq/chdir-refactor

refactor: remove some chdir-related unnecessary calls and checks
This commit is contained in:
James McCoy 2021-12-20 14:28:11 -05:00 committed by GitHub
commit 9241c684e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 13 deletions

View File

@ -1082,7 +1082,6 @@ static void f_chdir(typval_T *argvars, typval_T *rettv, FunPtr fptr)
// Return the current directory
cwd = xmalloc(MAXPATHL);
if (cwd != NULL) {
if (os_dirname(cwd, MAXPATHL) != FAIL) {
#ifdef BACKSLASH_IN_FILENAME
slash_adjust(cwd);
@ -1090,7 +1089,6 @@ static void f_chdir(typval_T *argvars, typval_T *rettv, FunPtr fptr)
rettv->vval.v_string = vim_strsave(cwd);
}
xfree(cwd);
}
if (curwin->w_localdir != NULL) {
scope = kCdScopeWindow;

View File

@ -7816,8 +7816,9 @@ bool changedir_func(char_u *new_dir, CdScope scope)
}
#endif
if (vim_chdir(new_dir) == 0) {
bool dir_differs = pdir == NULL || pathcmp((char *)pdir, (char *)new_dir, -1) != 0;
bool dir_differs = new_dir == NULL || pdir == NULL
|| pathcmp((char *)pdir, (char *)new_dir, -1) != 0;
if (new_dir != NULL && (!dir_differs || vim_chdir(new_dir) == 0)) {
post_chdir(scope, dir_differs);
retval = true;
} else {

View File

@ -1667,14 +1667,19 @@ int vim_chdirfile(char_u *fname, CdCause cause)
NameBuff[0] = NUL;
}
if (os_chdir(dir) == 0) {
if (cause != kCdCauseOther && pathcmp(dir, (char *)NameBuff, -1) != 0) {
do_autocmd_dirchanged(dir, kCdScopeWindow, cause);
if (pathcmp(dir, (char *)NameBuff, -1) == 0) {
// nothing to do
return OK;
}
} else {
if (os_chdir(dir) != 0) {
return FAIL;
}
if (cause != kCdCauseOther) {
do_autocmd_dirchanged(dir, kCdScopeWindow, cause);
}
return OK;
}