mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
Merge pull request #16734 from zeertzjq/chdir-refactor
refactor: remove some chdir-related unnecessary calls and checks
This commit is contained in:
commit
9241c684e1
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user