mirror of
https://github.com/neovim/neovim.git
synced 2025-09-15 07:48:18 +00:00
refactor/rename: path_try_shorten_fname()
This commit is contained in:
@@ -8561,7 +8561,7 @@ eval_vars (
|
|||||||
"E495: no autocommand file name to substitute for \"<afile>\"");
|
"E495: no autocommand file name to substitute for \"<afile>\"");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
result = path_shorten_fname_if_possible(result);
|
result = path_try_shorten_fname(result);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SPEC_ABUF: /* buffer number for autocommand */
|
case SPEC_ABUF: /* buffer number for autocommand */
|
||||||
|
@@ -1908,7 +1908,7 @@ int pathcmp(const char *p, const char *q, int maxlen)
|
|||||||
/// - Pointer into `full_path` if shortened.
|
/// - Pointer into `full_path` if shortened.
|
||||||
/// - `full_path` unchanged if no shorter name is possible.
|
/// - `full_path` unchanged if no shorter name is possible.
|
||||||
/// - NULL if `full_path` is NULL.
|
/// - 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 *dirname = xmalloc(MAXPATHL);
|
||||||
char_u *p = full_path;
|
char_u *p = full_path;
|
||||||
|
@@ -3649,8 +3649,8 @@ void ex_vimgrep(exarg_T *eap)
|
|||||||
cur_qf_start = qi->qf_lists[qi->qf_curlist].qf_start;
|
cur_qf_start = qi->qf_lists[qi->qf_curlist].qf_start;
|
||||||
|
|
||||||
seconds = (time_t)0;
|
seconds = (time_t)0;
|
||||||
for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi) {
|
for (fi = 0; fi < fcount && !got_int && tomatch > 0; fi++) {
|
||||||
fname = path_shorten_fname_if_possible(fnames[fi]);
|
fname = path_try_shorten_fname(fnames[fi]);
|
||||||
if (time(NULL) > seconds) {
|
if (time(NULL) > seconds) {
|
||||||
/* Display the file name every second or so, show the user we are
|
/* Display the file name every second or so, show the user we are
|
||||||
* working on it. */
|
* working on it. */
|
||||||
|
@@ -76,8 +76,8 @@ KHASH_SET_INIT_STR(strset)
|
|||||||
(vim_rename((char_u *)a, (char_u *)b))
|
(vim_rename((char_u *)a, (char_u *)b))
|
||||||
#define mb_strnicmp(a, b, c) \
|
#define mb_strnicmp(a, b, c) \
|
||||||
(mb_strnicmp((char_u *)a, (char_u *)b, c))
|
(mb_strnicmp((char_u *)a, (char_u *)b, c))
|
||||||
#define path_shorten_fname_if_possible(b) \
|
#define path_try_shorten_fname(b) \
|
||||||
((char *)path_shorten_fname_if_possible((char_u *)b))
|
((char *)path_try_shorten_fname((char_u *)b))
|
||||||
#define buflist_new(ffname, sfname, ...) \
|
#define buflist_new(ffname, sfname, ...) \
|
||||||
(buflist_new((char_u *)ffname, (char_u *)sfname, __VA_ARGS__))
|
(buflist_new((char_u *)ffname, (char_u *)sfname, __VA_ARGS__))
|
||||||
#define os_isdir(f) (os_isdir((char_u *) f))
|
#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: {
|
case kSDItemBufferList: {
|
||||||
for (size_t i = 0; i < cur_entry.data.buffer_list.size; i++) {
|
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);
|
cur_entry.data.buffer_list.buffers[i].fname);
|
||||||
buf_T *const buf = buflist_new(
|
buf_T *const buf = buflist_new(
|
||||||
cur_entry.data.buffer_list.buffers[i].fname, sfname, 0,
|
cur_entry.data.buffer_list.buffers[i].fname, sfname, 0,
|
||||||
|
@@ -261,7 +261,7 @@ describe('path.c', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('path_shorten_fname_if_possible', function()
|
describe('path_try_shorten_fname', function()
|
||||||
local cwd = lfs.currentdir()
|
local cwd = lfs.currentdir()
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
@@ -273,22 +273,22 @@ describe('path_shorten_fname_if_possible', function()
|
|||||||
lfs.rmdir('ut_directory')
|
lfs.rmdir('ut_directory')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('path_shorten_fname_if_possible', function()
|
describe('path_try_shorten_fname', function()
|
||||||
itp('returns shortened path if possible', function()
|
itp('returns shortened path if possible', function()
|
||||||
lfs.chdir('ut_directory')
|
lfs.chdir('ut_directory')
|
||||||
local full = to_cstr(lfs.currentdir() .. '/subdir/file.txt')
|
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)
|
end)
|
||||||
|
|
||||||
itp('returns `full_path` if a shorter version is not possible', function()
|
itp('returns `full_path` if a shorter version is not possible', function()
|
||||||
local old = lfs.currentdir()
|
local old = lfs.currentdir()
|
||||||
lfs.chdir('ut_directory')
|
lfs.chdir('ut_directory')
|
||||||
local full = old .. '/subdir/file.txt'
|
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)
|
end)
|
||||||
|
|
||||||
itp('returns NULL if `full_path` is NULL', function()
|
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)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user