diff options
| author | zeertzjq <zeertzjq@outlook.com> | 2026-05-21 09:35:27 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-21 09:35:27 +0800 |
| commit | a952575c3bb8e23cccaaeb91bc5cc0cb908cb02c (patch) | |
| tree | 5f5721d25dccc5b11ece3edb29f1ecca50831f9c /src/nvim/eval | |
| parent | 74cc0364f1706ae8df84f1750251b6a0dd3e43fd (diff) | |
| download | rneovim-a952575c3bb8e23cccaaeb91bc5cc0cb908cb02c.tar.gz rneovim-a952575c3bb8e23cccaaeb91bc5cc0cb908cb02c.tar.bz2 rneovim-a952575c3bb8e23cccaaeb91bc5cc0cb908cb02c.zip | |
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 <basilisk@internode.on.net>
Diffstat (limited to 'src/nvim/eval')
| -rw-r--r-- | src/nvim/eval/fs.c | 17 |
1 files changed, 11 insertions, 6 deletions
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); |