Merge #8168 'refactor: rename some functions'

This commit is contained in:
Justin M. Keyes 2018-03-24 16:07:11 +01:00 committed by GitHub
commit 1b61167373
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 71 additions and 75 deletions

View File

@ -2683,7 +2683,7 @@ void buflist_altfpos(win_T *win)
}
/// Check that "ffname" is not the same file as current file.
/// Fname must have a full path (expanded by path_get_absolute_path()).
/// Fname must have a full path (expanded by path_to_absolute()).
///
/// @param ffname full path name to check
bool otherfile(char_u *ffname)
@ -2693,7 +2693,7 @@ bool otherfile(char_u *ffname)
}
/// Check that "ffname" is not the same file as the file loaded in "buf".
/// Fname must have a full path (expanded by path_get_absolute_path()).
/// Fname must have a full path (expanded by path_to_absolute()).
///
/// @param buf buffer to check
/// @param ffname full path name to check

View File

@ -13496,7 +13496,7 @@ static void f_resolve(typval_T *argvars, typval_T *rettv, FunPtr fptr)
q[-1] = NUL;
q = (char *)path_tail((char_u *)p);
}
if (q > p && !path_is_absolute_path((const char_u *)buf)) {
if (q > p && !path_is_absolute((const char_u *)buf)) {
// Symlink is relative to directory of argument. Replace the
// symlink with the resolved name in the same directory.
const size_t p_len = strlen(p);

View File

@ -8547,7 +8547,7 @@ eval_vars (
break;
case SPEC_AFILE: // file name for autocommand
if (autocmd_fname != NULL && !path_is_absolute_path(autocmd_fname)) {
if (autocmd_fname != NULL && !path_is_absolute(autocmd_fname)) {
// Still need to turn the fname into a full path. It was
// postponed to avoid a delay when <afile> is not used.
result = (char_u *)FullName_save((char *)autocmd_fname, false);
@ -8561,7 +8561,7 @@ eval_vars (
"E495: no autocommand file name to substitute for \"<afile>\"");
return NULL;
}
result = path_shorten_fname_if_possible(result);
result = path_try_shorten_fname(result);
break;
case SPEC_ABUF: /* buffer number for autocommand */

View File

@ -4923,13 +4923,14 @@ static void expand_shellcmd(char_u *filepat, int *num_file, char_u ***file,
flags |= EW_FILE | EW_EXEC | EW_SHELLCMD;
bool mustfree = false; // Track memory allocation for *path.
/* For an absolute name we don't use $PATH. */
if (path_is_absolute_path(pat))
// For an absolute name we don't use $PATH.
if (path_is_absolute(pat)) {
path = (char_u *)" ";
else if ((pat[0] == '.' && (vim_ispathsep(pat[1])
|| (pat[1] == '.' && vim_ispathsep(pat[2])))))
} else if (pat[0] == '.' && (vim_ispathsep(pat[1])
|| (pat[1] == '.'
&& vim_ispathsep(pat[2])))) {
path = (char_u *)".";
else {
} else {
path = (char_u *)vim_getenv("PATH");
if (path == NULL) {
path = (char_u *)"";

View File

@ -4318,7 +4318,7 @@ void shorten_fnames(int force)
&& !path_with_url((char *)buf->b_fname)
&& (force
|| buf->b_sfname == NULL
|| path_is_absolute_path(buf->b_sfname))) {
|| path_is_absolute(buf->b_sfname))) {
xfree(buf->b_sfname);
buf->b_sfname = NULL;
p = path_shorten_fname(buf->b_ffname, dirname);

View File

@ -3020,20 +3020,17 @@ int resolve_symlink(const char_u *fname, char_u *buf)
}
buf[ret] = NUL;
/*
* Check whether the symlink is relative or absolute.
* If it's relative, build a new path based on the directory
* portion of the filename (if any) and the path the symlink
* points to.
*/
if (path_is_absolute_path(buf))
// Check whether the symlink is relative or absolute.
// If it's relative, build a new path based on the directory
// portion of the filename (if any) and the path the symlink
// points to.
if (path_is_absolute(buf)) {
STRCPY(tmp, buf);
else {
char_u *tail;
tail = path_tail(tmp);
if (STRLEN(tail) + STRLEN(buf) >= MAXPATHL)
} else {
char_u *tail = path_tail(tmp);
if (STRLEN(tail) + STRLEN(buf) >= MAXPATHL) {
return FAIL;
}
STRCPY(tail, buf);
}
}

View File

@ -886,7 +886,7 @@ bool os_setenv_append_path(const char *fname)
// No prescribed maximum on unix.
# define MAX_ENVPATHLEN INT_MAX
#endif
if (!path_is_absolute_path((char_u *)fname)) {
if (!path_is_absolute((char_u *)fname)) {
internal_error("os_setenv_append_path()");
return false;
}

View File

@ -222,7 +222,7 @@ int os_exepath(char *buffer, size_t *size)
bool os_can_exe(const char_u *name, char_u **abspath, bool use_path)
FUNC_ATTR_NONNULL_ARG(1)
{
bool no_path = !use_path || path_is_absolute_path(name);
bool no_path = !use_path || path_is_absolute(name);
#ifndef WIN32
// If the filename is "qualified" (relative or absolute) do not check $PATH.
no_path |= (name[0] == '.'
@ -244,7 +244,7 @@ bool os_can_exe(const char_u *name, char_u **abspath, bool use_path)
#endif
if (ok) {
if (abspath != NULL) {
*abspath = save_absolute_path(name);
*abspath = save_abs_path(name);
}
return true;
}
@ -357,7 +357,7 @@ static bool is_executable_in_path(const char_u *name, char_u **abspath)
#endif
if (ok) {
if (abspath != NULL) { // Caller asked for a copy of the path.
*abspath = save_absolute_path((char_u *)buf);
*abspath = save_abs_path((char_u *)buf);
}
rv = true;

View File

@ -452,10 +452,10 @@ char *FullName_save(const char *fname, bool force)
/// Saves the absolute path.
/// @param name An absolute or relative path.
/// @return The absolute path of `name`.
char_u *save_absolute_path(const char_u *name)
char_u *save_abs_path(const char_u *name)
FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL
{
if (!path_is_absolute_path(name)) {
if (!path_is_absolute(name)) {
return (char_u *)FullName_save((char *)name, true);
}
return vim_strsave((char_u *) name);
@ -814,7 +814,7 @@ static void expand_path_option(char_u *curdir, garray_T *gap)
STRCPY(buf, curdir); // relative to current directory
} else if (path_with_url((char *)buf)) {
continue; // URL can't be used here
} else if (!path_is_absolute_path(buf)) {
} else if (!path_is_absolute(buf)) {
// Expand relative path to their full path equivalent
size_t len = STRLEN(curdir);
if (len + STRLEN(buf) + 3 > MAXPATHL) {
@ -949,19 +949,17 @@ static void uniquefy_paths(garray_T *gap, char_u *pattern)
}
}
if (path_is_absolute_path(path)) {
/*
* Last resort: shorten relative to curdir if possible.
* 'possible' means:
* 1. It is under the current directory.
* 2. The result is actually shorter than the original.
*
* Before curdir After
* /foo/bar/file.txt /foo/bar ./file.txt
* c:\foo\bar\file.txt c:\foo\bar .\file.txt
* /file.txt / /file.txt
* c:\file.txt c:\ .\file.txt
*/
if (path_is_absolute(path)) {
// Last resort: shorten relative to curdir if possible.
// 'possible' means:
// 1. It is under the current directory.
// 2. The result is actually shorter than the original.
//
// Before curdir After
// /foo/bar/file.txt /foo/bar ./file.txt
// c:\foo\bar\file.txt c:\foo\bar .\file.txt
// /file.txt / /file.txt
// c:\file.txt c:\ .\file.txt
short_name = path_shorten_fname(path, curdir);
if (short_name != NULL && short_name > path + 1
) {
@ -1221,7 +1219,7 @@ int gen_expand_wildcards(int num_pat, char_u **pat, int *num_file,
*/
if (path_has_exp_wildcard(p)) {
if ((flags & EW_PATH)
&& !path_is_absolute_path(p)
&& !path_is_absolute(p)
&& !(p[0] == '.'
&& (vim_ispathsep(p[1])
|| (p[1] == '.' && vim_ispathsep(p[2]))))
@ -1667,7 +1665,7 @@ int path_with_url(const char *fname)
*/
bool vim_isAbsName(char_u *name)
{
return path_with_url((char *)name) != 0 || path_is_absolute_path(name);
return path_with_url((char *)name) != 0 || path_is_absolute(name);
}
/// Save absolute file name to "buf[len]".
@ -1701,7 +1699,7 @@ int vim_FullName(const char *fname, char *buf, size_t len, bool force)
return OK;
}
int rv = path_get_absolute_path((char_u *)fname, (char_u *)buf, len, force);
int rv = path_to_absolute((char_u *)fname, (char_u *)buf, len, force);
if (rv == FAIL) {
xstrlcpy(buf, fname, len); // something failed; use the filename
}
@ -1910,7 +1908,7 @@ int pathcmp(const char *p, const char *q, int maxlen)
/// - Pointer into `full_path` if shortened.
/// - `full_path` unchanged if no shorter name is possible.
/// - NULL if `full_path` is NULL.
char_u *path_shorten_fname_if_possible(char_u *full_path)
char_u *path_try_shorten_fname(char_u *full_path)
{
char_u *dirname = xmalloc(MAXPATHL);
char_u *p = full_path;
@ -2191,8 +2189,8 @@ int append_path(char *path, const char *to_append, size_t max_len)
/// @param force also expand when "fname" is already absolute.
///
/// @return FAIL for failure, OK for success.
static int path_get_absolute_path(const char_u *fname, char_u *buf,
size_t len, int force)
static int path_to_absolute(const char_u *fname, char_u *buf, size_t len,
int force)
{
char_u *p;
*buf = NUL;
@ -2201,7 +2199,7 @@ static int path_get_absolute_path(const char_u *fname, char_u *buf,
char *end_of_path = (char *) fname;
// expand it if forced or not an absolute path
if (force || !path_is_absolute_path(fname)) {
if (force || !path_is_absolute(fname)) {
p = vim_strrchr(fname, '/');
#ifdef WIN32
if (p == NULL) {
@ -2234,10 +2232,10 @@ static int path_get_absolute_path(const char_u *fname, char_u *buf,
return append_path((char *)buf, end_of_path, len);
}
/// Check if the given file is absolute.
/// Check if file `fname` is a full (absolute) path.
///
/// @return `TRUE` if "fname" is absolute.
int path_is_absolute_path(const char_u *fname)
int path_is_absolute(const char_u *fname)
{
#ifdef WIN32
// A name like "d:/foo" and "//server/share" is absolute
@ -2262,7 +2260,7 @@ void path_guess_exepath(const char *argv0, char *buf, size_t bufsize)
{
char *path = getenv("PATH");
if (path == NULL || path_is_absolute_path((char_u *)argv0)) {
if (path == NULL || path_is_absolute((char_u *)argv0)) {
xstrlcpy(buf, argv0, bufsize);
} else if (argv0[0] == '.' || strchr(argv0, PATHSEP)) {
// Relative to CWD.

View File

@ -3649,8 +3649,8 @@ void ex_vimgrep(exarg_T *eap)
cur_qf_start = qi->qf_lists[qi->qf_curlist].qf_start;
seconds = (time_t)0;
for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi) {
fname = path_shorten_fname_if_possible(fnames[fi]);
for (fi = 0; fi < fcount && !got_int && tomatch > 0; fi++) {
fname = path_try_shorten_fname(fnames[fi]);
if (time(NULL) > seconds) {
/* Display the file name every second or so, show the user we are
* working on it. */

View File

@ -76,8 +76,8 @@ KHASH_SET_INIT_STR(strset)
(vim_rename((char_u *)a, (char_u *)b))
#define mb_strnicmp(a, b, c) \
(mb_strnicmp((char_u *)a, (char_u *)b, c))
#define path_shorten_fname_if_possible(b) \
((char *)path_shorten_fname_if_possible((char_u *)b))
#define path_try_shorten_fname(b) \
((char *)path_try_shorten_fname((char_u *)b))
#define buflist_new(ffname, sfname, ...) \
(buflist_new((char_u *)ffname, (char_u *)sfname, __VA_ARGS__))
#define os_isdir(f) (os_isdir((char_u *) f))
@ -1397,7 +1397,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags)
}
case kSDItemBufferList: {
for (size_t i = 0; i < cur_entry.data.buffer_list.size; i++) {
char *const sfname = path_shorten_fname_if_possible(
char *const sfname = path_try_shorten_fname(
cur_entry.data.buffer_list.buffers[i].fname);
buf_T *const buf = buflist_new(
cur_entry.data.buffer_list.buffers[i].fname, sfname, 0,

View File

@ -4239,11 +4239,11 @@ static void syn_cmd_include(exarg_T *eap, int syncing)
*/
eap->argt |= (XFILE | NOSPC);
separate_nextcmd(eap);
if (*eap->arg == '<' || *eap->arg == '$' || path_is_absolute_path(eap->arg)) {
/* For an absolute path, "$VIM/..." or "<sfile>.." we ":source" the
* file. Need to expand the file name first. In other cases
* ":runtime!" is used. */
source = TRUE;
if (*eap->arg == '<' || *eap->arg == '$' || path_is_absolute(eap->arg)) {
// For an absolute path, "$VIM/..." or "<sfile>.." we ":source" the
// file. Need to expand the file name first. In other cases
// ":runtime!" is used.
source = true;
if (expand_filename(eap, syn_cmdlinep, &errormsg) == FAIL) {
if (errormsg != NULL)
EMSG(errormsg);

View File

@ -199,7 +199,7 @@ describe('fs.c', function()
itp('returns the absolute path when given an executable inside $PATH', function()
local fullpath = exe('ls')
eq(1, fs.path_is_absolute_path(to_cstr(fullpath)))
eq(1, fs.path_is_absolute(to_cstr(fullpath)))
end)
itp('returns the absolute path when given an executable relative to the current dir', function()

View File

@ -261,7 +261,7 @@ describe('path.c', function()
end)
end)
describe('path_shorten_fname_if_possible', function()
describe('path_try_shorten_fname', function()
local cwd = lfs.currentdir()
before_each(function()
@ -273,22 +273,22 @@ describe('path_shorten_fname_if_possible', function()
lfs.rmdir('ut_directory')
end)
describe('path_shorten_fname_if_possible', function()
describe('path_try_shorten_fname', function()
itp('returns shortened path if possible', function()
lfs.chdir('ut_directory')
local full = to_cstr(lfs.currentdir() .. '/subdir/file.txt')
eq('subdir/file.txt', (ffi.string(cimp.path_shorten_fname_if_possible(full))))
eq('subdir/file.txt', (ffi.string(cimp.path_try_shorten_fname(full))))
end)
itp('returns `full_path` if a shorter version is not possible', function()
local old = lfs.currentdir()
lfs.chdir('ut_directory')
local full = old .. '/subdir/file.txt'
eq(full, (ffi.string(cimp.path_shorten_fname_if_possible(to_cstr(full)))))
eq(full, (ffi.string(cimp.path_try_shorten_fname(to_cstr(full)))))
end)
itp('returns NULL if `full_path` is NULL', function()
eq(NULL, (cimp.path_shorten_fname_if_possible(NULL)))
eq(NULL, (cimp.path_try_shorten_fname(NULL)))
end)
end)
end)
@ -585,22 +585,22 @@ describe('path.c', function()
end)
end)
describe('path_is_absolute_path', function()
local function path_is_absolute_path(filename)
describe('path_is_absolute', function()
local function path_is_absolute(filename)
filename = to_cstr(filename)
return cimp.path_is_absolute_path(filename)
return cimp.path_is_absolute(filename)
end
itp('returns true if filename starts with a slash', function()
eq(OK, path_is_absolute_path('/some/directory/'))
eq(OK, path_is_absolute('/some/directory/'))
end)
itp('returns true if filename starts with a tilde', function()
eq(OK, path_is_absolute_path('~/in/my/home~/directory'))
eq(OK, path_is_absolute('~/in/my/home~/directory'))
end)
itp('returns false if filename starts not with slash nor tilde', function()
eq(FAIL, path_is_absolute_path('not/in/my/home~/directory'))
eq(FAIL, path_is_absolute('not/in/my/home~/directory'))
end)
end)
end)