summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0353
blob: 842e839c80bed7f86a068a88d85da3e6547d4d4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0353
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 8.1.0353
Problem:    An "after" directory of a package is appended to 'rtp', which
            will be after the user's "after" directory. ()
Solution:   Insert the package "after" directory before any other "after"
            directory in 'rtp'. (closes #3409)
Files:	    src/ex_cmds2.c, src/testdir/test_packadd.vim


*** ../vim-8.1.0352/src/ex_cmds2.c	2018-08-31 23:06:18.735841246 +0200
--- src/ex_cmds2.c	2018-09-08 18:03:22.848808156 +0200
***************
*** 3691,3704 ****
  add_pack_dir_to_rtp(char_u *fname)
  {
      char_u  *p4, *p3, *p2, *p1, *p;
!     char_u  *insp;
      int	    c;
      char_u  *new_rtp;
      int	    keep;
      size_t  oldlen;
      size_t  addlen;
      char_u  *afterdir = NULL;
      size_t  afterlen = 0;
      char_u  *ffname = NULL;
      size_t  fname_len;
      char_u  *buf = NULL;
--- 3691,3707 ----
  add_pack_dir_to_rtp(char_u *fname)
  {
      char_u  *p4, *p3, *p2, *p1, *p;
!     char_u  *entry;
!     char_u  *insp = NULL;
      int	    c;
      char_u  *new_rtp;
      int	    keep;
      size_t  oldlen;
      size_t  addlen;
+     size_t  new_rtp_len;
      char_u  *afterdir = NULL;
      size_t  afterlen = 0;
+     char_u  *after_insp = NULL;
      char_u  *ffname = NULL;
      size_t  fname_len;
      char_u  *buf = NULL;
***************
*** 3725,3778 ****
      if (ffname == NULL)
  	return FAIL;
  
!     /* Find "ffname" in "p_rtp", ignoring '/' vs '\' differences. */
      fname_len = STRLEN(ffname);
-     insp = p_rtp;
      buf = alloc(MAXPATHL);
      if (buf == NULL)
  	goto theend;
!     while (*insp != NUL)
      {
! 	copy_option_part(&insp, buf, MAXPATHL, ",");
! 	add_pathsep(buf);
! 	rtp_ffname = fix_fname(buf);
! 	if (rtp_ffname == NULL)
! 	    goto theend;
! 	match = vim_fnamencmp(rtp_ffname, ffname, fname_len) == 0;
! 	vim_free(rtp_ffname);
! 	if (match)
  	    break;
      }
  
!     if (*insp == NUL)
! 	/* not found, append at the end */
  	insp = p_rtp + STRLEN(p_rtp);
-     else
- 	/* append after the matching directory. */
- 	--insp;
  
!     /* check if rtp/pack/name/start/name/after exists */
      afterdir = concat_fnames(fname, (char_u *)"after", TRUE);
      if (afterdir != NULL && mch_isdir(afterdir))
! 	afterlen = STRLEN(afterdir) + 1; /* add one for comma */
  
      oldlen = STRLEN(p_rtp);
!     addlen = STRLEN(fname) + 1; /* add one for comma */
!     new_rtp = alloc((int)(oldlen + addlen + afterlen + 1));
!     /* add one for NUL */
      if (new_rtp == NULL)
  	goto theend;
      keep = (int)(insp - p_rtp);
      mch_memmove(new_rtp, p_rtp, keep);
!     new_rtp[keep] = ',';
!     mch_memmove(new_rtp + keep + 1, fname, addlen);
      if (p_rtp[keep] != NUL)
! 	mch_memmove(new_rtp + keep + addlen, p_rtp + keep, oldlen - keep + 1);
!     if (afterlen > 0)
      {
  	STRCAT(new_rtp, ",");
  	STRCAT(new_rtp, afterdir);
      }
      set_option_value((char_u *)"rtp", 0L, new_rtp, 0);
      vim_free(new_rtp);
      retval = OK;
--- 3728,3826 ----
      if (ffname == NULL)
  	return FAIL;
  
!     // Find "ffname" in "p_rtp", ignoring '/' vs '\' differences.
!     // Also stop at the first "after" directory.
      fname_len = STRLEN(ffname);
      buf = alloc(MAXPATHL);
      if (buf == NULL)
  	goto theend;
!     for (entry = p_rtp; *entry != NUL; )
      {
! 	char_u *cur_entry = entry;
! 
! 	copy_option_part(&entry, buf, MAXPATHL, ",");
! 	if (insp == NULL)
! 	{
! 	    add_pathsep(buf);
! 	    rtp_ffname = fix_fname(buf);
! 	    if (rtp_ffname == NULL)
! 		goto theend;
! 	    match = vim_fnamencmp(rtp_ffname, ffname, fname_len) == 0;
! 	    vim_free(rtp_ffname);
! 	    if (match)
! 		// Insert "ffname" after this entry (and comma).
! 		insp = entry;
! 	}
! 
! 	if ((p = (char_u *)strstr((char *)buf, "after")) != NULL
! 		&& p > buf
! 		&& vim_ispathsep(p[-1])
! 		&& (vim_ispathsep(p[5]) || p[5] == NUL || p[5] == ','))
! 	{
! 	    if (insp == NULL)
! 		// Did not find "ffname" before the first "after" directory,
! 		// insert it before this entry.
! 		insp = cur_entry;
! 	    after_insp = cur_entry;
  	    break;
+ 	}
      }
  
!     if (insp == NULL)
! 	// Both "fname" and "after" not found, append at the end.
  	insp = p_rtp + STRLEN(p_rtp);
  
!     // check if rtp/pack/name/start/name/after exists
      afterdir = concat_fnames(fname, (char_u *)"after", TRUE);
      if (afterdir != NULL && mch_isdir(afterdir))
! 	afterlen = STRLEN(afterdir) + 1; // add one for comma
  
      oldlen = STRLEN(p_rtp);
!     addlen = STRLEN(fname) + 1; // add one for comma
!     new_rtp = alloc((int)(oldlen + addlen + afterlen + 1)); // add one for NUL
      if (new_rtp == NULL)
  	goto theend;
+ 
+     // We now have 'rtp' parts: {keep}{keep_after}{rest}.
+     // Create new_rtp, first: {keep},{fname}
      keep = (int)(insp - p_rtp);
      mch_memmove(new_rtp, p_rtp, keep);
!     new_rtp_len = keep;
!     if (*insp == NUL)
! 	new_rtp[new_rtp_len++] = ',';  // add comma before
!     mch_memmove(new_rtp + new_rtp_len, fname, addlen - 1);
!     new_rtp_len += addlen - 1;
!     if (*insp != NUL)
! 	new_rtp[new_rtp_len++] = ',';  // add comma after
! 
!     if (afterlen > 0 && after_insp != NULL)
!     {
! 	int keep_after = (int)(after_insp - p_rtp);
! 
! 	// Add to new_rtp: {keep},{fname}{keep_after},{afterdir}
! 	mch_memmove(new_rtp + new_rtp_len, p_rtp + keep,
! 							keep_after - keep);
! 	new_rtp_len += keep_after - keep;
! 	mch_memmove(new_rtp + new_rtp_len, afterdir, afterlen - 1);
! 	new_rtp_len += afterlen - 1;
! 	new_rtp[new_rtp_len++] = ',';
! 	keep = keep_after;
!     }
! 
      if (p_rtp[keep] != NUL)
! 	// Append rest: {keep},{fname}{keep_after},{afterdir}{rest}
! 	mch_memmove(new_rtp + new_rtp_len, p_rtp + keep, oldlen - keep + 1);
!     else
! 	new_rtp[new_rtp_len] = NUL;
! 
!     if (afterlen > 0 && after_insp == NULL)
      {
+ 	// Append afterdir when "after" was not found:
+ 	// {keep},{fname}{rest},{afterdir}
  	STRCAT(new_rtp, ",");
  	STRCAT(new_rtp, afterdir);
      }
+ 
      set_option_value((char_u *)"rtp", 0L, new_rtp, 0);
      vim_free(new_rtp);
      retval = OK;
*** ../vim-8.1.0352/src/testdir/test_packadd.vim	2018-04-18 21:56:13.000000000 +0200
--- src/testdir/test_packadd.vim	2018-09-08 18:16:43.969062182 +0200
***************
*** 12,17 ****
--- 12,22 ----
  endfunc
  
  func Test_packadd()
+   if !exists('s:plugdir')
+     echomsg 'when running this test manually, call SetUp() first'
+     return
+   endif
+ 
    call mkdir(s:plugdir . '/plugin/also', 'p')
    call mkdir(s:plugdir . '/ftdetect', 'p')
    call mkdir(s:plugdir . '/after', 'p')
***************
*** 19,24 ****
--- 24,37 ----
    let rtp = &rtp
    filetype on
  
+   let rtp_entries = split(rtp, ',')
+   for entry in rtp_entries
+     if entry =~? '\<after\>' 
+       let first_after_entry = entry
+       break
+     endif
+   endfor
+ 
    exe 'split ' . s:plugdir . '/plugin/test.vim'
    call setline(1, 'let g:plugin_works = 42')
    wq
***************
*** 38,44 ****
    call assert_equal(17, g:ftdetect_works)
    call assert_true(len(&rtp) > len(rtp))
    call assert_match('/testdir/Xdir/pack/mine/opt/mytest\($\|,\)', &rtp)
!   call assert_match('/testdir/Xdir/pack/mine/opt/mytest/after$', &rtp)
  
    " NOTE: '/.../opt/myte' forwardly matches with '/.../opt/mytest'
    call mkdir(fnamemodify(s:plugdir, ':h') . '/myte', 'p')
--- 51,62 ----
    call assert_equal(17, g:ftdetect_works)
    call assert_true(len(&rtp) > len(rtp))
    call assert_match('/testdir/Xdir/pack/mine/opt/mytest\($\|,\)', &rtp)
! 
!   let new_after = match(&rtp, '/testdir/Xdir/pack/mine/opt/mytest/after,')
!   let old_after = match(&rtp, ',' . first_after_entry . '\>')
!   call assert_true(new_after > 0, 'rtp is ' . &rtp)
!   call assert_true(old_after > 0, 'rtp is ' . &rtp)
!   call assert_true(new_after < old_after, 'rtp is ' . &rtp)
  
    " NOTE: '/.../opt/myte' forwardly matches with '/.../opt/mytest'
    call mkdir(fnamemodify(s:plugdir, ':h') . '/myte', 'p')
*** ../vim-8.1.0352/src/version.c	2018-09-08 15:10:14.405097082 +0200
--- src/version.c	2018-09-08 17:01:12.259798047 +0200
***************
*** 796,797 ****
--- 796,799 ----
  {   /* Add new patch number below this line */
+ /**/
+     353,
  /**/

-- 
How To Keep A Healthy Level Of Insanity:
14. Put mosquito netting around your work area. Play a tape of jungle
    sounds all day.

 /// Bram Moolenaar -- Bram@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    ///