patch.1 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064
  1. .\" patch man page
  2. .de Id
  3. .ds Dt \\$4
  4. ..
  5. .Id $Id: patch.man,v 1.23 1997/07/16 12:26:36 eggert Exp $
  6. .ds = \-\^\-
  7. .de Sp
  8. .if t .sp .3
  9. .if n .sp
  10. ..
  11. .TH PATCH 1 \*(Dt GNU
  12. .ta 3n
  13. .SH NAME
  14. patch \- apply a diff file to an original
  15. .SH SYNOPSIS
  16. .B patch
  17. .RI [ options ]
  18. .RI [ originalfile
  19. .RI [ patchfile ]]
  20. .Sp
  21. but usually just
  22. .Sp
  23. .BI "patch \-p" "num"
  24. .BI < patchfile
  25. .SH DESCRIPTION
  26. .B patch
  27. takes a patch file
  28. .I patchfile
  29. containing a difference listing produced by the
  30. .B diff
  31. program and applies those differences to one or more original files,
  32. producing patched versions.
  33. Normally the patched versions are put in place of the originals.
  34. Backups can be made; see the
  35. .B \-b
  36. or
  37. .B \*=backup
  38. option.
  39. The names of the files to be patched are usually taken from the patch file,
  40. but if there's just one file to be patched it can specified on the
  41. command line as
  42. .IR originalfile .
  43. .PP
  44. Upon startup, patch attempts to determine the type of the diff listing,
  45. unless overruled by a
  46. \fB\-c\fP (\fB\*=context\fP),
  47. \fB\-e\fP (\fB\*=ed\fP),
  48. \fB\-n\fP (\fB\*=normal\fP),
  49. or
  50. \fB\-u\fP (\fB\*=unified\fP)
  51. option.
  52. Context diffs (old-style, new-style, and unified) and
  53. normal diffs are applied by the
  54. .B patch
  55. program itself, while
  56. .B ed
  57. diffs are simply fed to the
  58. .BR ed (1)
  59. editor via a pipe.
  60. .PP
  61. .B patch
  62. tries to skip any leading garbage, apply the diff,
  63. and then skip any trailing garbage.
  64. Thus you could feed an article or message containing a
  65. diff listing to
  66. .BR patch ,
  67. and it should work.
  68. If the entire diff is indented by a consistent amount,
  69. or if a context diff is encapsulated one or more times by prepending
  70. "\fB\- \fP" to lines starting with "\fB\-\fP" as specified by Internet RFC 934,
  71. this is taken into account.
  72. .PP
  73. With context diffs, and to a lesser extent with normal diffs,
  74. .B patch
  75. can detect when the line numbers mentioned in the patch are incorrect,
  76. and attempts to find the correct place to apply each hunk of the patch.
  77. As a first guess, it takes the line number mentioned for the hunk, plus or
  78. minus any offset used in applying the previous hunk.
  79. If that is not the correct place,
  80. .B patch
  81. scans both forwards and backwards for a set of lines matching the context
  82. given in the hunk.
  83. First
  84. .B patch
  85. looks for a place where all lines of the context match.
  86. If no such place is found, and it's a context diff, and the maximum fuzz factor
  87. is set to 1 or more, then another scan takes place ignoring the first and last
  88. line of context.
  89. If that fails, and the maximum fuzz factor is set to 2 or more,
  90. the first two and last two lines of context are ignored,
  91. and another scan is made.
  92. (The default maximum fuzz factor is 2.)
  93. If
  94. .B patch
  95. cannot find a place to install that hunk of the patch, it puts the
  96. hunk out to a reject file, which normally is the name of the output file
  97. plus a
  98. .B \&.rej
  99. suffix, or
  100. .B #
  101. if
  102. .B \&.rej
  103. would generate a file name that is too long
  104. (if even appending the single character
  105. .B #
  106. makes the file name too long, then
  107. .B #
  108. replaces the file name's last character).
  109. (The rejected hunk comes out in ordinary context diff form regardless of
  110. the input patch's form.
  111. If the input was a normal diff, many of the contexts are simply null.)
  112. The line numbers on the hunks in the reject file may be different than
  113. in the patch file: they reflect the approximate location patch thinks the
  114. failed hunks belong in the new file rather than the old one.
  115. .PP
  116. As each hunk is completed, you are told if the hunk
  117. failed, and if so which line (in the new file)
  118. .B patch
  119. thought the hunk should go on.
  120. If the hunk is installed at a different line
  121. from the line number specified in the diff you
  122. are told the offset.
  123. A single large offset
  124. .I may
  125. indicate that a hunk was installed in the
  126. wrong place.
  127. You are also told if a fuzz factor was used to make the match, in which
  128. case you should also be slightly suspicious.
  129. If the
  130. .B \*=verbose
  131. option is given, you are also told about hunks that match exactly.
  132. .PP
  133. If no original file
  134. .I origfile
  135. is specified on the command line,
  136. .B patch
  137. tries to figure out from the leading garbage what the name of the file
  138. to edit is, using the following rules.
  139. .TP 3
  140. .B " \(bu"
  141. If the header is that of a context diff,
  142. .B patch
  143. takes the old and new file names in the header.
  144. Any
  145. .B /dev/null
  146. names are ignored.
  147. .TP
  148. .B " \(bu"
  149. If there is an
  150. .B Index:\&
  151. line in the leading garbage
  152. and if either the old and new names are both absent or the
  153. .B POSIXLY_CORRECT
  154. environment variable is set,
  155. .B patch
  156. takes the name in the
  157. .B Index:\&
  158. line.
  159. .TP
  160. .B " \(bu"
  161. For the purpose of the following rules,
  162. the names are considered to be in the order (old, new, index),
  163. regardless of the order that they appear in the header.
  164. .TP
  165. .B " \(bu"
  166. If some of the named files exist,
  167. .B patch
  168. uses the first name if the
  169. .B POSIXLY_CORRECT
  170. environment variable is set, and the best name otherwise.
  171. .TP
  172. .B " \(bu"
  173. If
  174. .B patch
  175. is not ignoring \s-1RCS\s0 and \s-1SCCS\s0 (see the
  176. .BI "\-g\ " num
  177. or
  178. .BI \*=get= num
  179. option), and no named files exist
  180. but an \s-1RCS\s0 or \s-1SCCS\s0 master is found,
  181. .B patch
  182. uses the first named file with an \s-1RCS\s0 or \s-1SCCS\s0 master.
  183. .TP
  184. .B " \(bu"
  185. If no named files exist, no \s-1RCS\s0 or \s-1SCCS\s0 master was found,
  186. some names are given,
  187. .B POSIXLY_CORRECT
  188. is not set, and the patch appears to create a file,
  189. .B patch
  190. uses the best name requiring the creation of the fewest directories.
  191. .TP
  192. .B " \(bu"
  193. If no file name results from the above heuristics, you are asked
  194. for the name of the file to patch.
  195. .LP
  196. To determine the
  197. .I best
  198. of a nonempty list of file names,
  199. .B patch
  200. first takes all the names with the fewest path name components;
  201. of those, it then takes all the names with the shortest basename;
  202. of those, it then takes all the shortest names;
  203. finally, it takes the first remaining name.
  204. .PP
  205. Additionally, if the leading garbage contains a
  206. .B Prereq:\&
  207. line,
  208. .B patch
  209. takes the first word from the prerequisites line (normally a version
  210. number) and checks the original file to see if that word can be found.
  211. If not,
  212. .B patch
  213. asks for confirmation before proceeding.
  214. .PP
  215. The upshot of all this is that you should be able to say, while in a news
  216. interface, something like the following:
  217. .Sp
  218. \fB| patch \-d /usr/src/local/blurfl\fP
  219. .Sp
  220. and patch a file in the
  221. .B blurfl
  222. directory directly from the article containing
  223. the patch.
  224. .PP
  225. If the patch file contains more than one patch,
  226. .B patch
  227. tries to apply each of them as if they came from separate patch files.
  228. This means, among other things, that it is assumed that the name of the file
  229. to patch must be determined for each diff listing,
  230. and that the garbage before each diff listing
  231. contains interesting things such as file names and revision level, as
  232. mentioned previously.
  233. .SH OPTIONS
  234. .TP 3
  235. \fB\-b\fP or \fB\*=backup\fP
  236. Make backup files.
  237. That is, when patching a file,
  238. rename or copy the original instead of removing it.
  239. When backing up a file that does not exist,
  240. an empty, unreadable backup file is created
  241. as a placeholder to represent the nonexistent file.
  242. See the
  243. .B \-V
  244. or
  245. .B \*=version\-control
  246. option for details about how backup file names are determined.
  247. .TP
  248. .B \*=backup\-if\-mismatch
  249. Back up a file if the patch does not match the file exactly
  250. and if backups are not otherwise requested.
  251. This is the default unless the
  252. .B POSIXLY_CORRECT
  253. environment variable is set.
  254. .TP
  255. .B \*=no\-backup\-if\-mismatch
  256. Do not back up a file if the patch does not match the file exactly
  257. and if backups are not otherwise requested.
  258. This is the default if the
  259. .B POSIXLY_CORRECT
  260. environment variable is set.
  261. .TP
  262. \fB\-B\fP \fIpref\fP or \fB\*=prefix=\fP\fIpref\fP
  263. Prefix
  264. .I pref
  265. to a file name when generating its simple backup file name.
  266. For example, with
  267. .B "\-B\ /junk/"
  268. the simple backup file name for
  269. .B src/patch/util.c
  270. is
  271. .BR /junk/src/patch/util.c .
  272. .TP
  273. \fB\*=binary\fP
  274. Read and write all files in binary mode,
  275. except for standard output and
  276. .BR /dev/tty .
  277. This option has no effect on \s-1POSIX\s0-compliant systems.
  278. On systems like \s-1DOS\s0 where this option makes a difference,
  279. the patch should be generated by
  280. .BR "diff\ \-a\ \*=binary" .
  281. .TP
  282. \fB\-c\fP or \fB\*=context\fP
  283. Interpret the patch file as a ordinary context diff.
  284. .TP
  285. \fB\-d\fP \fIdir\fP or \fB\*=directory=\fP\fIdir\fP
  286. Change to the directory
  287. .I dir
  288. immediately, before doing
  289. anything else.
  290. .TP
  291. \fB\-D\fP \fIdefine\fP or \fB\*=ifdef=\fP\fIdefine\fP
  292. Use the
  293. .BR #ifdef " .\|.\|. " #endif
  294. construct to mark changes, with
  295. .I define
  296. as the differentiating symbol.
  297. .TP
  298. .B "\*=dry\-run"
  299. Print the results of applying the patches without actually changing any files.
  300. .TP
  301. \fB\-e\fP or \fB\*=ed\fP
  302. Interpret the patch file as an
  303. .B ed
  304. script.
  305. .TP
  306. \fB\-E\fP or \fB\*=remove\-empty\-files\fP
  307. Remove output files that are empty after the patches have been applied.
  308. Normally this option is unnecessary, since
  309. .B patch
  310. can examine the time stamps on the header to determine whether a file
  311. should exist after patching.
  312. However, if the input is not a context diff or if the
  313. .B POSIXLY_CORRECT
  314. environment variable is set,
  315. .B patch
  316. does not remove empty patched files unless this option is given.
  317. When
  318. .B patch
  319. removes a file, it also attempts to remove any empty ancestor directories.
  320. .TP
  321. \fB\-f\fP or \fB\*=force\fP
  322. Assume that the user knows exactly what he or she is doing, and do not
  323. ask any questions. Skip patches whose headers
  324. do not say which file is to be patched; patch files even though they have the
  325. wrong version for the
  326. .B Prereq:\&
  327. line in the patch; and assume that
  328. patches are not reversed even if they look like they are.
  329. This option does not suppress commentary; use
  330. .B \-s
  331. for that.
  332. .TP
  333. \fB\-F\fP \fInum\fP or \fB\*=fuzz=\fP\fInum\fP
  334. Set the maximum fuzz factor.
  335. This option only applies to diffs that have context, and causes
  336. .B patch
  337. to ignore up to that many lines in looking for places to install a hunk.
  338. Note that a larger fuzz factor increases the odds of a faulty patch.
  339. The default fuzz factor is 2, and it may not be set to more than
  340. the number of lines of context in the context diff, ordinarily 3.
  341. .TP
  342. \fB\-g\fP \fInum\fP or \fB\*=get=\fP\fInum\fP
  343. This option controls
  344. .BR patch 's
  345. actions when a file is under \s-1RCS\s0 or \s-1SCCS\s0 control,
  346. and does not exist or is read-only and matches the default version.
  347. If
  348. .I num
  349. is positive,
  350. .B patch
  351. gets (or checks out) the file from the revision control system; if zero,
  352. .B patch
  353. ignores \s-1RCS\s0 and \s-1SCCS\s0 and does not get the file; and if negative,
  354. .B patch
  355. asks the user whether to get the file.
  356. The default value of this option is given by the value of the
  357. .B PATCH_GET
  358. environment variable if it is set; if not, the default value is zero if
  359. .B POSIXLY_CORRECT
  360. is set, negative otherwise.
  361. .TP
  362. .B "\*=help"
  363. Print a summary of options and exit.
  364. .TP
  365. \fB\-i\fP \fIpatchfile\fP or \fB\*=input=\fP\fIpatchfile\fP
  366. Read the patch from
  367. .IR patchfile .
  368. If
  369. .I patchfile
  370. is
  371. .BR \- ,
  372. read from standard input, the default.
  373. .TP
  374. \fB\-l\fP or \fB\*=ignore\-whitespace\fP
  375. Match patterns loosely, in case tabs or spaces
  376. have been munged in your files.
  377. Any sequence of one or more blanks in the patch file matches any sequence
  378. in the original file, and sequences of blanks at the ends of lines are ignored.
  379. Normal characters must still match exactly.
  380. Each line of the context must still match a line in the original file.
  381. .TP
  382. \fB\-n\fP or \fB\*=normal\fP
  383. Interpret the patch file as a normal diff.
  384. .TP
  385. \fB\-N\fP or \fB\*=forward\fP
  386. Ignore patches that seem to be reversed or already applied.
  387. See also
  388. .BR \-R .
  389. .TP
  390. \fB\-o\fP \fIoutfile\fP or \fB\*=output=\fP\fIoutfile\fP
  391. Send output to
  392. .I outfile
  393. instead of patching files in place.
  394. .TP
  395. \fB\-p\fP\fInum\fP or \fB\*=strip\fP\fB=\fP\fInum\fP
  396. Strip the smallest prefix containing
  397. .I num
  398. leading slashes from each file name found in the patch file.
  399. A sequence of one or more adjacent slashes is counted as a single slash.
  400. This controls how file names found in the patch file are treated, in case
  401. you keep your files in a different directory than the person who sent
  402. out the patch.
  403. For example, supposing the file name in the patch file was
  404. .Sp
  405. \fB/u/howard/src/blurfl/blurfl.c\fP
  406. .Sp
  407. setting
  408. .B \-p0
  409. gives the entire file name unmodified,
  410. .B \-p1
  411. gives
  412. .Sp
  413. \fBu/howard/src/blurfl/blurfl.c\fP
  414. .Sp
  415. without the leading slash,
  416. .B \-p4
  417. gives
  418. .Sp
  419. \fBblurfl/blurfl.c\fP
  420. .Sp
  421. and not specifying
  422. .B \-p
  423. at all just gives you \fBblurfl.c\fP.
  424. Whatever you end up with is looked for either in the current directory,
  425. or the directory specified by the
  426. .B \-d
  427. option.
  428. .TP
  429. \fB\-r\fP \fIrejectfile\fP or \fB\*=reject\-file=\fP\fIrejectfile\fP
  430. Put rejects into
  431. .I rejectfile
  432. instead of the default
  433. .B \&.rej
  434. file.
  435. .TP
  436. \fB\-R\fP or \fB\*=reverse\fP
  437. Assume that this patch was created with the old and new files swapped.
  438. (Yes, I'm afraid that does happen occasionally, human nature being what it
  439. is.)
  440. .B patch
  441. attempts to swap each hunk around before applying it.
  442. Rejects come out in the swapped format.
  443. The
  444. .B \-R
  445. option does not work with
  446. .B ed
  447. diff scripts because there is too little
  448. information to reconstruct the reverse operation.
  449. .Sp
  450. If the first hunk of a patch fails,
  451. .B patch
  452. reverses the hunk to see if it can be applied that way.
  453. If it can, you are asked if you want to have the
  454. .B \-R
  455. option set.
  456. If it can't, the patch continues to be applied normally.
  457. (Note: this method cannot detect a reversed patch if it is a normal diff
  458. and if the first command is an append (i.e. it should have been a delete)
  459. since appends always succeed, due to the fact that a null context matches
  460. anywhere.
  461. Luckily, most patches add or change lines rather than delete them, so most
  462. reversed normal diffs begin with a delete, which fails, triggering
  463. the heuristic.)
  464. .TP
  465. \fB\-s\fP or \fB\*=silent\fP or \fB\*=quiet\fP
  466. Work silently, unless an error occurs.
  467. .TP
  468. \fB\-t\fP or \fB\*=batch\fP
  469. Suppress questions like
  470. .BR \-f ,
  471. but make some different assumptions:
  472. skip patches whose headers do not contain file names (the same as \fB\-f\fP);
  473. skip patches for which the file has the wrong version for the
  474. .B Prereq:\&
  475. line
  476. in the patch; and assume that patches are reversed if they look like
  477. they are.
  478. .TP
  479. \fB\-T\fP or \fB\*=set\-time\fP
  480. Set the modification and access times of patched files from time stamps
  481. given in context diff headers, assuming that the context diff headers
  482. use local time. This option is not recommended, because patches using
  483. local time cannot easily be used by people in other time zones, and
  484. because local time stamps are ambiguous when local clocks move backwards
  485. during daylight-saving time adjustments. Instead of using this option,
  486. generate patches with \s-1UTC\s0 and use the
  487. .B \-Z
  488. or
  489. .B \*=set\-utc
  490. option instead.
  491. .TP
  492. \fB\-u\fP or \fB\*=unified\fP
  493. Interpret the patch file as a unified context diff.
  494. .TP
  495. \fB\-v\fP or \fB\*=version\fP
  496. Print out
  497. .BR patch 's
  498. revision header and patch level, and exit.
  499. .TP
  500. \fB\-V\fP \fImethod\fP or \fB\*=version\-control=\fP\fImethod\fP
  501. Use
  502. .I method
  503. to determine
  504. backup file names. The method can also be given by the
  505. .B PATCH_VERSION_CONTROL
  506. (or, if that's not set, the
  507. .BR VERSION_CONTROL )
  508. environment variable, which is overridden by this option.
  509. The method does not affect whether backup files are made;
  510. it affects only the names of any backup files that are made.
  511. .Sp
  512. The value of
  513. .I method
  514. is like the \s-1GNU\s0
  515. Emacs `version-control' variable;
  516. .B patch
  517. also recognizes synonyms that
  518. are more descriptive. The valid values for
  519. .I method
  520. are (unique abbreviations are
  521. accepted):
  522. .RS
  523. .TP 3
  524. \fBexisting\fP or \fBnil\fP
  525. Make numbered backups of files that already have them,
  526. otherwise simple backups.
  527. This is the default.
  528. .TP
  529. \fBnumbered\fP or \fBt\fP
  530. Make numbered backups. The numbered backup file name for
  531. .I F
  532. is
  533. .IB F .~ N ~
  534. where
  535. .I N
  536. is the version number.
  537. .TP
  538. \fBsimple\fP or \fBnever\fP
  539. Make simple backups.
  540. The
  541. .B \-B
  542. or
  543. .BR \*=prefix ,
  544. .B \-Y
  545. or
  546. .BR \*=basename\-prefix ,
  547. and
  548. .B \-z
  549. or
  550. .BR \*=suffix
  551. options specify the simple backup file name.
  552. If none of these options are given, then a simple backup suffix is used;
  553. it is the value of the
  554. .B SIMPLE_BACKUP_SUFFIX
  555. environment variable if set, and is
  556. .B \&.orig
  557. otherwise.
  558. .PP
  559. With numbered or simple backups,
  560. if the backup file name is too long, the backup suffix
  561. .B ~
  562. is used instead; if even appending
  563. .B ~
  564. would make the name too long, then
  565. .B ~
  566. replaces the last character of the file name.
  567. .RE
  568. .TP
  569. \fB\*=verbose\fP
  570. Output extra information about the work being done.
  571. .TP
  572. \fB\-x\fP \fInum\fP or \fB\*=debug=\fP\fInum\fP
  573. Set internal debugging flags of interest only to
  574. .B patch
  575. patchers.
  576. .TP
  577. \fB\-Y\fP \fIpref\fP or \fB\*=basename\-prefix=\fP\fIpref\fP
  578. Prefix
  579. .I pref
  580. to the basename of a file name when generating its simple backup file name.
  581. For example, with
  582. .B "\-Y\ .del/"
  583. the simple backup file name for
  584. .B src/patch/util.c
  585. is
  586. .BR src/patch/.del/util.c .
  587. .TP
  588. \fB\-z\fP \fIsuffix\fP or \fB\*=suffix=\fP\fIsuffix\fP
  589. Use
  590. .I suffix
  591. as the simple backup suffix.
  592. For example, with
  593. .B "\-z\ -"
  594. the simple backup file name for
  595. .B src/patch/util.c
  596. is
  597. .BR src/patch/util.c- .
  598. The backup suffix may also be specified by the
  599. .B SIMPLE_BACKUP_SUFFIX
  600. environment variable, which is overridden by this option.
  601. .TP
  602. \fB\-Z\fP or \fB\*=set\-utc\fP
  603. Set the modification and access times of patched files from time stamps
  604. given in context diff headers, assuming that the context diff headers
  605. use Coordinated Universal Time (\s-1UTC\s0, often known as \s-1GMT\s0).
  606. Also see the
  607. .B \-T
  608. or
  609. .B \*=set\-time
  610. option.
  611. .Sp
  612. The
  613. .B \-Z
  614. or
  615. .B \*=set\-utc
  616. and
  617. .B \-T
  618. or
  619. .B \*=set\-time
  620. options normally refrain from setting a file's time if the file's original time
  621. does not match the time given in the patch header, or if its
  622. contents do not match the patch exactly. However, if the
  623. .B \-f
  624. or
  625. .B \*=force
  626. option is given, the file time is set regardless.
  627. .Sp
  628. Due to the limitations of
  629. .B diff
  630. output format, these options cannot update the times of files whose
  631. contents have not changed. Also, if you use these options, you should remove
  632. (e.g. with
  633. .BR "make\ clean" )
  634. all files that depend on the patched files, so that later invocations of
  635. .B make
  636. do not get confused by the patched files' times.
  637. .SH ENVIRONMENT
  638. .TP 3
  639. \fBPATCH_GET\fP
  640. This specifies whether
  641. .B patch
  642. gets missing or read-only files from \s-1RCS\s0 or \s-1SCCS\s0
  643. by default; see the
  644. .B \-g
  645. or
  646. .B \*=get
  647. option.
  648. .TP
  649. .B POSIXLY_CORRECT
  650. If set,
  651. .B patch
  652. conforms more strictly to the \s-1POSIX\s0 standard:
  653. it takes the first existing file from the list (old, new, index)
  654. when intuiting file names from diff headers,
  655. it does not remove files that are empty after patching,
  656. it does not ask whether to get files from \s-1RCS\s0 or \s-1SCCS\s0,
  657. it requires that all options precede the files in the command line,
  658. and it does not backup files when there is a mismatch.
  659. .TP
  660. .B SIMPLE_BACKUP_SUFFIX
  661. Extension to use for simple backup file names instead of
  662. .BR \&.orig .
  663. .TP
  664. \fBTMPDIR\fP, \fBTMP\fP, \fBTEMP\fP
  665. Directory to put temporary files in;
  666. .B patch
  667. uses the first environment variable in this list that is set.
  668. If none are set, the default is system-dependent;
  669. it is normally
  670. .B /tmp
  671. on Unix hosts.
  672. .TP
  673. \fBVERSION_CONTROL\fP or \fBPATCH_VERSION_CONTROL\fP
  674. Selects version control style; see the
  675. .B \-v
  676. or
  677. .B \*=version\-control
  678. option.
  679. .SH FILES
  680. .TP 3
  681. .IB $TMPDIR "/p\(**"
  682. temporary files
  683. .TP
  684. .B /dev/tty
  685. controlling terminal; used to get answers to questions asked of the user
  686. .SH "SEE ALSO"
  687. .BR diff (1),
  688. .BR ed (1)
  689. .Sp
  690. Marshall T. Rose and Einar A. Stefferud,
  691. Proposed Standard for Message Encapsulation,
  692. Internet RFC 934 <URL:ftp://ftp.isi.edu/in-notes/rfc934.txt> (1985-01).
  693. .SH "NOTES FOR PATCH SENDERS"
  694. There are several things you should bear in mind if you are going to
  695. be sending out patches.
  696. .PP
  697. Create your patch systematically.
  698. A good method is the command
  699. .BI "diff\ \-Naur\ " "old\ new"
  700. where
  701. .I old
  702. and
  703. .I new
  704. identify the old and new directories.
  705. The names
  706. .I old
  707. and
  708. .I new
  709. should not contain any slashes.
  710. The
  711. .B diff
  712. command's headers should have dates
  713. and times in Universal Time using traditional Unix format,
  714. so that patch recipients can use the
  715. .B \-Z
  716. or
  717. .B \*=set\-utc
  718. option.
  719. Here is an example command, using Bourne shell syntax:
  720. .Sp
  721. \fBLC_ALL=C TZ=UTC0 diff \-Naur gcc\-2.7 gcc\-2.8\fP
  722. .PP
  723. Tell your recipients how to apply the patch
  724. by telling them which directory to
  725. .B cd
  726. to, and which
  727. .B patch
  728. options to use. The option string
  729. .B "\-Np1"
  730. is recommended.
  731. Test your procedure by pretending to be a recipient and applying
  732. your patch to a copy of the original files.
  733. .PP
  734. You can save people a lot of grief by keeping a
  735. .B patchlevel.h
  736. file which is patched to increment the patch level
  737. as the first diff in the patch file you send out.
  738. If you put a
  739. .B Prereq:\&
  740. line in with the patch, it won't let them apply
  741. patches out of order without some warning.
  742. .PP
  743. You can create a file by sending out a diff that compares
  744. .B /dev/null
  745. or an empty file dated the Epoch (1970-01-01 00:00:00 \s-1UTC\s0)
  746. to the file you want to create.
  747. This only works if the file you want to create doesn't exist already in
  748. the target directory.
  749. Conversely, you can remove a file by sending out a context diff that compares
  750. the file to be deleted with an empty file dated the Epoch.
  751. The file will be removed unless the
  752. .B POSIXLY_CORRECT
  753. environment variable is set and the
  754. .B \-E
  755. or
  756. .B \*=remove\-empty\-files
  757. option is not given.
  758. An easy way to generate patches that create and remove files
  759. is to use \s-1GNU\s0
  760. .BR diff 's
  761. .B \-N
  762. or
  763. .B \*=new\-file
  764. option.
  765. .PP
  766. If the recipient is supposed to use the
  767. .BI \-p N
  768. option, do not send output that looks like this:
  769. .Sp
  770. .ft B
  771. .ne 3
  772. diff \-Naur v2.0.29/prog/README prog/README
  773. .br
  774. \-\^\-\^\- v2.0.29/prog/README Mon Mar 10 15:13:12 1997
  775. .br
  776. +\^+\^+ prog/README Mon Mar 17 14:58:22 1997
  777. .ft
  778. .Sp
  779. because the two file names have different numbers of slashes,
  780. and different versions of
  781. .B patch
  782. interpret the file names differently.
  783. To avoid confusion, send output that looks like this instead:
  784. .Sp
  785. .ft B
  786. .ne 3
  787. diff \-Naur v2.0.29/prog/README v2.0.30/prog/README
  788. .br
  789. \-\^\-\^\- v2.0.29/prog/README Mon Mar 10 15:13:12 1997
  790. .br
  791. +\^+\^+ v2.0.30/prog/README Mon Mar 17 14:58:22 1997
  792. .ft
  793. .Sp
  794. .PP
  795. Avoid sending patches that compare backup file names like
  796. .BR README.orig ,
  797. since this might confuse
  798. .B patch
  799. into patching a backup file instead of the real file.
  800. Instead, send patches that compare the same base file names
  801. in different directories, e.g.\&
  802. .B old/README
  803. and
  804. .BR new/README .
  805. .PP
  806. Take care not to send out reversed patches, since it makes people wonder
  807. whether they already applied the patch.
  808. .PP
  809. Try not to have your patch modify derived files
  810. (e.g. the file
  811. .B configure
  812. where there is a line
  813. .B "configure: configure.in"
  814. in your makefile), since the recipient should be
  815. able to regenerate the derived files anyway.
  816. If you must send diffs of derived files,
  817. generate the diffs using \s-1UTC\s0,
  818. have the recipients apply the patch with the
  819. .B \-Z
  820. or
  821. .B \*=set\-utc
  822. option, and have them remove any unpatched files that depend on patched files
  823. (e.g. with
  824. .BR "make\ clean" ).
  825. .PP
  826. While you may be able to get away with putting 582 diff listings into
  827. one file, it may be wiser to group related patches into separate files in
  828. case something goes haywire.
  829. .SH DIAGNOSTICS
  830. Diagnostics generally indicate that
  831. .B patch
  832. couldn't parse your patch file.
  833. .PP
  834. If the
  835. .B \*=verbose
  836. option is given, the message
  837. .B Hmm.\|.\|.\&
  838. indicates that there is unprocessed text in
  839. the patch file and that
  840. .B patch
  841. is attempting to intuit whether there is a patch in that text and, if so,
  842. what kind of patch it is.
  843. .PP
  844. .BR patch 's
  845. exit status is
  846. 0 if all hunks are applied successfully,
  847. 1 if some hunks cannot be applied,
  848. and 2 if there is more serious trouble.
  849. When applying a set of patches in a loop it behooves you to check this
  850. exit status so you don't apply a later patch to a partially patched file.
  851. .SH CAVEATS
  852. Context diffs cannot reliably represent the creation or deletion of
  853. empty files, empty directories, or special files such as symbolic links.
  854. Nor can they represent changes to file metadata like ownership, permissions,
  855. or whether one file is a hard link to another.
  856. If changes like these are also required, separate instructions
  857. (e.g. a shell script) to accomplish them should accompany the patch.
  858. .PP
  859. .B patch
  860. cannot tell if the line numbers are off in an
  861. .B ed
  862. script, and can detect
  863. bad line numbers in a normal diff only when it finds a change or deletion.
  864. A context diff using fuzz factor 3 may have the same problem.
  865. Until a suitable interactive interface is added, you should probably do
  866. a context diff in these cases to see if the changes made sense.
  867. Of course, compiling without errors is a pretty good indication that the patch
  868. worked, but not always.
  869. .PP
  870. .B patch
  871. usually produces the correct results, even when it has to do a lot of
  872. guessing.
  873. However, the results are guaranteed to be correct only when the patch is
  874. applied to exactly the same version of the file that the patch was
  875. generated from.
  876. .SH "COMPATIBILITY ISSUES"
  877. The \s-1POSIX\s0 standard specifies behavior that differs from
  878. .BR patch 's
  879. traditional behavior.
  880. You should be aware of these differences if you must interoperate with
  881. .B patch
  882. versions 2.1 and earlier, which are not \s-1POSIX\s0-compliant.
  883. .TP 3
  884. .B " \(bu"
  885. In traditional
  886. .BR patch ,
  887. the
  888. .B \-p
  889. option's operand was optional, and a bare
  890. .B \-p
  891. was equivalent to
  892. .BR \-p0.
  893. The
  894. .B \-p
  895. option now requires an operand, and
  896. .B "\-p\ 0"
  897. is now equivalent to
  898. .BR \-p0 .
  899. For maximum compatibility, use options like
  900. .B \-p0
  901. and
  902. .BR \-p1 .
  903. .Sp
  904. Also,
  905. traditional
  906. .B patch
  907. simply counted slashes when stripping path prefixes;
  908. .B patch
  909. now counts pathname components.
  910. That is, a sequence of one or more adjacent slashes
  911. now counts as a single slash.
  912. For maximum portability, avoid sending patches containing
  913. .B //
  914. in file names.
  915. .TP
  916. .B " \(bu"
  917. In traditional
  918. .BR patch ,
  919. backups were enabled by default.
  920. This behavior is now enabled with the
  921. .B \-b
  922. or
  923. .B \*=backup
  924. option.
  925. .Sp
  926. Conversely, in \s-1POSIX\s0
  927. .BR patch ,
  928. backups are never made, even when there is a mismatch.
  929. In \s-1GNU\s0
  930. .BR patch ,
  931. this behavior is enabled with the
  932. .B \*=no\-backup\-if\-mismatch
  933. option or by setting the
  934. .B POSIXLY_CORRECT
  935. environment variable.
  936. .Sp
  937. The
  938. .BI \-b "\ suffix"
  939. option
  940. of traditional
  941. .B patch
  942. is equivalent to the
  943. .BI "\-b\ \-z" "\ suffix"
  944. options of \s-1GNU\s0
  945. .BR patch .
  946. .TP
  947. .B " \(bu"
  948. Traditional
  949. .B patch
  950. used a complicated (and incompletely documented) method
  951. to intuit the name of the file to be patched from the patch header.
  952. This method was not \s-1POSIX\s0-compliant, and had a few gotchas.
  953. Now
  954. .B patch
  955. uses a different, equally complicated (but better documented) method
  956. that is optionally \s-1POSIX\s0-compliant; we hope it has
  957. fewer gotchas. The two methods are compatible if the
  958. file names in the context diff header and the
  959. .B Index:\&
  960. line are all identical after prefix-stripping.
  961. Your patch is normally compatible if each header's file names
  962. all contain the same number of slashes.
  963. .TP
  964. .B " \(bu"
  965. When traditional
  966. .B patch
  967. asked the user a question, it sent the question to standard error
  968. and looked for an answer from
  969. the first file in the following list that was a terminal:
  970. standard error, standard output,
  971. .BR /dev/tty ,
  972. and standard input.
  973. Now
  974. .B patch
  975. sends questions to standard output and gets answers from
  976. .BR /dev/tty .
  977. Defaults for some answers have been changed so that
  978. .B patch
  979. never goes into an infinite loop when using default answers.
  980. .TP
  981. .B " \(bu"
  982. Traditional
  983. .B patch
  984. exited with a status value that counted the number of bad hunks,
  985. or with status 1 if there was real trouble.
  986. Now
  987. .B patch
  988. exits with status 1 if some hunks failed,
  989. or with 2 if there was real trouble.
  990. .TP
  991. .B " \(bu"
  992. Limit yourself to the following options when sending instructions
  993. meant to be executed by anyone running \s-1GNU\s0
  994. .BR patch ,
  995. traditional
  996. .BR patch ,
  997. or a \s-1POSIX\s0-compliant
  998. .BR patch .
  999. Spaces are significant in the following list, and operands are required.
  1000. .Sp
  1001. .nf
  1002. .in +3
  1003. .ne 11
  1004. .B \-c
  1005. .BI \-d " dir"
  1006. .BI \-D " define"
  1007. .B \-e
  1008. .B \-l
  1009. .B \-n
  1010. .B \-N
  1011. .BI \-o " outfile"
  1012. .BI \-p num
  1013. .B \-R
  1014. .BI \-r " rejectfile"
  1015. .in
  1016. .fi
  1017. .SH BUGS
  1018. .B patch
  1019. could be smarter about partial matches, excessively deviant offsets and
  1020. swapped code, but that would take an extra pass.
  1021. .PP
  1022. If code has been duplicated (for instance with
  1023. \fB#ifdef OLDCODE\fP .\|.\|. \fB#else .\|.\|. #endif\fP),
  1024. .B patch
  1025. is incapable of patching both versions, and, if it works at all, will likely
  1026. patch the wrong one, and tell you that it succeeded to boot.
  1027. .PP
  1028. If you apply a patch you've already applied,
  1029. .B patch
  1030. thinks it is a reversed patch, and offers to un-apply the patch.
  1031. This could be construed as a feature.
  1032. .SH COPYING
  1033. Copyright
  1034. .if t \(co
  1035. 1984, 1985, 1986, 1988 Larry Wall.
  1036. .br
  1037. Copyright
  1038. .if t \(co
  1039. 1997 Free Software Foundation, Inc.
  1040. .PP
  1041. Permission is granted to make and distribute verbatim copies of
  1042. this manual provided the copyright notice and this permission notice
  1043. are preserved on all copies.
  1044. .PP
  1045. Permission is granted to copy and distribute modified versions of this
  1046. manual under the conditions for verbatim copying, provided that the
  1047. entire resulting derived work is distributed under the terms of a
  1048. permission notice identical to this one.
  1049. .PP
  1050. Permission is granted to copy and distribute translations of this
  1051. manual into another language, under the above conditions for modified
  1052. versions, except that this permission notice may be included in
  1053. translations approved by the copyright holders instead of in
  1054. the original English.
  1055. .SH AUTHORS
  1056. Larry Wall wrote the original version of
  1057. .BR patch .
  1058. Paul Eggert removed
  1059. .BR patch 's
  1060. arbitrary limits; added support for binary files,
  1061. setting file times, and deleting files;
  1062. and made it conform better to \s-1POSIX\s0.
  1063. Other contributors include Wayne Davison, who added unidiff support,
  1064. and David MacKenzie, who added configuration and backup support.