mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:9.0.0865: duplicate arguments are not always detected (#21036)
Problem: Duplicate arguments are not always detected.
Solution: Expand to full path before comparing arguments. (Nir Lichtman,
closes vim/vim#11505, closes vim/vim#9402)
b3052aa1b5
Co-authored-by: Nir Lichtman <nir@lichtman.org>
This commit is contained in:
parent
849394e4e2
commit
9d7dc50628
@ -693,8 +693,17 @@ void ex_next(exarg_T *eap)
|
|||||||
void ex_argdedupe(exarg_T *eap FUNC_ATTR_UNUSED)
|
void ex_argdedupe(exarg_T *eap FUNC_ATTR_UNUSED)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < ARGCOUNT; i++) {
|
for (int i = 0; i < ARGCOUNT; i++) {
|
||||||
|
// Expand each argument to a full path to catch different paths leading
|
||||||
|
// to the same file.
|
||||||
|
char *firstFullname = FullName_save(ARGLIST[i].ae_fname, false);
|
||||||
|
|
||||||
for (int j = i + 1; j < ARGCOUNT; j++) {
|
for (int j = i + 1; j < ARGCOUNT; j++) {
|
||||||
if (path_fnamecmp(ARGLIST[i].ae_fname, ARGLIST[j].ae_fname) == 0) {
|
char *secondFullname = FullName_save(ARGLIST[j].ae_fname, false);
|
||||||
|
bool areNamesDuplicate = path_fnamecmp(firstFullname, secondFullname) == 0;
|
||||||
|
xfree(secondFullname);
|
||||||
|
|
||||||
|
if (areNamesDuplicate) {
|
||||||
|
// remove one duplicate argument
|
||||||
xfree(ARGLIST[j].ae_fname);
|
xfree(ARGLIST[j].ae_fname);
|
||||||
memmove(ARGLIST + j, ARGLIST + j + 1,
|
memmove(ARGLIST + j, ARGLIST + j + 1,
|
||||||
(size_t)(ARGCOUNT - j - 1) * sizeof(aentry_T));
|
(size_t)(ARGCOUNT - j - 1) * sizeof(aentry_T));
|
||||||
@ -709,6 +718,8 @@ void ex_argdedupe(exarg_T *eap FUNC_ATTR_UNUSED)
|
|||||||
j--;
|
j--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xfree(firstFullname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,15 +418,19 @@ func Test_argdedupe()
|
|||||||
call Reset_arglist()
|
call Reset_arglist()
|
||||||
argdedupe
|
argdedupe
|
||||||
call assert_equal([], argv())
|
call assert_equal([], argv())
|
||||||
|
|
||||||
args a a a aa b b a b aa
|
args a a a aa b b a b aa
|
||||||
argdedupe
|
argdedupe
|
||||||
call assert_equal(['a', 'aa', 'b'], argv())
|
call assert_equal(['a', 'aa', 'b'], argv())
|
||||||
|
|
||||||
args a b c
|
args a b c
|
||||||
argdedupe
|
argdedupe
|
||||||
call assert_equal(['a', 'b', 'c'], argv())
|
call assert_equal(['a', 'b', 'c'], argv())
|
||||||
|
|
||||||
args a
|
args a
|
||||||
argdedupe
|
argdedupe
|
||||||
call assert_equal(['a'], argv())
|
call assert_equal(['a'], argv())
|
||||||
|
|
||||||
args a A b B
|
args a A b B
|
||||||
argdedupe
|
argdedupe
|
||||||
if has('fname_case')
|
if has('fname_case')
|
||||||
@ -434,11 +438,17 @@ func Test_argdedupe()
|
|||||||
else
|
else
|
||||||
call assert_equal(['a', 'b'], argv())
|
call assert_equal(['a', 'b'], argv())
|
||||||
endif
|
endif
|
||||||
|
|
||||||
args a b a c a b
|
args a b a c a b
|
||||||
last
|
last
|
||||||
argdedupe
|
argdedupe
|
||||||
next
|
next
|
||||||
call assert_equal('c', expand('%:t'))
|
call assert_equal('c', expand('%:t'))
|
||||||
|
|
||||||
|
args a ./a
|
||||||
|
argdedupe
|
||||||
|
call assert_equal(['a'], argv())
|
||||||
|
|
||||||
%argd
|
%argd
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user