Skip to content

Commit 46577b5

Browse files
committed
patch 8.1.0133: tagfiles() can have duplicate entries
Problem: tagfiles() can have duplicate entries. Solution: Simplify the filename to make checking for duplicates work better. Add a test. (Dominique Pelle, closes #2979)
1 parent 4ff4814 commit 46577b5

3 files changed

Lines changed: 44 additions & 4 deletions

File tree

src/tag.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,7 +2595,6 @@ find_tags(
25952595
}
25962596

25972597
static garray_T tag_fnames = GA_EMPTY;
2598-
static void found_tagfile_cb(char_u *fname, void *cookie);
25992598

26002599
/*
26012600
* Callback function for finding all "tags" and "tags-??" files in
@@ -2605,8 +2604,15 @@ static void found_tagfile_cb(char_u *fname, void *cookie);
26052604
found_tagfile_cb(char_u *fname, void *cookie UNUSED)
26062605
{
26072606
if (ga_grow(&tag_fnames, 1) == OK)
2608-
((char_u **)(tag_fnames.ga_data))[tag_fnames.ga_len++] =
2609-
vim_strsave(fname);
2607+
{
2608+
char_u *tag_fname = vim_strsave(fname);
2609+
2610+
#ifdef BACKSLASH_IN_FILENAME
2611+
slash_adjust(tag_fname);
2612+
#endif
2613+
simplify_filename(tag_fname);
2614+
((char_u **)(tag_fnames.ga_data))[tag_fnames.ga_len++] = tag_fname;
2615+
}
26102616
}
26112617

26122618
#if defined(EXITFREE) || defined(PROTO)
@@ -2638,6 +2644,7 @@ get_tagfname(
26382644
{
26392645
char_u *fname = NULL;
26402646
char_u *r_ptr;
2647+
int i;
26412648

26422649
if (first)
26432650
vim_memset(tnp, 0, sizeof(tagname_T));
@@ -2679,6 +2686,14 @@ get_tagfname(
26792686
++tnp->tn_hf_idx;
26802687
STRCPY(buf, p_hf);
26812688
STRCPY(gettail(buf), "tags");
2689+
#ifdef BACKSLASH_IN_FILENAME
2690+
slash_adjust(buf);
2691+
#endif
2692+
simplify_filename(buf);
2693+
2694+
for (i = 0; i < tag_fnames.ga_len; ++i)
2695+
if (STRCMP(buf, ((char_u **)(tag_fnames.ga_data))[i]) == 0)
2696+
return FAIL; // avoid duplicate file names
26822697
}
26832698
else
26842699
vim_strncpy(buf, ((char_u **)(tag_fnames.ga_data))[

src/testdir/test_taglist.vim

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
" test 'taglist' function and :tags command
1+
" test taglist(), tagfiles() functions and :tags command
22

33
func Test_taglist()
44
call writefile([
@@ -61,3 +61,26 @@ func Test_tags_too_long()
6161
call assert_fails('tag ' . repeat('x', 1020), 'E426')
6262
tags
6363
endfunc
64+
65+
func Test_tagfiles()
66+
call assert_equal([], tagfiles())
67+
68+
call writefile(["FFoo\tXfoo\t1"], 'Xtags1')
69+
call writefile(["FBar\tXbar\t1"], 'Xtags2')
70+
set tags=Xtags1,Xtags2
71+
call assert_equal(['Xtags1', 'Xtags2'], tagfiles())
72+
73+
help
74+
let tf = tagfiles()
75+
call assert_equal(1, len(tf))
76+
call assert_equal(fnamemodify(expand('$VIMRUNTIME/doc/tags'), ':p:gs?\\?/?'),
77+
\ fnamemodify(tf[0], ':p:gs?\\?/?'))
78+
helpclose
79+
call assert_equal(['Xtags1', 'Xtags2'], tagfiles())
80+
set tags&
81+
call assert_equal([], tagfiles())
82+
83+
call delete('Xtags1')
84+
call delete('Xtags2')
85+
bd
86+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,8 @@ static char *(features[]) =
789789

790790
static int included_patches[] =
791791
{ /* Add new patch number below this line */
792+
/**/
793+
133,
792794
/**/
793795
132,
794796
/**/

0 commit comments

Comments
 (0)