Patch 8.1.0133
Problem:    tagfiles() can have duplicate entries.
Solution:   Simplify the filename to make checking for duplicates work better.
            Add a test. (Dominique Pelle, closes #2979)
Files:      src/tag.c, src/testdir/test_taglist.vim


*** ../vim-8.1.0132/src/tag.c   2018-04-27 22:44:39.000000000 +0200
--- src/tag.c   2018-06-30 22:40:27.157629813 +0200
***************
*** 2595,2601 ****
  }
  
  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
--- 2595,2600 ----
***************
*** 2605,2612 ****
  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);
  }
  
  #if defined(EXITFREE) || defined(PROTO)
--- 2604,2618 ----
  found_tagfile_cb(char_u *fname, void *cookie UNUSED)
  {
      if (ga_grow(&tag_fnames, 1) == OK)
!     {
!       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,2643 ****
--- 2644,2650 ----
  {
      char_u            *fname = NULL;
      char_u            *r_ptr;
+     int                       i;
  
      if (first)
        vim_memset(tnp, 0, sizeof(tagname_T));
***************
*** 2679,2684 ****
--- 2686,2699 ----
            ++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))[
*** ../vim-8.1.0132/src/testdir/test_taglist.vim        2018-02-09 
18:25:21.000000000 +0100
--- src/testdir/test_taglist.vim        2018-06-30 22:33:05.044664951 +0200
***************
*** 1,4 ****
! " test 'taglist' function and :tags command
  
  func Test_taglist()
    call writefile([
--- 1,4 ----
! " test taglist(), tagfiles() functions and :tags command
  
  func Test_taglist()
    call writefile([
***************
*** 61,63 ****
--- 61,86 ----
    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
*** ../vim-8.1.0132/src/version.c       2018-06-30 21:50:16.856674912 +0200
--- src/version.c       2018-06-30 22:33:36.756434678 +0200
***************
*** 791,792 ****
--- 791,794 ----
  {   /* Add new patch number below this line */
+ /**/
+     133,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
158. You get a tuner card so you can watch TV while surfing.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui