]>
Commit | Line | Data |
---|---|---|
f0b7bf8c AM |
1 | diff --git a/NEWS b/NEWS |
2 | index 28d0e91..42afed7 100644 | |
3 | --- a/NEWS | |
4 | +++ b/NEWS | |
5 | @@ -1,3 +1,9 @@ | |
6 | +* When a file isn't being deleted because the file contents don't match the | |
7 | + patch, the resulting message is now "Not deleting file ... as content | |
8 | + differs from patch" instead of "File ... is not empty after patch; not | |
9 | + deleting". | |
10 | +* Function names in hunks (from diff -p) are now preserved in reject files. | |
11 | + | |
12 | Changes in version 2.7.1: | |
13 | ||
14 | * Two critical bug fixes in the "diff --git" format support. | |
15 | diff --git a/configure.ac b/configure.ac | |
16 | index dc837d6..f078469 100644 | |
17 | --- a/configure.ac | |
18 | +++ b/configure.ac | |
19 | @@ -33,7 +33,7 @@ AM_CONDITIONAL([ENABLE_MERGE], [test "$enableval" != no]) | |
20 | AM_CONDITIONAL([ALPHA_VERSION], | |
21 | [[echo "$PACKAGE_VERSION" | grep -- "-[0-9a-f][0-9a-f]*\\(-dirty\\)\\?$" >/dev/null]]) | |
22 | ||
23 | -AM_INIT_AUTOMAKE([1.11.2 -Wall -Werror gnu dist-bzip2 dist-xz color-tests parallel-tests]) | |
24 | +AM_INIT_AUTOMAKE([1.11.2 -Wall gnu dist-bzip2 dist-xz color-tests parallel-tests]) | |
25 | AM_SILENT_RULES([yes]) | |
26 | ||
27 | AC_CONFIG_HEADER([config.h:config.hin]) | |
28 | diff --git a/patch.man b/patch.man | |
29 | index c5cc5c4..2c9def5 100644 | |
30 | --- a/patch.man | |
31 | +++ b/patch.man | |
32 | @@ -1,14 +1,10 @@ | |
33 | .\" patch man page | |
34 | -.de Id | |
35 | -.ds Dt \\$4 | |
36 | -.. | |
37 | .ds = \-\^\- | |
38 | .de Sp | |
39 | .if t .sp .3 | |
40 | .if n .sp | |
41 | .. | |
42 | -.TH PATCH 1 \*(Dt GNU | |
43 | -.ta 3n | |
44 | +.TH PATCH 1 "" GNU | |
45 | .SH NAME | |
46 | patch \- apply a diff file to an original | |
47 | .SH SYNOPSIS | |
48 | @@ -241,7 +237,9 @@ asks for confirmation before proceeding. | |
49 | The upshot of all this is that you should be able to say, while in a news | |
50 | interface, something like the following: | |
51 | .Sp | |
52 | - \fB| patch \-d /usr/src/local/blurfl\fP | |
53 | +.RS | |
54 | +\fB| patch \-d /usr/src/local/blurfl\fP | |
55 | +.RE | |
56 | .Sp | |
57 | and patch a file in the | |
58 | .B blurfl | |
59 | @@ -445,8 +443,8 @@ This option implies \fB\*=forward\fP and does not take the | |
60 | Interpret the patch file as a normal diff. | |
61 | .TP | |
62 | \fB\-N\fP or \fB\*=forward\fP | |
63 | -Ignore patches that seem to be reversed or already applied. It is only checked if | |
64 | -the first hunk of a patch can be reversed. | |
65 | +When a patch does not apply, patch usually checks if the patch looks like it | |
66 | +has been reversed. The \fB\*=forward\fP option prevents that. | |
67 | See also | |
68 | .BR \-R . | |
69 | .TP | |
70 | @@ -470,7 +468,9 @@ you keep your files in a different directory than the person who sent | |
71 | out the patch. | |
72 | For example, supposing the file name in the patch file was | |
73 | .Sp | |
74 | - \fB/u/howard/src/blurfl/blurfl.c\fP | |
75 | +.RS | |
76 | +\fB/u/howard/src/blurfl/blurfl.c\fP | |
77 | +.RE | |
78 | .Sp | |
79 | setting | |
80 | .B \-p0 | |
81 | @@ -478,13 +478,17 @@ gives the entire file name unmodified, | |
82 | .B \-p1 | |
83 | gives | |
84 | .Sp | |
85 | - \fBu/howard/src/blurfl/blurfl.c\fP | |
86 | +.RS | |
87 | +\fBu/howard/src/blurfl/blurfl.c\fP | |
88 | +.RE | |
89 | .Sp | |
90 | without the leading slash, | |
91 | .B \-p4 | |
92 | gives | |
93 | .Sp | |
94 | - \fBblurfl/blurfl.c\fP | |
95 | +.RS | |
96 | +\fBblurfl/blurfl.c\fP | |
97 | +.RE | |
98 | .Sp | |
99 | and not specifying | |
100 | .B \-p | |
101 | @@ -876,7 +880,9 @@ or | |
102 | option. | |
103 | Here is an example command, using Bourne shell syntax: | |
104 | .Sp | |
105 | - \fBLC_ALL=C TZ=UTC0 diff \-Naur gcc\-2.7 gcc\-2.8\fP | |
106 | +.RS | |
107 | +\fBLC_ALL=C TZ=UTC0 diff \-Naur gcc\-2.7 gcc\-2.8\fP | |
108 | +.RE | |
109 | .PP | |
110 | Tell your recipients how to apply the patch | |
111 | by telling them which directory to | |
112 | @@ -925,14 +931,16 @@ If the recipient is supposed to use the | |
113 | .BI \-p N | |
114 | option, do not send output that looks like this: | |
115 | .Sp | |
116 | -.ft B | |
117 | +.RS | |
118 | +.ft CW | |
119 | .ne 3 | |
120 | - diff \-Naur v2.0.29/prog/README prog/README | |
121 | +diff \-Naur v2.0.29/prog/README prog/README | |
122 | .br | |
123 | - \-\^\-\^\- v2.0.29/prog/README Mon Mar 10 15:13:12 1997 | |
124 | +\-\^\-\^\- v2.0.29/prog/README Mon Mar 10 15:13:12 1997 | |
125 | .br | |
126 | - +\^+\^+ prog/README Mon Mar 17 14:58:22 1997 | |
127 | ++\^+\^+ prog/README Mon Mar 17 14:58:22 1997 | |
128 | .ft | |
129 | +.RE | |
130 | .Sp | |
131 | because the two file names have different numbers of slashes, | |
132 | and different versions of | |
133 | @@ -940,14 +948,16 @@ and different versions of | |
134 | interpret the file names differently. | |
135 | To avoid confusion, send output that looks like this instead: | |
136 | .Sp | |
137 | -.ft B | |
138 | +.RS | |
139 | +.ft CW | |
140 | .ne 3 | |
141 | - diff \-Naur v2.0.29/prog/README v2.0.30/prog/README | |
142 | +diff \-Naur v2.0.29/prog/README v2.0.30/prog/README | |
143 | .br | |
144 | - \-\^\-\^\- v2.0.29/prog/README Mon Mar 10 15:13:12 1997 | |
145 | +\-\^\-\^\- v2.0.29/prog/README Mon Mar 10 15:13:12 1997 | |
146 | .br | |
147 | - +\^+\^+ v2.0.30/prog/README Mon Mar 17 14:58:22 1997 | |
148 | ++\^+\^+ v2.0.30/prog/README Mon Mar 17 14:58:22 1997 | |
149 | .ft | |
150 | +.RE | |
151 | .Sp | |
152 | .PP | |
153 | Avoid sending patches that compare backup file names like | |
154 | diff --git a/src/patch.c b/src/patch.c | |
155 | index 828943b..12028a9 100644 | |
156 | --- a/src/patch.c | |
157 | +++ b/src/patch.c | |
158 | @@ -150,6 +150,10 @@ main (int argc, char **argv) | |
159 | else if ((version_control = getenv ("VERSION_CONTROL"))) | |
160 | version_control_context = "$VERSION_CONTROL"; | |
161 | ||
162 | + init_backup_hash_table (); | |
163 | + init_files_to_delete (); | |
164 | + init_files_to_output (); | |
165 | + | |
166 | /* parse switches */ | |
167 | Argc = argc; | |
168 | Argv = argv; | |
169 | @@ -162,10 +166,6 @@ main (int argc, char **argv) | |
170 | if (make_backups | backup_if_mismatch) | |
171 | backup_type = get_version (version_control_context, version_control); | |
172 | ||
173 | - init_backup_hash_table (); | |
174 | - init_files_to_delete (); | |
175 | - init_files_to_output (); | |
176 | - | |
177 | init_output (&outstate); | |
178 | if (outfile) | |
179 | outstate.ofp = open_outfile (outfile); | |
180 | @@ -519,7 +519,7 @@ main (int argc, char **argv) | |
181 | mismatch = true; | |
182 | somefailed = true; | |
183 | if (verbosity != SILENT) | |
184 | - say ("File %s is not empty after patch; not deleting\n", | |
185 | + say ("Not deleting file %s as content differs from patch\n", | |
186 | quotearg (outname)); | |
187 | } | |
188 | ||
189 | @@ -646,8 +646,8 @@ main (int argc, char **argv) | |
190 | if (outstate.ofp && (ferror (outstate.ofp) || fclose (outstate.ofp) != 0)) | |
191 | write_fatal (); | |
192 | output_files (NULL); | |
193 | - delete_files (); | |
194 | cleanup (); | |
195 | + delete_files (); | |
196 | if (somefailed) | |
197 | exit (1); | |
198 | return 0; | |
199 | @@ -762,7 +762,7 @@ static char const *const option_help[] = | |
200 | "", | |
201 | " -D NAME --ifdef=NAME Make merged if-then-else output using NAME.", | |
202 | #ifdef ENABLE_MERGE | |
203 | -" -m --merge Merge using conflict markers instead of creating reject files.", | |
204 | +" --merge Merge using conflict markers instead of creating reject files.", | |
205 | #endif | |
206 | " -E --remove-empty-files Remove output files that are empty after patching.", | |
207 | "", | |
208 | @@ -1237,6 +1237,7 @@ abort_hunk_unified (bool header, bool reverse) | |
209 | lin old = 1; | |
210 | lin lastline = pch_ptrn_lines (); | |
211 | lin new = lastline + 1; | |
212 | + char const *c_function = pch_c_function(); | |
213 | ||
214 | if (header) | |
215 | { | |
216 | @@ -1251,7 +1252,7 @@ abort_hunk_unified (bool header, bool reverse) | |
217 | print_unidiff_range (rejfp, pch_first () + out_offset, lastline); | |
218 | fprintf (rejfp, " +"); | |
219 | print_unidiff_range (rejfp, pch_newfirst () + out_offset, pch_repl_lines ()); | |
220 | - fprintf (rejfp, " @@\n"); | |
221 | + fprintf (rejfp, " @@%s\n", c_function ? c_function : ""); | |
222 | ||
223 | while (pch_char (new) == '=' || pch_char (new) == '\n') | |
224 | new++; | |
225 | diff --git a/src/util.c b/src/util.c | |
226 | index 1cc1a68..0af6013 100644 | |
227 | --- a/src/util.c | |
228 | +++ b/src/util.c | |
229 | @@ -1599,7 +1599,7 @@ make_tempfile (char const **name, char letter, char const *real_name, | |
230 | int try_makedirs_errno = ENOENT; | |
231 | char *template; | |
232 | ||
233 | - if (real_name) | |
234 | + if (real_name && ! dry_run) | |
235 | { | |
236 | char *dirname, *basename; | |
237 | ||
238 | diff --git a/tests/Makefile.am b/tests/Makefile.am | |
239 | index 02fc6de..cfc4f37 100644 | |
240 | --- a/tests/Makefile.am | |
241 | +++ b/tests/Makefile.am | |
242 | @@ -20,6 +20,7 @@ TESTS = \ | |
243 | asymmetric-hunks \ | |
244 | backup-prefix-suffix \ | |
245 | bad-filenames \ | |
246 | + bad-usage \ | |
247 | concat-git-diff \ | |
248 | copy-rename \ | |
249 | corrupt-reject-files \ | |
250 | @@ -49,6 +50,7 @@ TESTS = \ | |
251 | reject-format \ | |
252 | remember-backup-files \ | |
253 | remember-reject-files \ | |
254 | + remove-directories \ | |
255 | symlinks \ | |
256 | unmodified-files | |
257 | ||
258 | diff --git a/tests/bad-usage b/tests/bad-usage | |
259 | new file mode 100644 | |
260 | index 0000000..022eeda | |
261 | --- /dev/null | |
262 | +++ b/tests/bad-usage | |
263 | @@ -0,0 +1,18 @@ | |
264 | +# Copyright (C) 2009, 2011-2012 Free Software Foundation, Inc. | |
265 | +# | |
266 | +# Copying and distribution of this file, with or without modification, | |
267 | +# in any medium, are permitted without royalty provided the copyright | |
268 | +# notice and this notice are preserved. | |
269 | + | |
270 | +. $srcdir/test-lib.sh | |
271 | + | |
272 | +require_cat | |
273 | +use_local_patch | |
274 | +use_tmpdir | |
275 | + | |
276 | +# ============================================================== | |
277 | + | |
278 | +check 'patch -px || echo "status: $?"' <<EOF | |
279 | +$PATCH: **** strip count x is not a number | |
280 | +status: 2 | |
281 | +EOF | |
282 | diff --git a/tests/create-delete b/tests/create-delete | |
283 | index 7c46166..404d99e 100644 | |
284 | --- a/tests/create-delete | |
285 | +++ b/tests/create-delete | |
286 | @@ -182,7 +182,7 @@ EOF | |
287 | ||
288 | check 'patch -p0 < p.diff || echo status: $?' <<EOF | |
289 | patching file target | |
290 | -File target is not empty after patch; not deleting | |
291 | +Not deleting file target as content differs from patch | |
292 | status: 1 | |
293 | EOF | |
294 | ||
295 | @@ -202,7 +202,7 @@ EOF | |
296 | ||
297 | check 'patch -p0 < p.diff || echo status: $?' <<EOF | |
298 | patching file target | |
299 | -File target is not empty after patch; not deleting | |
300 | +Not deleting file target as content differs from patch | |
301 | status: 1 | |
302 | EOF | |
303 | ||
304 | @@ -212,23 +212,27 @@ EOF | |
305 | ||
306 | # -------------------------------------------------------------- | |
307 | printf '\0' > target | |
308 | -cat > p.diff <<EOF | |
309 | +if ! test -s target; then | |
310 | + echo "Failed to printf a null character; skipping this test" | |
311 | +else | |
312 | + cat > p.diff <<EOF | |
313 | diff --git a/target b/target | |
314 | deleted file mode 100644 | |
315 | index f76dd23..0000000 | |
316 | Binary files a/target and /dev/null differ | |
317 | EOF | |
318 | ||
319 | -check 'patch -p1 -b < p.diff || echo status: $?' <<EOF | |
320 | + check 'patch -p1 -b < p.diff || echo status: $?' <<EOF | |
321 | patching file target | |
322 | -File target is not empty after patch; not deleting | |
323 | +Not deleting file target as content differs from patch | |
324 | status: 1 | |
325 | EOF | |
326 | ||
327 | -ncheck 'test -e target' | |
328 | + ncheck 'test -e target' | |
329 | ||
330 | # Patch creates a backup file even when the original file remains unchanged: | |
331 | -ncheck 'test -e target.orig' | |
332 | + ncheck 'test -e target.orig' | |
333 | +fi | |
334 | ||
335 | # ================================================================ | |
336 | # File not expected to become empty does become empty | |
337 | diff --git a/tests/create-directory b/tests/create-directory | |
338 | index f02ce6e..9fc3288 100644 | |
339 | --- a/tests/create-directory | |
340 | +++ b/tests/create-directory | |
341 | @@ -4,15 +4,14 @@ | |
342 | # in any medium, are permitted without royalty provided the copyright | |
343 | # notice and this notice are preserved. | |
344 | ||
345 | -# Check whether patch correctly creates directories before creating | |
346 | -# new files. | |
347 | - | |
348 | . $srcdir/test-lib.sh | |
349 | ||
350 | use_local_patch | |
351 | use_tmpdir | |
352 | ||
353 | # ============================================================== | |
354 | +# Check whether patch correctly creates directories before creating | |
355 | +# new files. | |
356 | ||
357 | cat > f.diff <<EOF | |
358 | --- /dev/null | |
359 | @@ -25,3 +24,20 @@ EOF | |
360 | check 'patch -p0 < f.diff' <<EOF | |
361 | patching file b/newfile | |
362 | EOF | |
363 | + | |
364 | +# ============================================================== | |
365 | +# Make sure it doesn't create files or directories in the target | |
366 | +# location in --dry-run mode | |
367 | +mkdir d | |
368 | +cat > f.diff <<EOF | |
369 | +--- /dev/null | |
370 | ++++ d/e/f | |
371 | +@@ -0,0 +1 @@ | |
372 | ++f | |
373 | +EOF | |
374 | + | |
375 | +chmod u-w d | |
376 | +check 'patch -p0 --dry-run < f.diff' <<EOF | |
377 | +checking file d/e/f | |
378 | +EOF | |
379 | +chmod u+w d | |
380 | diff --git a/tests/reject-format b/tests/reject-format | |
381 | index be710f5..0b02af6 100644 | |
382 | --- a/tests/reject-format | |
383 | +++ b/tests/reject-format | |
384 | @@ -79,7 +79,7 @@ check 'cat f.rej' <<EOF | |
385 | Index: f | |
386 | --- f.orig | |
387 | +++ f | |
388 | -@@ -2,6 +2,6 @@ | |
389 | +@@ -2,6 +2,6 @@ a() { | |
390 | 2 | |
391 | 3 | |
392 | $preserve_trailing_blank | |
393 | @@ -102,7 +102,7 @@ EOF | |
394 | check 'cat f.rej' <<EOF | |
395 | --- f.orig | |
396 | +++ f | |
397 | -@@ -2,6 +2,6 @@ | |
398 | +@@ -2,6 +2,6 @@ a() { | |
399 | 2 | |
400 | 3 | |
401 | $preserve_trailing_blank | |
402 | diff --git a/tests/remove-directories b/tests/remove-directories | |
403 | new file mode 100644 | |
404 | index 0000000..6acdc49 | |
405 | --- /dev/null | |
406 | +++ b/tests/remove-directories | |
407 | @@ -0,0 +1,29 @@ | |
408 | +# Copyright (C) 2013 Free Software Foundation, Inc. | |
409 | +# | |
410 | +# Copying and distribution of this file, with or without modification, | |
411 | +# in any medium, are permitted without royalty provided the copyright | |
412 | +# notice and this notice are preserved. | |
413 | + | |
414 | +. $srcdir/test-lib.sh | |
415 | + | |
416 | +require_cat | |
417 | +use_local_patch | |
418 | +use_tmpdir | |
419 | + | |
420 | +# ============================================================== | |
421 | +# Remove empty parent diectories when removing a file | |
422 | + | |
423 | +mkdir dir | |
424 | +echo foobar > dir/file | |
425 | +cat > apatch <<EOF | |
426 | +--- dir/file | |
427 | ++++ /dev/null | |
428 | +@@ -1 +0,0 @@ | |
429 | +-foobar | |
430 | +EOF | |
431 | + | |
432 | +check 'patch -p0 -E < apatch' <<EOF | |
433 | +patching file dir/file | |
434 | +EOF | |
435 | + | |
436 | +ncheck '! test -e dir' |