source: trunk/minix/man/man1/patch.1@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 16.9 KB
Line 
1.\" -*- nroff -*-
2.rn '' }`
3'\" $Header: /cvsup/minix/src/man/man1/patch.1,v 1.1 2005/05/02 13:01:39 beng Exp $
4'\"
5'\" $Log: patch.1,v $
6'\" Revision 1.1 2005/05/02 13:01:39 beng
7'\" Added man pages.
8'\"
9'\" Revision 2.0.1.2 88/06/22 20:47:18 lwall
10'\" patch12: now avoids Bell System Logo
11'\"
12'\" Revision 2.0.1.1 88/06/03 15:12:51 lwall
13'\" patch10: -B switch was contributed.
14'\"
15'\" Revision 2.0 86/09/17 15:39:09 lwall
16'\" Baseline for netwide release.
17'\"
18'\" Revision 1.4 86/08/01 19:23:22 lwall
19'\" Documented -v, -p, -F.
20'\" Added notes to patch senders.
21'\"
22'\" Revision 1.3 85/03/26 15:11:06 lwall
23'\" Frozen.
24'\"
25'\" Revision 1.2.1.4 85/03/12 16:14:27 lwall
26'\" Documented -p.
27'\"
28'\" Revision 1.2.1.3 85/03/12 16:09:41 lwall
29'\" Documented -D.
30'\"
31'\" Revision 1.2.1.2 84/12/05 11:06:55 lwall
32'\" Added -l switch, and noted bistability bug.
33'\"
34'\" Revision 1.2.1.1 84/12/04 17:23:39 lwall
35'\" Branch for sdcrdcf changes.
36'\"
37'\" Revision 1.2 84/12/04 17:22:02 lwall
38'\" Baseline version.
39'\"
40.de Sh
41.br
42.ne 5
43.PP
44\fB\\$1\fR
45.PP
46..
47.de Sp
48.if t .sp .5v
49.if n .sp
50..
51'\"
52'\" Set up \*(-- to give an unbreakable dash;
53'\" string Tr holds user defined translation string.
54'\" Bell System Logo is used as a dummy character.
55'\"
56'\" Shut up a groff -ww warning.
57'\".if \n(.g .if !dTr .ds Tr
58'\".ie n \{\
59.tr \(*W-\*(Tr
60'\".ds -- \(*W-
61'\".if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
62'\".if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
63.ds L" ""
64.ds R" ""
65.ds L' '
66.ds R' '
67'\"'br \}
68'\".el \{\
69.ds -- \(em\|
70.tr \*(Tr
71.ds L" ``
72.ds R" ''
73.ds L' `
74.ds R' '
75'\"'br\}
76.TH PATCH 1 LOCAL
77.SH NAME
78patch - apply a diff file to an original
79.SH SYNOPSIS
80.B patch
81[options] [origfile [patchfile]] [+ [options] [origfile]]...
82.sp
83but usually just
84.sp
85.B patch
86<patchfile
87.SH DESCRIPTION
88.I Patch
89will take a patch file containing any of the four forms of difference
90listing produced by the
91.I diff
92program and apply those differences to an original file, producing a patched
93version.
94By default, the patched version is put in place of the original, with
95the original file backed up to the same name with the
96extension \*(L".orig\*(R" (\*(L"~\*(R" on systems that do not
97support long filenames), or as specified by the
98.BR -b ,
99.BR -B ,
100or
101.B -V
102switches.
103The extension used for making backup files may also be specified in the
104.B SIMPLE_BACKUP_SUFFIX
105environment variable, which is overridden by above switches.
106.PP
107If the backup file already exists,
108.B patch
109creates a new backup file name by changing the first lowercase letter
110in the last component of the file's name into uppercase. If there are
111no more lowercase letters in the name, it removes the first character
112from the name. It repeats this process until it comes up with a
113backup file that does not already exist.
114.PP
115You may also specify where you want the output to go with a
116.B -o
117switch; if that file already exists, it is backed up first.
118.PP
119If
120.I patchfile
121is omitted, or is a hyphen, the patch will be read from standard input.
122.PP
123Upon startup, patch will attempt to determine the type of the diff listing,
124unless over-ruled by a
125.BR -c ,
126.BR -e ,
127.BR -n ,
128or
129.B -u
130switch.
131Context diffs (old-style, new-style, and unified) and
132normal diffs are applied by the
133.I patch
134program itself, while ed diffs are simply fed to the
135.I ed
136editor via a pipe.
137.PP
138.I Patch
139will try to skip any leading garbage, apply the diff,
140and then skip any trailing garbage.
141Thus you could feed an article or message containing a
142diff listing to
143.IR patch ,
144and it should work.
145If the entire diff is indented by a consistent amount,
146this will be taken into account.
147.PP
148With context diffs, and to a lesser extent with normal diffs,
149.I patch
150can detect when the line numbers mentioned in the patch are incorrect,
151and will attempt to find the correct place to apply each hunk of the patch.
152As a first guess, it takes the line number mentioned for the hunk, plus or
153minus any offset used in applying the previous hunk.
154If that is not the correct place,
155.I patch
156will scan both forwards and backwards for a set of lines matching the context
157given in the hunk.
158First
159.I patch
160looks for a place where all lines of the context match.
161If no such place is found, and it's a context diff, and the maximum fuzz factor
162is set to 1 or more, then another scan takes place ignoring the first and last
163line of context.
164If that fails, and the maximum fuzz factor is set to 2 or more,
165the first two and last two lines of context are ignored,
166and another scan is made.
167(The default maximum fuzz factor is 2.)
168If
169.I patch
170cannot find a place to install that hunk of the patch, it will put the
171hunk out to a reject file, which normally is the name of the output file
172plus \*(L".rej\*(R" (\*(L"#\*(R" on systems that do not support
173long filenames).
174(Note that the rejected hunk will come out in context diff form whether the
175input patch was a context diff or a normal diff.
176If the input was a normal diff, many of the contexts will simply be null.)
177The line numbers on the hunks in the reject file may be different than
178in the patch file: they reflect the approximate location patch thinks the
179failed hunks belong in the new file rather than the old one.
180.PP
181As each hunk is completed, you will be told whether the hunk succeeded or
182failed, and which line (in the new file)
183.I patch
184thought the hunk should go on.
185If this is different from the line number specified in the diff you will
186be told the offset.
187A single large offset MAY be an indication that a hunk was installed in the
188wrong place.
189You will also be told if a fuzz factor was used to make the match, in which
190case you should also be slightly suspicious.
191.PP
192If no original file is specified on the command line,
193.I patch
194will try to figure out from the leading garbage what the name of the file
195to edit is.
196In the header of a context diff, the filename is found from lines beginning
197with \*(L"***\*(R" or \*(L"---\*(R", with the shortest name of an existing
198file winning.
199Only context diffs have lines like that, but if there is an \*(L"Index:\*(R"
200line in the leading garbage,
201.I patch
202will try to use the filename from that line.
203The context diff header takes precedence over an Index line.
204If no filename can be intuited from the leading garbage, you will be asked
205for the name of the file to patch.
206.PP
207If the original file cannot be found or is read-only, but a suitable
208SCCS or RCS file is handy,
209.I patch
210will attempt to get or check out the file.
211.PP
212Additionally, if the leading garbage contains a \*(L"Prereq: \*(R" line,
213.I patch
214will take the first word from the prerequisites line (normally a version
215number) and check the input file to see if that word can be found.
216If not,
217.I patch
218will ask for confirmation before proceeding.
219.PP
220The upshot of all this is that you should be able to say, while in a news
221interface, the following:
222.Sp
223 | patch -d /usr/src/local/blurfl
224.Sp
225and patch a file in the blurfl directory directly from the article containing
226the patch.
227.PP
228If the patch file contains more than one patch,
229.I patch
230will try to apply each of them as if they came from separate patch files.
231This means, among other things, that it is assumed that the name of the file
232to patch must be determined for each diff listing,
233and that the garbage before each diff listing will
234be examined for interesting things such as filenames and revision level, as
235mentioned previously.
236You can give switches (and another original file name) for the second and
237subsequent patches by separating the corresponding argument lists
238by a \*(L'+\*(R'.
239(The argument list for a second or subsequent patch may not specify a new
240patch file, however.)
241.PP
242.I Patch
243recognizes the following switches:
244.TP 5
245.B \-b
246causes the next argument to be interpreted as the backup extension, to be
247used in place of \*(L".orig\*(R" or \*(L"~\*(R".
248.TP 5
249.B \-B
250causes the next argument to be interpreted as a prefix to the backup file
251name. If this argument is specified any argument from -b will be ignored.
252.TP 5
253.B \-c
254forces
255.I patch
256to interpret the patch file as a context diff.
257.TP 5
258.B \-d
259causes
260.I patch
261to interpret the next argument as a directory, and cd to it before doing
262anything else.
263.TP 5
264.B \-D
265causes
266.I patch
267to use the "#ifdef...#endif" construct to mark changes.
268The argument following will be used as the differentiating symbol.
269Note that, unlike the C compiler, there must be a space between the
270.B \-D
271and the argument.
272.TP 5
273.B \-e
274forces
275.I patch
276to interpret the patch file as an ed script.
277.TP 5
278.B \-E
279causes
280.I patch
281to remove output files that are empty after the patches have been applied.
282.TP 5
283.B \-f
284forces
285.I patch
286to assume that the user knows exactly what he or she is doing, and to not
287ask any questions. It assumes the following: skip patches for which a
288file to patch can't be found; patch files even though they have the
289wrong version for the ``Prereq:'' line in the patch; and assume that
290patches are not reversed even if they look like they are.
291This option does not suppress commentary; use
292.B \-s
293for that.
294.TP 5
295.B \-t
296similar to
297.BR \-f ,
298in that it suppresses questions, but makes some different assumptions:
299skip patches for which a file to patch can't be found (the same as \fB\-f\fP);
300skip patches for which the file has the wrong version for the ``Prereq:'' line
301in the patch; and assume that patches are reversed if they look like
302they are.
303.TP 5
304.B \-F<number>
305sets the maximum fuzz factor.
306This switch only applies to context diffs, and causes
307.I patch
308to ignore up to that many lines in looking for places to install a hunk.
309Note that a larger fuzz factor increases the odds of a faulty patch.
310The default fuzz factor is 2, and it may not be set to more than
311the number of lines of context in the context diff, ordinarily 3.
312.TP 5
313.B \-l
314causes the pattern matching to be done loosely, in case the tabs and
315spaces have been munged in your input file.
316Any sequence of whitespace in the pattern line will match any sequence
317in the input file.
318Normal characters must still match exactly.
319Each line of the context must still match a line in the input file.
320.TP 5
321.B \-n
322forces
323.I patch
324to interpret the patch file as a normal diff.
325.TP 5
326.B \-N
327causes
328.I patch
329to ignore patches that it thinks are reversed or already applied.
330See also
331.B \-R .
332.TP 5
333.B \-o
334causes the next argument to be interpreted as the output file name.
335.TP 5
336.B \-p<number>
337sets the pathname strip count,
338which controls how pathnames found in the patch file are treated, in case
339the you keep your files in a different directory than the person who sent
340out the patch.
341The strip count specifies how many slashes are to be stripped from
342the front of the pathname.
343(Any intervening directory names also go away.)
344For example, supposing the filename in the patch file was
345.sp
346 /u/howard/src/blurfl/blurfl.c
347.sp
348setting
349.B \-p
350or
351.B \-p0
352gives the entire pathname unmodified,
353.B \-p1
354gives
355.sp
356 u/howard/src/blurfl/blurfl.c
357.sp
358without the leading slash,
359.B \-p4
360gives
361.sp
362 blurfl/blurfl.c
363.sp
364and not specifying
365.B \-p
366at all just gives you "blurfl.c", unless all of the directories in the
367leading path (u/howard/src/blurfl) exist and that path is relative,
368in which case you get the entire pathname unmodified.
369Whatever you end up with is looked for either in the current directory,
370or the directory specified by the
371.B \-d
372switch.
373.TP 5
374.B \-r
375causes the next argument to be interpreted as the reject file name.
376.TP 5
377.B \-R
378tells
379.I patch
380that this patch was created with the old and new files swapped.
381(Yes, I'm afraid that does happen occasionally, human nature being what it
382is.)
383.I Patch
384will attempt to swap each hunk around before applying it.
385Rejects will come out in the swapped format.
386The
387.B \-R
388switch will not work with ed diff scripts because there is too little
389information to reconstruct the reverse operation.
390.Sp
391If the first hunk of a patch fails,
392.I patch
393will reverse the hunk to see if it can be applied that way.
394If it can, you will be asked if you want to have the
395.B \-R
396switch set.
397If it can't, the patch will continue to be applied normally.
398(Note: this method cannot detect a reversed patch if it is a normal diff
399and if the first command is an append (i.e. it should have been a delete)
400since appends always succeed, due to the fact that a null context will match
401anywhere.
402Luckily, most patches add or change lines rather than delete them, so most
403reversed normal diffs will begin with a delete, which will fail, triggering
404the heuristic.)
405.TP 5
406.B \-s
407makes
408.I patch
409do its work silently, unless an error occurs.
410.TP 5
411.B \-S
412causes
413.I patch
414to ignore this patch from the patch file, but continue on looking
415for the next patch in the file.
416Thus
417.sp
418 patch -S + -S + <patchfile
419.sp
420will ignore the first and second of three patches.
421.TP 5
422.B \-u
423forces
424.I patch
425to interpret the patch file as a unified context diff (a unidiff).
426.TP 5
427.B \-v
428causes
429.I patch
430to print out its revision header and patch level.
431.TP 5
432.B \-V
433causes the next argument to be interpreted as a method for creating
434backup file names. The type of backups made can also be given in the
435.B VERSION_CONTROL
436environment variable, which is overridden by this option.
437The
438.B -B
439option overrides this option, causing the prefix to always be used for
440making backup file names.
441The value of the
442.B VERSION_CONTROL
443environment variable and the argument to the
444.B -V
445option are like the GNU
446Emacs `version-control' variable; they also recognize synonyms that
447are more descriptive. The valid values are (unique abbreviations are
448accepted):
449.RS
450.TP
451`t' or `numbered'
452Always make numbered backups.
453.TP
454`nil' or `existing'
455Make numbered backups of files that already
456have them, simple backups of the others.
457This is the default.
458.TP
459`never' or `simple'
460Always make simple backups.
461.RE
462.TP 5
463.B \-x<number>
464sets internal debugging flags, and is of interest only to
465.I patch
466patchers.
467.SH AUTHOR
468Larry Wall <lwall@netlabs.com>
469.br
470with many other contributors.
471.SH ENVIRONMENT
472.TP
473.B TMPDIR
474Directory to put temporary files in; default is /tmp.
475.TP
476.B SIMPLE_BACKUP_SUFFIX
477Extension to use for backup file names instead of \*(L".orig\*(R" or
478\*(L"~\*(R".
479.TP
480.B VERSION_CONTROL
481Selects when numbered backup files are made.
482.SH FILES
483$TMPDIR/patch*
484.SH SEE ALSO
485diff(1)
486.SH NOTES FOR PATCH SENDERS
487There are several things you should bear in mind if you are going to
488be sending out patches.
489First, you can save people a lot of grief by keeping a patchlevel.h file
490which is patched to increment the patch level as the first diff in the
491patch file you send out.
492If you put a Prereq: line in with the patch, it won't let them apply
493patches out of order without some warning.
494Second, make sure you've specified the filenames right, either in a
495context diff header, or with an Index: line.
496If you are patching something in a subdirectory, be sure to tell the patch
497user to specify a
498.B \-p
499switch as needed.
500Third, you can create a file by sending out a diff that compares a
501null file to the file you want to create.
502This will only work if the file you want to create doesn't exist already in
503the target directory.
504Fourth, take care not to send out reversed patches, since it makes people wonder
505whether they already applied the patch.
506Fifth, while you may be able to get away with putting 582 diff listings into
507one file, it is probably wiser to group related patches into separate files in
508case something goes haywire.
509.SH DIAGNOSTICS
510Too many to list here, but generally indicative that
511.I patch
512couldn't parse your patch file.
513.PP
514The message \*(L"Hmm...\*(R" indicates that there is unprocessed text in
515the patch file and that
516.I patch
517is attempting to intuit whether there is a patch in that text and, if so,
518what kind of patch it is.
519.PP
520.I Patch
521will exit with a non-zero status if any reject files were created.
522When applying a set of patches in a loop it behooves you to check this
523exit status so you don't apply a later patch to a partially patched file.
524.SH CAVEATS
525.I Patch
526cannot tell if the line numbers are off in an ed script, and can only detect
527bad line numbers in a normal diff when it finds a \*(L"change\*(R" or
528a \*(L"delete\*(R" command.
529A context diff using fuzz factor 3 may have the same problem.
530Until a suitable interactive interface is added, you should probably do
531a context diff in these cases to see if the changes made sense.
532Of course, compiling without errors is a pretty good indication that the patch
533worked, but not always.
534.PP
535.I Patch
536usually produces the correct results, even when it has to do a lot of
537guessing.
538However, the results are guaranteed to be correct only when the patch is
539applied to exactly the same version of the file that the patch was
540generated from.
541.SH BUGS
542Could be smarter about partial matches, excessively \&deviant offsets and
543swapped code, but that would take an extra pass.
544.PP
545If code has been duplicated (for instance with #ifdef OLDCODE ... #else ...
546#endif),
547.I patch
548is incapable of patching both versions, and, if it works at all, will likely
549patch the wrong one, and tell you that it succeeded to boot.
550.PP
551If you apply a patch you've already applied,
552.I patch
553will think it is a reversed patch, and offer to un-apply the patch.
554This could be construed as a feature.
555.rn }` ''
Note: See TracBrowser for help on using the repository browser.