|
|
1.1 root 1: ''' $Header: patch.man,v 1.3 85/03/26 15:11:06 lwall Exp $
2: '''
3: ''' $Log: patch.man,v $
4: ''' Revision 1.3 85/03/26 15:11:06 lwall
5: ''' Frozen.
6: '''
7: ''' Revision 1.2.1.4 85/03/12 16:14:27 lwall
8: ''' Documented -p.
9: '''
10: ''' Revision 1.2.1.3 85/03/12 16:09:41 lwall
11: ''' Documented -D.
12: '''
13: ''' Revision 1.2.1.2 84/12/05 11:06:55 lwall
14: ''' Added -l switch, and noted bistability bug.
15: '''
16: ''' Revision 1.2.1.1 84/12/04 17:23:39 lwall
17: ''' Branch for sdcrdcf changes.
18: '''
19: ''' Revision 1.2 84/12/04 17:22:02 lwall
20: ''' Baseline version.
21: '''
22: .de Sh
23: .br
24: .ne 5
25: .PP
26: \fB\\$1\fR
27: .PP
28: ..
29: .de Sp
30: .if t .sp .5v
31: .if n .sp
32: ..
33: '''
34: ''' Set up \*(-- to give an unbreakable dash;
35: ''' string Tr holds user defined translation string.
36: ''' Bell System Logo is used as a dummy character.
37: '''
38: .ie n \{\
39: .tr \(bs-\*(Tr
40: .ds -- \(bs-
41: .if (\n(.H=4u)&(1m=24u) .ds -- \(bs\h'-12u'\(bs\h'-12u'-\" diablo 10 pitch
42: .if (\n(.H=4u)&(1m=20u) .ds -- \(bs\h'-12u'\(bs\h'-8u'-\" diablo 12 pitch
43: .ds L" ""
44: .ds R" ""
45: .ds L' '
46: .ds R' '
47: 'br\}
48: .el\{\
49: .ds -- \(em\|
50: .tr \*(Tr
51: .ds L" ``
52: .ds R" ''
53: .ds L' `
54: .ds R' '
55: 'br\}
56: .TH PATCH 1 LOCAL
57: .SH NAME
58: patch - a program for applying a diff file to an original
59: .SH SYNOPSIS
60: .B patch
61: [options] orig diff [+ [options] orig]
62: .SH DESCRIPTION
63: .I Patch
64: will take a patch file containing any of the three forms of difference
65: listing produced by the
66: .I diff
67: program and apply those differences to an original file, producing a patched
68: version.
69: By default, the patched version is put in place of the original, with
70: the original file backed up to the same name with the
71: extension \*(L".orig\*(R", or as specified by the
72: .B -b
73: switch.
74: You may also specify where you want the output to go with a
75: .B -o
76: switch.
77: If
78: .I diff
79: is omitted, or is a hyphen, the patch will be read from standard input.
80: .PP
81: Upon startup, patch will attempt to determine the type of the diff file,
82: unless over-ruled by a
83: .BR -c ,
84: .BR -e ,
85: or
86: .B -n
87: switch.
88: Context diffs and normal diffs are applied by the
89: .I patch
90: program itself, while ed diffs are simply fed to the
91: .I ed
92: editor via a pipe.
93: .PP
94: .I Patch
95: will try to skip any leading garbage, apply the diff,
96: and then skip any trailing garbage.
97: Thus you could feed an article or message containing a context or normal
98: diff to
99: .IR patch ,
100: and it should work.
101: If the entire diff is indented by a consistent amount,
102: this will be taken into account.
103: .PP
104: With context diffs, and to a lesser extent with normal diffs,
105: .I patch
106: can detect when the line numbers mentioned in the patch are incorrect,
107: and will attempt to find the correct place to apply each hunk of the patch.
108: As a first guess, it takes the line number mentioned for the hunk, plus or
109: minus any offset used in applying the previous hunk.
110: If that is not the correct place,
111: .I patch
112: will scan both forwards and backwards for a set of lines matching the context
113: given in the hunk.
114: All lines of the context must match.
115: If
116: .I patch
117: cannot find a place to install that hunk of the patch, it will put the
118: hunk out to a reject file, which normally is the name of the output file
119: plus \*(L".rej\*(R".
120: (Note that the rejected hunk will come out in context diff form whether the
121: input patch was a context diff or a normal diff.
122: If the input was a normal diff, many of the contexts will simply be null.)
123: .PP
124: If no original file is specified on the command line,
125: .I patch
126: will try to figure out from the leading garbage what the name of the file
127: to edit is.
128: In the header of a context diff, the filename is found from lines beginning
129: with \*(L"***\*(R" or \*(L"---\*(R", with the shortest name of an existing
130: file winning.
131: Only context diffs have lines like that, but if there is an \*(L"Index:\*(R"
132: line in the leading garbage,
133: .I patch
134: will try to use the filename from that line.
135: The context diff header takes precedence over an Index line.
136: If no filename can be intuited from the leading garbage, you will be asked
137: for the name of the file to patch.
138: .PP
139: (If the original file cannot be found, but a suitable SCCS or RCS file is
140: handy,
141: .I patch
142: will attempt to get or check out the file.)
143: .PP
144: Additionally, if the leading garbage contains a \*(L"Prereq: \*(R" line,
145: .I patch
146: will take the first word from the prerequisites line (normally a version
147: number) and check the input file to see if that word can be found.
148: If not,
149: .I patch
150: will ask for confirmation before proceeding.
151: .PP
152: The upshot of all this is that you should be able to say, while in a news
153: interface, the following:
154: .Sp
155: | patch -d /usr/src/local/blurfl
156: .Sp
157: and patch a file in the blurfl directory directly from the article containing
158: the patch.
159: .PP
160: If the patch file contains more than one patch,
161: .I patch
162: will try to apply each of them as if they came from separate patch files.
163: This means, among other things, that it is assumed that separate patches
164: will apply to separate files, and that the garbage before each patch will
165: be examined for interesting things such as filenames and revision level, as
166: mentioned previously.
167: You can give switches (and another original file name) for the second and
168: subsequent patches by separating the corresponding argument lists
169: by a \*(L'+\*(R'.
170: The argument list for a second or subsequent patch may not specify a new
171: patch file, however.
172: .PP
173: .I Patch
174: recognizes the following switches:
175: .TP 5
176: .B \-b
177: causes the next argument to be interpreted as the backup extension, to be
178: used in place of \*(L".orig\*(R".
179: .TP 5
180: .B \-c
181: forces
182: .I patch
183: to interpret the patch file as a context diff.
184: .TP 5
185: .B \-d
186: causes
187: .I patch
188: to interpret the next argument as a directory, and cd to it before doing
189: anything else.
190: .TP 5
191: .B \-D
192: causes
193: .I patch
194: to use the "#ifdef...#endif" construct to mark changes.
195: The argument following will be used as the differentiating symbol.
196: Note that, unlike the C compiler, there must be a space between the
197: .B \-D
198: and the argument.
199: .TP 5
200: .B \-e
201: forces
202: .I patch
203: to interpret the patch file as an ed script.
204: .TP 5
205: .B \-l
206: causes the pattern matching to be done loosely, in case the tabs and
207: spaces have been munged in you input file.
208: Any sequence of whitespace in the pattern line will match any sequence
209: in the input file.
210: Normal characters must still match exactly.
211: Each line of the context must still match a line in the input file.
212: .TP 5
213: .B \-n
214: forces
215: .I patch
216: to interpret the patch file as a normal diff.
217: .TP 5
218: .B \-o
219: causes the next argument to be interpreted as the output file name.
220: .TP 5
221: .B \-p
222: causes leading pathnames to be kept.
223: If the diff is of the file \*(lqb/a.c\*(rq, patch will look for \*(lqa.c\*(rq
224: in the \*(lqb\*(rq directory, instead of the current directory.
225: This probably won't work if the diff has rooted pathnames.
226: .TP 5
227: .B \-r
228: causes the next argument to be interpreted as the reject file name.
229: .TP 5
230: .B \-R
231: tells
232: .I patch
233: that this patch was created with the old and new files swapped.
234: (Yes, I'm afraid that does happen occasionally, human nature being what it
235: is.)
236: .I Patch
237: will attempt to swap each hunk around before applying it.
238: Rejects will come out in the swapped format.
239: The
240: .B \-R
241: switch will not work with ed diff scripts because there is too little
242: information to reconstruct the reverse operation.
243: .Sp
244: If the first hunk of a patch fails,
245: .I patch
246: will reverse the hunk to see if it can be applied that way.
247: If it can, the
248: .B \-R
249: switch will be set automatically.
250: If it can't, the patch will continue to be applied normally.
251: (Note: this method cannot detect a reversed patch if it is a normal diff
252: and if the first command is an append (i.e. it should have been a delete)
253: since appends always succeed.
254: Luckily, most patches add lines rather than delete them, so most reversed
255: normal diffs will begin with a delete, which will fail, triggering the
256: heuristic.)
257: .TP 5
258: .B \-s
259: makes
260: .I patch
261: do its work silently, unless an error occurs.
262: .TP 5
263: .B \-x<number>
264: sets internal debugging flags, and is of interest only to
265: .I patch
266: patchers.
267: .SH ENVIRONMENT
268: No environment variables are used by
269: .IR patch .
270: .SH FILES
271: /tmp/patch*
272: .SH SEE ALSO
273: diff(1)
274: .SH DIAGNOSTICS
275: Too many to list here, but generally indicative that
276: .I patch
277: couldn't parse your patch file.
278: .PP
279: The message \*(L"Hmm...\*(R" indicates that there is unprocessed text in
280: the patch file and that
281: .I patch
282: is attempting to intuit whether there is a patch in that text and, if so,
283: what kind of patch it is.
284: .SH CAVEATS
285: .I Patch
286: cannot tell if the line numbers are off in an ed script, and can only detect
287: bad line numbers in a normal diff when it finds a \*(L"change\*(R" command.
288: Until a suitable interactive interface is added, you should probably do
289: a context diff in these cases to see if the changes made sense.
290: Of course, compiling without errors is a pretty good indication that it
291: worked, but not always.
292: .PP
293: .I Patch
294: usually produces the correct results, even when it has to do a lot of
295: guessing.
296: However, the results are guaranteed to be correct only when the patch is
297: applied to exactly the same version of the file that the patch was
298: generated from.
299: .SH BUGS
300: Could be smarter about partial matches, excessively \&deviant offsets and
301: swapped code, but that would take an extra pass.
302: .PP
303: If code has been duplicated (for instance with #ifdef OLDCODE ... #else ...
304: #endif),
305: .I patch
306: is incapable of patching both versions, and, if it works at all, will likely
307: patch the wrong one, and tell you it succeeded to boot.
308: .PP
309: If you apply a patch you've already applied,
310: .I patch
311: will think it is a reversed patch, and un-apply the patch.
312: This could be construed as a feature.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.