summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0251
blob: f5b927a09800fde686ca5eb18c81432cc4df5c55 (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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0251
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.0251
Problem:    Using a full path is supported for 'directory' but not for
            'backupdir'. (Mikolaj Machowski)
Solution:   Support 'backupdir' as well. (Christian Brabandt, closes #179)
Files:	    runtime/doc/options.txt, src/fileio.c, src/memline.c,
            src/proto/memline.pro, src/testdir/test_alot.vim,
            src/testdir/test_backup.vim, src/Make_all.mak


*** ../vim-8.1.0250/runtime/doc/options.txt	2018-06-23 19:22:45.598486362 +0200
--- runtime/doc/options.txt	2018-08-07 21:04:11.238964573 +0200
***************
*** 1052,1057 ****
--- 1054,1067 ----
  	  name, precede it with a backslash.
  	- To include a comma in a directory name precede it with a backslash.
  	- A directory name may end in an '/'.
+ 	- For Unix and Win32, if a directory ends in two path separators "//",
+ 	  the swap file name will be built from the complete path to the file
+ 	  with all path separators changed to percent '%' signs. This will
+ 	  ensure file name uniqueness in the backup directory.
+ 	  On Win32, it is also possible to end with "\\".  However, When a
+ 	  separating comma is following, you must use "//", since "\\" will
+ 	  include the comma in the file name. Therefore it is recommended to
+ 	  use '//', instead of '\\'.
  	- Environment variables are expanded |:set_env|.
  	- Careful with '\' characters, type one before a space, type two to
  	  get one in the option (see |option-backslash|), for example: >
***************
*** 2678,2689 ****
  	- A directory starting with "./" (or ".\" for MS-DOS et al.) means to
  	  put the swap file relative to where the edited file is.  The leading
  	  "." is replaced with the path name of the edited file.
! 	- For Unix and Win32, if a directory ends in two path separators "//"
! 	  or "\\", the swap file name will be built from the complete path to
! 	  the file with all path separators substituted to percent '%' signs.
! 	  This will ensure file name uniqueness in the preserve directory.
! 	  On Win32, when a separating comma is following, you must use "//",
! 	  since "\\" will include the comma in the file name.
  	- Spaces after the comma are ignored, other spaces are considered part
  	  of the directory name.  To have a space at the start of a directory
  	  name, precede it with a backslash.
--- 2688,2701 ----
  	- A directory starting with "./" (or ".\" for MS-DOS et al.) means to
  	  put the swap file relative to where the edited file is.  The leading
  	  "." is replaced with the path name of the edited file.
! 	- For Unix and Win32, if a directory ends in two path separators "//",
! 	  the swap file name will be built from the complete path to the file
! 	  with all path separators substituted to percent '%' signs. This will
! 	  ensure file name uniqueness in the preserve directory.
! 	  On Win32, it is also possible to end with "\\".  However, When a
! 	  separating comma is following, you must use "//", since "\\" will
! 	  include the comma in the file name. Therefore it is recommended to
! 	  use '//', instead of '\\'.
  	- Spaces after the comma are ignored, other spaces are considered part
  	  of the directory name.  To have a space at the start of a directory
  	  name, precede it with a backslash.
*** ../vim-8.1.0250/src/fileio.c	2018-08-01 17:53:04.689381294 +0200
--- src/fileio.c	2018-08-07 21:36:54.903803767 +0200
***************
*** 3850,3855 ****
--- 3850,3858 ----
  	    stat_T	st_new;
  	    char_u	*dirp;
  	    char_u	*rootname;
+ #if defined(UNIX) || defined(WIN3264)
+ 	    char_u      *p;
+ #endif
  #if defined(UNIX)
  	    int		did_set_shortname;
  	    mode_t	umask_save;
***************
*** 3887,3892 ****
--- 3890,3906 ----
  		 * Isolate one directory name, using an entry in 'bdir'.
  		 */
  		(void)copy_option_part(&dirp, copybuf, BUFSIZE, ",");
+ 
+ #if defined(UNIX) || defined(WIN3264)
+ 		p = copybuf + STRLEN(copybuf);
+ 		if (after_pathsep(copybuf, p) && p[-1] == p[-2])
+ 		    // Ends with '//', use full path
+ 		    if ((p = make_percent_swname(copybuf, fname)) != NULL)
+ 		    {
+ 			backup = modname(p, backup_ext, FALSE);
+ 			vim_free(p);
+ 		    }
+ #endif
  		rootname = get_file_in_dir(fname, copybuf);
  		if (rootname == NULL)
  		{
***************
*** 3904,3912 ****
  		for (;;)
  		{
  		    /*
! 		     * Make backup file name.
  		     */
! 		    backup = buf_modname((buf->b_p_sn || buf->b_shortname),
  						 rootname, backup_ext, FALSE);
  		    if (backup == NULL)
  		    {
--- 3918,3927 ----
  		for (;;)
  		{
  		    /*
! 		     * Make the backup file name.
  		     */
! 		    if (backup == NULL)
! 			backup = buf_modname((buf->b_p_sn || buf->b_shortname),
  						 rootname, backup_ext, FALSE);
  		    if (backup == NULL)
  		    {
***************
*** 4108,4121 ****
  		 * Isolate one directory name and make the backup file name.
  		 */
  		(void)copy_option_part(&dirp, IObuff, IOSIZE, ",");
! 		rootname = get_file_in_dir(fname, IObuff);
! 		if (rootname == NULL)
! 		    backup = NULL;
! 		else
  		{
! 		    backup = buf_modname((buf->b_p_sn || buf->b_shortname),
! 						 rootname, backup_ext, FALSE);
! 		    vim_free(rootname);
  		}
  
  		if (backup != NULL)
--- 4123,4151 ----
  		 * Isolate one directory name and make the backup file name.
  		 */
  		(void)copy_option_part(&dirp, IObuff, IOSIZE, ",");
! 
! #if defined(UNIX) || defined(WIN3264)
! 		p = IObuff + STRLEN(IObuff);
! 		if (after_pathsep(IObuff, p) && p[-1] == p[-2])
! 		    // path ends with '//', use full path
! 		    if ((p = make_percent_swname(IObuff, fname)) != NULL)
! 		    {
! 			backup = modname(p, backup_ext, FALSE);
! 			vim_free(p);
! 		    }
! #endif
! 		if (backup == NULL)
  		{
! 		    rootname = get_file_in_dir(fname, IObuff);
! 		    if (rootname == NULL)
! 			backup = NULL;
! 		    else
! 		    {
! 			backup = buf_modname(
! 				(buf->b_p_sn || buf->b_shortname),
! 						rootname, backup_ext, FALSE);
! 			vim_free(rootname);
! 		    }
  		}
  
  		if (backup != NULL)
***************
*** 6252,6258 ****
  #endif
  
  /*
!  * add extension to file name - change path/fo.o.h to path/fo.o.h.ext or
   * fo_o_h.ext for MSDOS or when shortname option set.
   *
   * Assumed that fname is a valid name found in the filesystem we assure that
--- 6282,6288 ----
  #endif
  
  /*
!  * Add extension to file name - change path/fo.o.h to path/fo.o.h.ext or
   * fo_o_h.ext for MSDOS or when shortname option set.
   *
   * Assumed that fname is a valid name found in the filesystem we assure that
*** ../vim-8.1.0250/src/memline.c	2018-05-26 17:35:19.717625256 +0200
--- src/memline.c	2018-08-07 21:32:43.441160597 +0200
***************
*** 262,270 ****
  #endif
  static void long_to_char(long, char_u *);
  static long char_to_long(char_u *);
- #if defined(UNIX) || defined(WIN3264)
- static char_u *make_percent_swname(char_u *dir, char_u *name);
- #endif
  #ifdef FEAT_CRYPT
  static cryptstate_T *ml_crypt_prepare(memfile_T *mfp, off_T offset, int reading);
  #endif
--- 262,267 ----
***************
*** 2007,2024 ****
      return file_count;
  }
  
! #if defined(UNIX) || defined(WIN3264)  /* Need _very_ long file names */
  /*
   * Append the full path to name with path separators made into percent
   * signs, to dir. An unnamed buffer is handled as "" (<currentdir>/"")
   */
!     static char_u *
  make_percent_swname(char_u *dir, char_u *name)
  {
!     char_u *d, *s, *f;
  
!     f = fix_fname(name != NULL ? name : (char_u *) "");
!     d = NULL;
      if (f != NULL)
      {
  	s = alloc((unsigned)(STRLEN(f) + 1));
--- 2004,2021 ----
      return file_count;
  }
  
! #if defined(UNIX) || defined(WIN3264) || defined(PROTO)
  /*
+  * Need _very_ long file names.
   * Append the full path to name with path separators made into percent
   * signs, to dir. An unnamed buffer is handled as "" (<currentdir>/"")
   */
!     char_u *
  make_percent_swname(char_u *dir, char_u *name)
  {
!     char_u *d = NULL, *s, *f;
  
!     f = fix_fname(name != NULL ? name : (char_u *)"");
      if (f != NULL)
      {
  	s = alloc((unsigned)(STRLEN(f) + 1));
***************
*** 4070,4077 ****
  }
  
  #if defined(FEAT_EVAL)
- static int do_swapexists(buf_T *buf, char_u *fname);
- 
  /*
   * Trigger the SwapExists autocommands.
   * Returns a value for equivalent to do_dialog() (see below):
--- 4067,4072 ----
*** ../vim-8.1.0250/src/proto/memline.pro	2018-05-17 13:52:44.000000000 +0200
--- src/proto/memline.pro	2018-08-07 20:56:46.217467718 +0200
***************
*** 34,37 ****
--- 34,38 ----
  void ml_decrypt_data(memfile_T *mfp, char_u *data, off_T offset, unsigned size);
  long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp);
  void goto_byte(long cnt);
+ char_u *make_percent_swname (char_u *dir, char_u *name);
  /* vim: set ft=c : */
*** ../vim-8.1.0250/src/testdir/test_alot.vim	2018-07-23 04:11:37.648969780 +0200
--- src/testdir/test_alot.vim	2018-08-07 20:57:34.725202003 +0200
***************
*** 2,7 ****
--- 2,8 ----
  " This makes testing go faster, since Vim doesn't need to restart.
  
  source test_assign.vim
+ source test_backup.vim
  source test_bufline.vim
  source test_cd.vim
  source test_changedtick.vim
*** ../vim-8.1.0250/src/testdir/test_backup.vim	2018-08-07 21:37:56.879462014 +0200
--- src/testdir/test_backup.vim	2018-08-07 21:21:16.656940451 +0200
***************
*** 0 ****
--- 1,58 ----
+ " Tests for the backup function
+ 
+ func Test_backup()
+   set backup backupdir=.
+   new
+   call setline(1, ['line1', 'line2'])
+   :f Xbackup.txt
+   :w! Xbackup.txt
+   " backup file is only created after
+   " writing a second time (before overwriting)
+   :w! Xbackup.txt
+   let l = readfile('Xbackup.txt~')
+   call assert_equal(['line1', 'line2'], l)
+   bw!
+   set backup&vim backupdir&vim
+   call delete('Xbackup.txt')
+   call delete('Xbackup.txt~')
+ endfunc
+ 
+ func Test_backup2()
+   set backup backupdir=.//
+   new
+   call setline(1, ['line1', 'line2', 'line3'])
+   :f Xbackup.txt
+   :w! Xbackup.txt
+   " backup file is only created after
+   " writing a second time (before overwriting)
+   :w! Xbackup.txt
+   sp *Xbackup.txt~
+   call assert_equal(['line1', 'line2', 'line3'], getline(1,'$'))
+   let f=expand('%')
+   call assert_match('src%testdir%Xbackup.txt\~', f)
+   bw!
+   bw!
+   call delete('Xbackup.txt')
+   call delete(f)
+   set backup&vim backupdir&vim
+ endfunc
+ 
+ func Test_backup2_backupcopy()
+   set backup backupdir=.// backupcopy=yes
+   new
+   call setline(1, ['line1', 'line2', 'line3'])
+   :f Xbackup.txt
+   :w! Xbackup.txt
+   " backup file is only created after
+   " writing a second time (before overwriting)
+   :w! Xbackup.txt
+   sp *Xbackup.txt~
+   call assert_equal(['line1', 'line2', 'line3'], getline(1,'$'))
+   let f=expand('%')
+   call assert_match('src%testdir%Xbackup.txt\~', f)
+   bw!
+   bw!
+   call delete('Xbackup.txt')
+   call delete(f)
+   set backup&vim backupdir&vim backupcopy&vim
+ endfunc
*** ../vim-8.1.0250/src/Make_all.mak	2018-07-23 04:11:37.644969804 +0200
--- src/Make_all.mak	2018-08-07 21:17:31.690274783 +0200
***************
*** 12,17 ****
--- 12,18 ----
  	test_autocmd \
  	test_autoload \
  	test_backspace_opt \
+ 	test_backup \
  	test_blockedit \
  	test_breakindent \
  	test_bufline \
*** ../vim-8.1.0250/src/version.c	2018-08-07 20:47:02.756848221 +0200
--- src/version.c	2018-08-07 20:59:39.444509393 +0200
***************
*** 796,797 ****
--- 796,799 ----
  {   /* Add new patch number below this line */
+ /**/
+     251,
  /**/

-- 
TALL KNIGHT: When you have found the shrubbery, then you must cut down the
             mightiest tree in the forest ... with a herring.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

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