summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-06-30 22:40:42 +0200
committerBram Moolenaar <Bram@vim.org>2018-06-30 22:40:42 +0200
commit46577b5e5445c4aaa1e7ae1764373d11dae71663 (patch)
treef3f3a80c47eb1c3d294eb3eaf638fd2ad4636797
parent4ff4814b383bc85fbf5d8f62c8022f4379d7a490 (diff)
downloadvim-46577b5e5445c4aaa1e7ae1764373d11dae71663.zip
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)
-rw-r--r--src/tag.c21
-rw-r--r--src/testdir/test_taglist.vim25
-rw-r--r--src/version.c2
3 files changed, 44 insertions, 4 deletions
diff --git a/src/tag.c b/src/tag.c
index 92ed2a7c4..b23cb5aab 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -2595,7 +2595,6 @@ findtag_end:
}
static garray_T tag_fnames = GA_EMPTY;
-static void found_tagfile_cb(char_u *fname, void *cookie);
/*
* Callback function for finding all "tags" and "tags-??" files in
@@ -2605,8 +2604,15 @@ static void found_tagfile_cb(char_u *fname, void *cookie);
found_tagfile_cb(char_u *fname, void *cookie UNUSED)
{
if (ga_grow(&tag_fnames, 1) == OK)
- ((char_u **)(tag_fnames.ga_data))[tag_fnames.ga_len++] =
- vim_strsave(fname);
+ {
+ char_u *tag_fname = vim_strsave(fname);
+
+#ifdef BACKSLASH_IN_FILENAME
+ slash_adjust(tag_fname);
+#endif
+ simplify_filename(tag_fname);
+ ((char_u **)(tag_fnames.ga_data))[tag_fnames.ga_len++] = tag_fname;
+ }
}
#if defined(EXITFREE) || defined(PROTO)
@@ -2638,6 +2644,7 @@ get_tagfname(
{
char_u *fname = NULL;
char_u *r_ptr;
+ int i;
if (first)
vim_memset(tnp, 0, sizeof(tagname_T));
@@ -2679,6 +2686,14 @@ get_tagfname(
++tnp->tn_hf_idx;
STRCPY(buf, p_hf);
STRCPY(gettail(buf), "tags");
+#ifdef BACKSLASH_IN_FILENAME
+ slash_adjust(buf);
+#endif
+ simplify_filename(buf);
+
+ for (i = 0; i < tag_fnames.ga_len; ++i)
+ if (STRCMP(buf, ((char_u **)(tag_fnames.ga_data))[i]) == 0)
+ return FAIL; // avoid duplicate file names
}
else
vim_strncpy(buf, ((char_u **)(tag_fnames.ga_data))[
diff --git a/src/testdir/test_taglist.vim b/src/testdir/test_taglist.vim
index 3ad202591..0a9350adc 100644
--- a/src/testdir/test_taglist.vim
+++ b/src/testdir/test_taglist.vim
@@ -1,4 +1,4 @@
-" test 'taglist' function and :tags command
+" test taglist(), tagfiles() functions and :tags command
func Test_taglist()
call writefile([
@@ -61,3 +61,26 @@ func Test_tags_too_long()
call assert_fails('tag ' . repeat('x', 1020), 'E426')
tags
endfunc
+
+func Test_tagfiles()
+ call assert_equal([], tagfiles())
+
+ call writefile(["FFoo\tXfoo\t1"], 'Xtags1')
+ call writefile(["FBar\tXbar\t1"], 'Xtags2')
+ set tags=Xtags1,Xtags2
+ call assert_equal(['Xtags1', 'Xtags2'], tagfiles())
+
+ help
+ let tf = tagfiles()
+ call assert_equal(1, len(tf))
+ call assert_equal(fnamemodify(expand('$VIMRUNTIME/doc/tags'), ':p:gs?\\?/?'),
+ \ fnamemodify(tf[0], ':p:gs?\\?/?'))
+ helpclose
+ call assert_equal(['Xtags1', 'Xtags2'], tagfiles())
+ set tags&
+ call assert_equal([], tagfiles())
+
+ call delete('Xtags1')
+ call delete('Xtags2')
+ bd
+endfunc
diff --git a/src/version.c b/src/version.c
index 572b8f184..c724159d1 100644
--- a/src/version.c
+++ b/src/version.c
@@ -790,6 +790,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 133,
+/**/
132,
/**/
131,