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,15 +1082,13 @@ static void f_chdir(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
|
|
||||||
// Return the current directory
|
// Return the current directory
|
||||||
cwd = xmalloc(MAXPATHL);
|
cwd = xmalloc(MAXPATHL);
|
||||||
if (cwd != NULL) {
|
if (os_dirname(cwd, MAXPATHL) != FAIL) {
|
||||||
if (os_dirname(cwd, MAXPATHL) != FAIL) {
|
|
||||||
#ifdef BACKSLASH_IN_FILENAME
|
#ifdef BACKSLASH_IN_FILENAME
|
||||||
slash_adjust(cwd);
|
slash_adjust(cwd);
|
||||||
#endif
|
#endif
|
||||||
rettv->vval.v_string = vim_strsave(cwd);
|
rettv->vval.v_string = vim_strsave(cwd);
|
||||||
}
|
|
||||||
xfree(cwd);
|
|
||||||
}
|
}
|
||||||
|
xfree(cwd);
|
||||||
|
|
||||||
if (curwin->w_localdir != NULL) {
|
if (curwin->w_localdir != NULL) {
|
||||||
scope = kCdScopeWindow;
|
scope = kCdScopeWindow;
|
||||||
|
@ -7816,8 +7816,9 @@ bool changedir_func(char_u *new_dir, CdScope scope)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (vim_chdir(new_dir) == 0) {
|
bool dir_differs = new_dir == NULL || pdir == NULL
|
||||||
bool dir_differs = pdir == NULL || pathcmp((char *)pdir, (char *)new_dir, -1) != 0;
|
|| pathcmp((char *)pdir, (char *)new_dir, -1) != 0;
|
||||||
|
if (new_dir != NULL && (!dir_differs || vim_chdir(new_dir) == 0)) {
|
||||||
post_chdir(scope, dir_differs);
|
post_chdir(scope, dir_differs);
|
||||||
retval = true;
|
retval = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1667,14 +1667,19 @@ int vim_chdirfile(char_u *fname, CdCause cause)
|
|||||||
NameBuff[0] = NUL;
|
NameBuff[0] = NUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (os_chdir(dir) == 0) {
|
if (pathcmp(dir, (char *)NameBuff, -1) == 0) {
|
||||||
if (cause != kCdCauseOther && pathcmp(dir, (char *)NameBuff, -1) != 0) {
|
// nothing to do
|
||||||
do_autocmd_dirchanged(dir, kCdScopeWindow, cause);
|
return OK;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
|
if (os_chdir(dir) != 0) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cause != kCdCauseOther) {
|
||||||
|
do_autocmd_dirchanged(dir, kCdScopeWindow, cause);
|
||||||
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user