summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0814
blob: a9752d40937d4e05f9b19a4a693cc91acd2cf3cc (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
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0814
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.0814
Problem:    :mksession cannot handle a very long 'runtimepath'. (Timothy
            Madden)
Solution:   Expand each part separately, instead of the whole option at once.
            (Christian Brabandt, closes #3466)
Files:	    src/option.c, src/testdir/test_mksession.vim


*** ../vim-8.1.0813/src/option.c	2019-01-24 15:54:17.794846944 +0100
--- src/option.c	2019-01-24 20:23:14.225567873 +0100
***************
*** 3243,3249 ****
  static void showoptions(int all, int opt_flags);
  static int optval_default(struct vimoption *, char_u *varp);
  static void showoneopt(struct vimoption *, int opt_flags);
! static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
  static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
  static int put_setbool(FILE *fd, char *cmd, char *name, int value);
  static int  istermoption(struct vimoption *);
--- 3243,3249 ----
  static void showoptions(int all, int opt_flags);
  static int optval_default(struct vimoption *, char_u *varp);
  static void showoneopt(struct vimoption *, int opt_flags);
! static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
  static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
  static int put_setbool(FILE *fd, char *cmd, char *name, int value);
  static int  istermoption(struct vimoption *);
***************
*** 10297,10303 ****
  			do_endif = TRUE;
  		    }
  		    if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
! 					  (p->flags & P_EXPAND) != 0) == FAIL)
  			return FAIL;
  		    if (do_endif)
  		    {
--- 10297,10303 ----
  			do_endif = TRUE;
  		    }
  		    if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
! 							     p->flags) == FAIL)
  			return FAIL;
  		    if (do_endif)
  		    {
***************
*** 10319,10332 ****
      int
  makefoldset(FILE *fd)
  {
!     if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
  # ifdef FEAT_EVAL
! 	    || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
  								       == FAIL
  # endif
! 	    || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
  								       == FAIL
! 	    || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
  								       == FAIL
  	    || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
  	    || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
--- 10319,10332 ----
      int
  makefoldset(FILE *fd)
  {
!     if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
  # ifdef FEAT_EVAL
! 	    || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
  								       == FAIL
  # endif
! 	    || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
  								       == FAIL
! 	    || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
  								       == FAIL
  	    || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
  	    || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
***************
*** 10345,10354 ****
      char	*cmd,
      char	*name,
      char_u	**valuep,
!     int		expand)
  {
      char_u	*s;
!     char_u	*buf;
  
      if (fprintf(fd, "%s %s=", cmd, name) < 0)
  	return FAIL;
--- 10345,10356 ----
      char	*cmd,
      char	*name,
      char_u	**valuep,
!     long_u	flags)
  {
      char_u	*s;
!     char_u	*buf = NULL;
!     char_u	*part = NULL;
!     char_u	*p;
  
      if (fprintf(fd, "%s %s=", cmd, name) < 0)
  	return FAIL;
***************
*** 10364,10375 ****
  		if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
  		    return FAIL;
  	}
! 	else if (expand)
  	{
! 	    buf = alloc(MAXPATHL);
  	    if (buf == NULL)
! 		return FAIL;
! 	    home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
  	    if (put_escstr(fd, buf, 2) == FAIL)
  	    {
  		vim_free(buf);
--- 10366,10411 ----
  		if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
  		    return FAIL;
  	}
! 	// expand the option value, replace $HOME by ~
! 	else if ((flags & P_EXPAND) != 0)
  	{
! 	    int  size = (int)STRLEN(*valuep) + 1;
! 
! 	    // replace home directory in the whole option value into "buf"
! 	    buf = alloc(size);
  	    if (buf == NULL)
! 		goto fail;
! 	    home_replace(NULL, *valuep, buf, size, FALSE);
! 
! 	    // If the option value is longer than MAXPATHL, we need to append
! 	    // earch comma separated part of the option separately, so that it
! 	    // can be expanded when read back.
! 	    if (size >= MAXPATHL && (flags & P_COMMA) != 0
! 					   && vim_strchr(*valuep, ',') != NULL)
! 	    {
! 		part = alloc(size);
! 		if (part == NULL)
! 		    goto fail;
! 
! 		// write line break to clear the option, e.g. ':set rtp='
! 		if (put_eol(fd) == FAIL)
! 		    goto fail;
! 
! 		p = buf;
! 		while (*p != NUL)
! 		{
! 		    // for each comma separated option part, append value to
! 		    // the option, :set rtp+=value
! 		    if (fprintf(fd, "%s %s+=", cmd, name) < 0)
! 			goto fail;
! 		    (void)copy_option_part(&p, part, size,  ",");
! 		    if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
! 			goto fail;
! 		}
! 		vim_free(buf);
! 		vim_free(part);
! 		return OK;
! 	    }
  	    if (put_escstr(fd, buf, 2) == FAIL)
  	    {
  		vim_free(buf);
***************
*** 10383,10388 ****
--- 10419,10428 ----
      if (put_eol(fd) < 0)
  	return FAIL;
      return OK;
+ fail:
+     vim_free(buf);
+     vim_free(part);
+     return FAIL;
  }
  
      static int
*** ../vim-8.1.0813/src/testdir/test_mksession.vim	2019-01-24 15:57:25.321532574 +0100
--- src/testdir/test_mksession.vim	2019-01-24 19:56:04.503236163 +0100
***************
*** 3,9 ****
  set encoding=latin1
  scriptencoding latin1
  
! if !has('multi_byte') || !has('mksession')
    finish
  endif
  
--- 3,9 ----
  set encoding=latin1
  scriptencoding latin1
  
! if !has('mksession')
    finish
  endif
  
***************
*** 126,131 ****
--- 126,154 ----
    call delete('Xtest_mks_winheight.out')
  endfunc
  
+ func Test_mksession_rtp()
+   new
+   let _rtp=&rtp
+   " Make a real long (invalid) runtimepath value,
+   " that should exceed PATH_MAX (hopefully)
+   let newrtp=&rtp.',~'.repeat('/foobar', 1000)
+   let newrtp.=",".expand("$HOME")."/.vim"
+   let &rtp=newrtp
+ 
+   " determine expected value
+   let expected=split(&rtp, ',')
+   let expected = map(expected, '"set runtimepath+=".v:val')
+   let expected = ['set runtimepath='] + expected
+   let expected = map(expected, {v,w -> substitute(w, $HOME, "~", "g")})
+ 
+   mksession! Xtest_mks.out
+   let &rtp=_rtp
+   let li = filter(readfile('Xtest_mks.out'), 'v:val =~# "runtimepath"')
+   call assert_equal(expected, li)
+ 
+   call delete('Xtest_mks.out')
+ endfunc
+ 
  func Test_mksession_arglist()
    argdel *
    next file1 file2 file3 file4
*** ../vim-8.1.0813/src/version.c	2019-01-24 19:37:35.912390940 +0100
--- src/version.c	2019-01-24 20:30:18.569799280 +0100
***************
*** 789,790 ****
--- 789,792 ----
  {   /* Add new patch number below this line */
+ /**/
+     814,
  /**/

-- 
Yah, well, we had to carve our electrons out of driftwood we'd
find.  In the winter.  Uphill.  Both ways.

 /// 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    ///