home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / TOP / USR / SRC / upatch.t.Z / upatch.t / patch.1 < prev    next >
Text File  |  1988-08-24  |  14KB  |  466 lines

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