From a952575c3bb8e23cccaaeb91bc5cc0cb908cb02c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 21 May 2026 09:35:27 +0800 Subject: vim-patch:9.2.0506: home_replace() function can be improved (#39925) Problem: home_replace() function can be improved Solution: Refactor home_replace() to return the length of the string (John Marriott). In addition: - in function set_b0_fname() move ulen into the block where it is used. - In function findswapname() rework logic around displaying "swap file already exists" dialogue so that literal message text is set once. closes: vim/vim#20249 https://github.com/vim/vim/commit/a0931a90eeee6692556f330b5ba1fb413f9ea85d Co-authored-by: John Marriott --- src/nvim/eval/fs.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/fs.c b/src/nvim/eval/fs.c index 8bf7414d8e..121897c84b 100644 --- a/src/nvim/eval/fs.c +++ b/src/nvim/eval/fs.c @@ -161,19 +161,24 @@ repeat: has_fullname = false; if (p != NULL) { + size_t dirnamelen = 0; + if (c == '.') { os_dirname(dirname, MAXPATHL); if (has_homerelative) { s = xstrdup(dirname); - home_replace(NULL, s, dirname, MAXPATHL, true); + dirnamelen = home_replace(NULL, s, dirname, MAXPATHL, true); xfree(s); } - size_t namelen = strlen(dirname); + + if (dirnamelen == 0) { + dirnamelen = strlen(dirname); + } // Do not call shorten_fname() here since it removes the prefix // even though the path does not have a prefix. - if (path_fnamencmp(p, dirname, namelen) == 0) { - p += namelen; + if (path_fnamencmp(p, dirname, dirnamelen) == 0) { + p += dirnamelen; if (vim_ispathsep(*p)) { while (*p && vim_ispathsep(*p)) { p++; @@ -188,10 +193,10 @@ repeat: } } } else { - home_replace(NULL, p, dirname, MAXPATHL, true); + dirnamelen = home_replace(NULL, p, dirname, MAXPATHL, true); // Only replace it when it starts with '~' if (*dirname == '~') { - s = xstrdup(dirname); + s = xmemdupz(dirname, dirnamelen); assert(s != NULL); // suppress clang "Argument with 'nonnull' attribute passed null" *fnamep = s; xfree(*bufp); -- cgit