From 50feb85b0c1e29583c6f6f928512e7b853a3ebf6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 12 Jul 2024 05:45:40 +0800 Subject: vim-patch:9.1.0565: Stop directory doesn't work properly in 'tags' Problem: Stop directory doesn't work properly in 'tags'. (Jesse Pavel) Solution: Also move the stop directory forward by one byte. (zeertzjq) This doesn't support relative stop directories yet, as they are not supported in other places like findfile() either. fixes: vim/vim#15200 related: vim/vim#15202 https://github.com/vim/vim/commit/68819afb2cdd0f44baa080db589e1d8f77099e5f --- src/nvim/tag.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/nvim/tag.c b/src/nvim/tag.c index 90269c776e..cc7ff070c2 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -2583,6 +2583,10 @@ int get_tagfname(tagname_T *tnp, int first, char *buf) // move the filename one char forward and truncate the // filepath with a NUL filename = path_tail(buf); + if (r_ptr != NULL) { + STRMOVE(r_ptr + 1, r_ptr); + r_ptr++; + } STRMOVE(filename + 1, filename); *filename++ = NUL; -- cgit From 091a130804282c9d40e639d68659d2ea2941259d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 12 Jul 2024 06:39:17 +0800 Subject: vim-patch:9.1.0566: Stop dir in findfile() doesn't work properly w/o trailing slash Problem: Stop directory in findfile() doesn't work properly without a trailing slash. Solution: Always use fnamencmp(), not fnamecmp(). related: vim/vim#15200 related: vim/vim#15202 https://github.com/vim/vim/commit/e6ab23bd4a41840860ae2904956c4d255a9dd528 --- src/nvim/file_search.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index b6a039af5e..9bc0095515 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -892,11 +892,12 @@ char *vim_findfile(void *search_ctx_arg) if (search_ctx->ffsc_start_dir && search_ctx->ffsc_stopdirs_v != NULL && !got_int) { ff_stack_T *sptr; + // path_end may point to the NUL or the previous path separator + ptrdiff_t plen = (path_end - search_ctx->ffsc_start_dir) + (*path_end != NUL); // is the last starting directory in the stop list? if (ff_path_in_stoplist(search_ctx->ffsc_start_dir, - (int)(path_end - search_ctx->ffsc_start_dir), - search_ctx->ffsc_stopdirs_v)) { + (size_t)plen, search_ctx->ffsc_stopdirs_v)) { break; } @@ -1231,7 +1232,7 @@ static void ff_clear(ff_search_ctx_T *search_ctx) /// check if the given path is in the stopdirs /// /// @return true if yes else false -static bool ff_path_in_stoplist(char *path, int path_len, char **stopdirs_v) +static bool ff_path_in_stoplist(char *path, size_t path_len, char **stopdirs_v) { // eat up trailing path separators, except the first while (path_len > 1 && vim_ispathsep(path[path_len - 1])) { @@ -1244,20 +1245,16 @@ static bool ff_path_in_stoplist(char *path, int path_len, char **stopdirs_v) } for (int i = 0; stopdirs_v[i] != NULL; i++) { - if ((int)strlen(stopdirs_v[i]) > path_len) { - // match for parent directory. So '/home' also matches - // '/home/rks'. Check for PATHSEP in stopdirs_v[i], else - // '/home/r' would also match '/home/rks' - if (path_fnamencmp(stopdirs_v[i], path, (size_t)path_len) == 0 - && vim_ispathsep(stopdirs_v[i][path_len])) { - return true; - } - } else { - if (path_fnamecmp(stopdirs_v[i], path) == 0) { - return true; - } + // match for parent directory. So '/home' also matches + // '/home/rks'. Check for PATHSEP in stopdirs_v[i], else + // '/home/r' would also match '/home/rks' + if (path_fnamencmp(stopdirs_v[i], path, path_len) == 0 + && (strlen(stopdirs_v[i]) <= path_len + || vim_ispathsep(stopdirs_v[i][path_len]))) { + return true; } } + return false; } -- cgit From 80818641f3504eb57a4fae5003f234f5f5f19ba1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 12 Jul 2024 06:45:39 +0800 Subject: vim-patch:9.1.0567: Cannot use relative paths as findfile() stop directories Problem: Cannot use relative paths as findfile() stop directories. Solution: Change a relative path to an absolute path. (zeertzjq) related: vim/vim#15200 closes: vim/vim#15202 https://github.com/vim/vim/commit/764526e2799fbed040fc867858ee2eb0677afe98 --- src/nvim/file_search.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 9bc0095515..5760fc864a 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -349,23 +349,24 @@ void *vim_findfile_init(char *path, char *filename, char *stopdirs, int level, i search_ctx->ffsc_stopdirs_v = xmalloc(sizeof(char *)); do { - char *helper; - void *ptr; - - helper = walker; - ptr = xrealloc(search_ctx->ffsc_stopdirs_v, - (dircount + 1) * sizeof(char *)); + char *helper = walker; + void *ptr = xrealloc(search_ctx->ffsc_stopdirs_v, + (dircount + 1) * sizeof(char *)); search_ctx->ffsc_stopdirs_v = ptr; walker = vim_strchr(walker, ';'); + assert(!walker || walker - helper >= 0); + size_t len = walker ? (size_t)(walker - helper) : strlen(helper); + // "" means ascent till top of directory tree. + if (*helper != NUL && !vim_isAbsName(helper) && len + 1 < MAXPATHL) { + // Make the stop dir an absolute path name. + xmemcpyz(ff_expand_buffer, helper, len); + search_ctx->ffsc_stopdirs_v[dircount - 1] = FullName_save(helper, len); + } else { + search_ctx->ffsc_stopdirs_v[dircount - 1] = xmemdupz(helper, len); + } if (walker) { - assert(walker - helper >= 0); - search_ctx->ffsc_stopdirs_v[dircount - 1] = xstrnsave(helper, (size_t)(walker - helper)); walker++; - } else { - // this might be "", which means ascent till top of directory tree. - search_ctx->ffsc_stopdirs_v[dircount - 1] = xstrdup(helper); } - dircount++; } while (walker != NULL); search_ctx->ffsc_stopdirs_v[dircount - 1] = NULL; -- cgit