xref: /freebsd/usr.bin/patch/patch.1 (revision b2c76c41be32f904179efed29c0ca04d53f3996c)
1e56ef7d3SXin LI.\"-
22dd076b8SGabor Kovesdan.\" Copyright 1986, Larry Wall
32dd076b8SGabor Kovesdan.\"
42dd076b8SGabor Kovesdan.\" Redistribution and use in source and binary forms, with or without
52dd076b8SGabor Kovesdan.\" modification, are permitted provided that the following condition
62dd076b8SGabor Kovesdan.\" is met:
72dd076b8SGabor Kovesdan.\"  1. Redistributions of source code must retain the above copyright
82dd076b8SGabor Kovesdan.\"     notice, this condition and the following disclaimer.
92dd076b8SGabor Kovesdan.\"
102dd076b8SGabor Kovesdan.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
112dd076b8SGabor Kovesdan.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
122dd076b8SGabor Kovesdan.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
132dd076b8SGabor Kovesdan.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
142dd076b8SGabor Kovesdan.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
152dd076b8SGabor Kovesdan.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
162dd076b8SGabor Kovesdan.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
172dd076b8SGabor Kovesdan.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
182dd076b8SGabor Kovesdan.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
192dd076b8SGabor Kovesdan.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
202dd076b8SGabor Kovesdan.\" SUCH DAMAGE.
212dd076b8SGabor Kovesdan.\"
229f00ccd3SPedro F. Giffuni.\" $OpenBSD: patch.1,v 1.27 2014/04/15 06:26:54 jmc Exp $
23*50dacbf6SKyle Evans.Dd November 3, 2019
242dd076b8SGabor Kovesdan.Dt PATCH 1
252dd076b8SGabor Kovesdan.Os
262dd076b8SGabor Kovesdan.Sh NAME
272dd076b8SGabor Kovesdan.Nm patch
282dd076b8SGabor Kovesdan.Nd apply a diff file to an original
292dd076b8SGabor Kovesdan.Sh SYNOPSIS
302dd076b8SGabor Kovesdan.Nm
312dd076b8SGabor Kovesdan.Bk -words
322dd076b8SGabor Kovesdan.Op Fl bCcEeflNnRstuv
332dd076b8SGabor Kovesdan.Op Fl B Ar backup-prefix
342dd076b8SGabor Kovesdan.Op Fl D Ar symbol
352dd076b8SGabor Kovesdan.Op Fl d Ar directory
362dd076b8SGabor Kovesdan.Op Fl F Ar max-fuzz
372dd076b8SGabor Kovesdan.Op Fl i Ar patchfile
382dd076b8SGabor Kovesdan.Op Fl o Ar out-file
392dd076b8SGabor Kovesdan.Op Fl p Ar strip-count
402dd076b8SGabor Kovesdan.Op Fl r Ar rej-name
41300ca9a8SConrad Meyer.Op Fl V Cm t | nil | never | none
422dd076b8SGabor Kovesdan.Op Fl x Ar number
432dd076b8SGabor Kovesdan.Op Fl z Ar backup-ext
442dd076b8SGabor Kovesdan.Op Fl Fl posix
452dd076b8SGabor Kovesdan.Op Ar origfile Op Ar patchfile
462dd076b8SGabor Kovesdan.Ek
472dd076b8SGabor Kovesdan.Nm
482dd076b8SGabor Kovesdan.Pf \*(Lt Ar patchfile
492dd076b8SGabor Kovesdan.Sh DESCRIPTION
502dd076b8SGabor Kovesdan.Nm
512dd076b8SGabor Kovesdanwill take a patch file containing any of the four forms of difference
522dd076b8SGabor Kovesdanlisting produced by the
532dd076b8SGabor Kovesdan.Xr diff 1
542dd076b8SGabor Kovesdanprogram and apply those differences to an original file,
552dd076b8SGabor Kovesdanproducing a patched version.
562dd076b8SGabor KovesdanIf
572dd076b8SGabor Kovesdan.Ar patchfile
582dd076b8SGabor Kovesdanis omitted, or is a hyphen, the patch will be read from the standard input.
592dd076b8SGabor Kovesdan.Pp
602dd076b8SGabor Kovesdan.Nm
61e56ef7d3SXin LIwill attempt to determine the type of the diff listing, unless overruled by a
622dd076b8SGabor Kovesdan.Fl c ,
632dd076b8SGabor Kovesdan.Fl e ,
642dd076b8SGabor Kovesdan.Fl n ,
652dd076b8SGabor Kovesdanor
662dd076b8SGabor Kovesdan.Fl u
672dd076b8SGabor Kovesdanoption.
682dd076b8SGabor KovesdanContext diffs (old-style, new-style, and unified) and
692dd076b8SGabor Kovesdannormal diffs are applied directly by the
702dd076b8SGabor Kovesdan.Nm
712dd076b8SGabor Kovesdanprogram itself, whereas ed diffs are simply fed to the
722dd076b8SGabor Kovesdan.Xr ed 1
732dd076b8SGabor Kovesdaneditor via a pipe.
742dd076b8SGabor Kovesdan.Pp
752dd076b8SGabor KovesdanIf the
762dd076b8SGabor Kovesdan.Ar patchfile
772dd076b8SGabor Kovesdancontains more than one patch,
782dd076b8SGabor Kovesdan.Nm
792dd076b8SGabor Kovesdanwill try to apply each of them as if they came from separate patch files.
802dd076b8SGabor KovesdanThis means, among other things, that it is assumed that the name of the file
812dd076b8SGabor Kovesdanto patch must be determined for each diff listing, and that the garbage before
822dd076b8SGabor Kovesdaneach diff listing will be examined for interesting things such as file names
832dd076b8SGabor Kovesdanand revision level (see the section on
842dd076b8SGabor Kovesdan.Sx Filename Determination
852dd076b8SGabor Kovesdanbelow).
862dd076b8SGabor Kovesdan.Pp
872dd076b8SGabor KovesdanThe options are as follows:
882dd076b8SGabor Kovesdan.Bl -tag -width Ds
892dd076b8SGabor Kovesdan.It Xo
902dd076b8SGabor Kovesdan.Fl B Ar backup-prefix ,
912dd076b8SGabor Kovesdan.Fl Fl prefix Ar backup-prefix
922dd076b8SGabor Kovesdan.Xc
932dd076b8SGabor KovesdanCauses the next argument to be interpreted as a prefix to the backup file
942dd076b8SGabor Kovesdanname.
952dd076b8SGabor KovesdanIf this argument is specified, any argument to
962dd076b8SGabor Kovesdan.Fl z
972dd076b8SGabor Kovesdanwill be ignored.
982dd076b8SGabor Kovesdan.It Fl b , Fl Fl backup
992dd076b8SGabor KovesdanSave a backup copy of the file before it is modified.
1002dd076b8SGabor KovesdanBy default the original file is saved with a backup extension of
1012dd076b8SGabor Kovesdan.Qq .orig
1022dd076b8SGabor Kovesdanunless the file already has a numbered backup, in which case a numbered
1032dd076b8SGabor Kovesdanbackup is made.
1042dd076b8SGabor KovesdanThis is equivalent to specifying
1052dd076b8SGabor Kovesdan.Qo Fl V Cm existing Qc .
1062dd076b8SGabor KovesdanThis option is currently the default, unless
1072dd076b8SGabor Kovesdan.Fl -posix
1082dd076b8SGabor Kovesdanis specified.
1095e64d66cSPedro F. Giffuni.It Fl C , Fl Fl check , Fl Fl dry-run
1102dd076b8SGabor KovesdanChecks that the patch would apply cleanly, but does not modify anything.
1112dd076b8SGabor Kovesdan.It Fl c , Fl Fl context
1122dd076b8SGabor KovesdanForces
1132dd076b8SGabor Kovesdan.Nm
1142dd076b8SGabor Kovesdanto interpret the patch file as a context diff.
1152dd076b8SGabor Kovesdan.It Xo
1162dd076b8SGabor Kovesdan.Fl D Ar symbol ,
1172dd076b8SGabor Kovesdan.Fl Fl ifdef Ar symbol
1182dd076b8SGabor Kovesdan.Xc
1192dd076b8SGabor KovesdanCauses
1202dd076b8SGabor Kovesdan.Nm
1212dd076b8SGabor Kovesdanto use the
1222dd076b8SGabor Kovesdan.Qq #ifdef...#endif
1232dd076b8SGabor Kovesdanconstruct to mark changes.
1242dd076b8SGabor KovesdanThe argument following will be used as the differentiating symbol.
1252dd076b8SGabor KovesdanNote that, unlike the C compiler, there must be a space between the
1262dd076b8SGabor Kovesdan.Fl D
1272dd076b8SGabor Kovesdanand the argument.
1282dd076b8SGabor Kovesdan.It Xo
1292dd076b8SGabor Kovesdan.Fl d Ar directory ,
1302dd076b8SGabor Kovesdan.Fl Fl directory Ar directory
1312dd076b8SGabor Kovesdan.Xc
1322dd076b8SGabor KovesdanCauses
1332dd076b8SGabor Kovesdan.Nm
1342dd076b8SGabor Kovesdanto interpret the next argument as a directory,
1352dd076b8SGabor Kovesdanand change the working directory to it before doing anything else.
1362dd076b8SGabor Kovesdan.It Fl E , Fl Fl remove-empty-files
1372dd076b8SGabor KovesdanCauses
1382dd076b8SGabor Kovesdan.Nm
1392dd076b8SGabor Kovesdanto remove output files that are empty after the patches have been applied.
1402dd076b8SGabor KovesdanThis option is useful when applying patches that create or remove files.
1412dd076b8SGabor Kovesdan.It Fl e , Fl Fl ed
1422dd076b8SGabor KovesdanForces
1432dd076b8SGabor Kovesdan.Nm
1442dd076b8SGabor Kovesdanto interpret the patch file as an
1452dd076b8SGabor Kovesdan.Xr ed 1
1462dd076b8SGabor Kovesdanscript.
1472dd076b8SGabor Kovesdan.It Xo
1482dd076b8SGabor Kovesdan.Fl F Ar max-fuzz ,
1492dd076b8SGabor Kovesdan.Fl Fl fuzz Ar max-fuzz
1502dd076b8SGabor Kovesdan.Xc
1512dd076b8SGabor KovesdanSets the maximum fuzz factor.
1522dd076b8SGabor KovesdanThis option only applies to context diffs, and causes
1532dd076b8SGabor Kovesdan.Nm
1542dd076b8SGabor Kovesdanto ignore up to that many lines in looking for places to install a hunk.
1552dd076b8SGabor KovesdanNote that a larger fuzz factor increases the odds of a faulty patch.
1562dd076b8SGabor KovesdanThe default fuzz factor is 2, and it may not be set to more than
1572dd076b8SGabor Kovesdanthe number of lines of context in the context diff, ordinarily 3.
1582dd076b8SGabor Kovesdan.It Fl f , Fl Fl force
1592dd076b8SGabor KovesdanForces
1602dd076b8SGabor Kovesdan.Nm
1612dd076b8SGabor Kovesdanto assume that the user knows exactly what he or she is doing, and to not
1622dd076b8SGabor Kovesdanask any questions.
1632dd076b8SGabor KovesdanIt assumes the following:
164b1edef17SJoel Dahlskip patches for which a file to patch cannot be found;
1652dd076b8SGabor Kovesdanpatch files even though they have the wrong version for the
1662dd076b8SGabor Kovesdan.Qq Prereq :
1672dd076b8SGabor Kovesdanline in the patch;
1682dd076b8SGabor Kovesdanand assume that patches are not reversed even if they look like they are.
1692dd076b8SGabor KovesdanThis option does not suppress commentary; use
1702dd076b8SGabor Kovesdan.Fl s
1712dd076b8SGabor Kovesdanfor that.
1722dd076b8SGabor Kovesdan.It Xo
1732dd076b8SGabor Kovesdan.Fl i Ar patchfile ,
1742dd076b8SGabor Kovesdan.Fl Fl input Ar patchfile
1752dd076b8SGabor Kovesdan.Xc
1762dd076b8SGabor KovesdanCauses the next argument to be interpreted as the input file name
177e678759cSXin LI(i.e., a patchfile).
1782dd076b8SGabor KovesdanThis option may be specified multiple times.
1792dd076b8SGabor Kovesdan.It Fl l , Fl Fl ignore-whitespace
1802dd076b8SGabor KovesdanCauses the pattern matching to be done loosely, in case the tabs and
1812dd076b8SGabor Kovesdanspaces have been munged in your input file.
1822dd076b8SGabor KovesdanAny sequence of whitespace in the pattern line will match any sequence
1832dd076b8SGabor Kovesdanin the input file.
1842dd076b8SGabor KovesdanNormal characters must still match exactly.
1852dd076b8SGabor KovesdanEach line of the context must still match a line in the input file.
1862dd076b8SGabor Kovesdan.It Fl N , Fl Fl forward
1872dd076b8SGabor KovesdanCauses
1882dd076b8SGabor Kovesdan.Nm
1892dd076b8SGabor Kovesdanto ignore patches that it thinks are reversed or already applied.
1902dd076b8SGabor KovesdanSee also
1912dd076b8SGabor Kovesdan.Fl R .
1922dd076b8SGabor Kovesdan.It Fl n , Fl Fl normal
1932dd076b8SGabor KovesdanForces
1942dd076b8SGabor Kovesdan.Nm
1952dd076b8SGabor Kovesdanto interpret the patch file as a normal diff.
1962dd076b8SGabor Kovesdan.It Xo
1972dd076b8SGabor Kovesdan.Fl o Ar out-file ,
1982dd076b8SGabor Kovesdan.Fl Fl output Ar out-file
1992dd076b8SGabor Kovesdan.Xc
2002dd076b8SGabor KovesdanCauses the next argument to be interpreted as the output file name.
2012dd076b8SGabor Kovesdan.It Xo
2022dd076b8SGabor Kovesdan.Fl p Ar strip-count ,
2032dd076b8SGabor Kovesdan.Fl Fl strip Ar strip-count
2042dd076b8SGabor Kovesdan.Xc
2052dd076b8SGabor KovesdanSets the pathname strip count,
2062dd076b8SGabor Kovesdanwhich controls how pathnames found in the patch file are treated,
2072dd076b8SGabor Kovesdanin case you keep your files in a different directory than the person who sent
2082dd076b8SGabor Kovesdanout the patch.
2092dd076b8SGabor KovesdanThe strip count specifies how many slashes are to be stripped from
2102dd076b8SGabor Kovesdanthe front of the pathname.
2112dd076b8SGabor Kovesdan(Any intervening directory names also go away.)
2122dd076b8SGabor KovesdanFor example, supposing the file name in the patch file was
2132dd076b8SGabor Kovesdan.Pa /u/howard/src/blurfl/blurfl.c :
2142dd076b8SGabor Kovesdan.Pp
2152dd076b8SGabor KovesdanSetting
2162dd076b8SGabor Kovesdan.Fl p Ns Ar 0
2172dd076b8SGabor Kovesdangives the entire pathname unmodified.
2182dd076b8SGabor Kovesdan.Pp
2192dd076b8SGabor Kovesdan.Fl p Ns Ar 1
2202dd076b8SGabor Kovesdangives
2212dd076b8SGabor Kovesdan.Pp
2222dd076b8SGabor Kovesdan.D1 Pa u/howard/src/blurfl/blurfl.c
2232dd076b8SGabor Kovesdan.Pp
2242dd076b8SGabor Kovesdanwithout the leading slash.
2252dd076b8SGabor Kovesdan.Pp
2262dd076b8SGabor Kovesdan.Fl p Ns Ar 4
2272dd076b8SGabor Kovesdangives
2282dd076b8SGabor Kovesdan.Pp
2292dd076b8SGabor Kovesdan.D1 Pa blurfl/blurfl.c
2302dd076b8SGabor Kovesdan.Pp
2312dd076b8SGabor KovesdanNot specifying
2322dd076b8SGabor Kovesdan.Fl p
2332dd076b8SGabor Kovesdanat all just gives you
2342dd076b8SGabor Kovesdan.Pa blurfl.c ,
2352dd076b8SGabor Kovesdanunless all of the directories in the leading path
2362dd076b8SGabor Kovesdan.Pq Pa u/howard/src/blurfl
2372dd076b8SGabor Kovesdanexist and that path is relative,
2382dd076b8SGabor Kovesdanin which case you get the entire pathname unmodified.
2392dd076b8SGabor KovesdanWhatever you end up with is looked for either in the current directory,
2402dd076b8SGabor Kovesdanor the directory specified by the
2412dd076b8SGabor Kovesdan.Fl d
2422dd076b8SGabor Kovesdanoption.
2432dd076b8SGabor Kovesdan.It Fl R , Fl Fl reverse
2442dd076b8SGabor KovesdanTells
2452dd076b8SGabor Kovesdan.Nm
2462dd076b8SGabor Kovesdanthat this patch was created with the old and new files swapped.
247e678759cSXin LI(Yes, I am afraid that does happen occasionally, human nature being what it
2482dd076b8SGabor Kovesdanis.)
2492dd076b8SGabor Kovesdan.Nm
2502dd076b8SGabor Kovesdanwill attempt to swap each hunk around before applying it.
2512dd076b8SGabor KovesdanRejects will come out in the swapped format.
2522dd076b8SGabor KovesdanThe
2532dd076b8SGabor Kovesdan.Fl R
2542dd076b8SGabor Kovesdanoption will not work with ed diff scripts because there is too little
2552dd076b8SGabor Kovesdaninformation to reconstruct the reverse operation.
2562dd076b8SGabor Kovesdan.Pp
2572dd076b8SGabor KovesdanIf the first hunk of a patch fails,
2582dd076b8SGabor Kovesdan.Nm
2592dd076b8SGabor Kovesdanwill reverse the hunk to see if it can be applied that way.
2602dd076b8SGabor KovesdanIf it can, you will be asked if you want to have the
2612dd076b8SGabor Kovesdan.Fl R
2622dd076b8SGabor Kovesdanoption set.
263b1edef17SJoel DahlIf it cannot, the patch will continue to be applied normally.
2642dd076b8SGabor Kovesdan(Note: this method cannot detect a reversed patch if it is a normal diff
265e678759cSXin LIand if the first command is an append (i.e., it should have been a delete)
2662dd076b8SGabor Kovesdansince appends always succeed, due to the fact that a null context will match
2672dd076b8SGabor Kovesdananywhere.
2682dd076b8SGabor KovesdanLuckily, most patches add or change lines rather than delete them, so most
2692dd076b8SGabor Kovesdanreversed normal diffs will begin with a delete, which will fail, triggering
2702dd076b8SGabor Kovesdanthe heuristic.)
2712dd076b8SGabor Kovesdan.It Xo
2722dd076b8SGabor Kovesdan.Fl r Ar rej-name ,
2732dd076b8SGabor Kovesdan.Fl Fl reject-file Ar rej-name
2742dd076b8SGabor Kovesdan.Xc
2752dd076b8SGabor KovesdanCauses the next argument to be interpreted as the reject file name.
2762dd076b8SGabor Kovesdan.It Xo
2772dd076b8SGabor Kovesdan.Fl s , Fl Fl quiet ,
2782dd076b8SGabor Kovesdan.Fl Fl silent
2792dd076b8SGabor Kovesdan.Xc
2802dd076b8SGabor KovesdanMakes
2812dd076b8SGabor Kovesdan.Nm
2822dd076b8SGabor Kovesdando its work silently, unless an error occurs.
2832dd076b8SGabor Kovesdan.It Fl t , Fl Fl batch
2842dd076b8SGabor KovesdanSimilar to
2852dd076b8SGabor Kovesdan.Fl f ,
2862dd076b8SGabor Kovesdanin that it suppresses questions, but makes some different assumptions:
287b1edef17SJoel Dahlskip patches for which a file to patch cannot be found (the same as
2882dd076b8SGabor Kovesdan.Fl f ) ;
2892dd076b8SGabor Kovesdanskip patches for which the file has the wrong version for the
2902dd076b8SGabor Kovesdan.Qq Prereq :
2912dd076b8SGabor Kovesdanline in the patch;
2922dd076b8SGabor Kovesdanand assume that patches are reversed if they look like they are.
2932dd076b8SGabor Kovesdan.It Fl u , Fl Fl unified
2942dd076b8SGabor KovesdanForces
2952dd076b8SGabor Kovesdan.Nm
2962dd076b8SGabor Kovesdanto interpret the patch file as a unified context diff (a unidiff).
2972dd076b8SGabor Kovesdan.It Xo
298300ca9a8SConrad Meyer.Fl V Cm t | nil | never | none ,
299300ca9a8SConrad Meyer.Fl Fl version-control Cm t | nil | never | none
3002dd076b8SGabor Kovesdan.Xc
3012dd076b8SGabor KovesdanCauses the next argument to be interpreted as a method for creating
3022dd076b8SGabor Kovesdanbackup file names.
3032dd076b8SGabor KovesdanThe type of backups made can also be given in the
3042dd076b8SGabor Kovesdan.Ev PATCH_VERSION_CONTROL
3052dd076b8SGabor Kovesdanor
3062dd076b8SGabor Kovesdan.Ev VERSION_CONTROL
3072dd076b8SGabor Kovesdanenvironment variables, which are overridden by this option.
3082dd076b8SGabor KovesdanThe
3092dd076b8SGabor Kovesdan.Fl B
3102dd076b8SGabor Kovesdanoption overrides this option, causing the prefix to always be used for
3112dd076b8SGabor Kovesdanmaking backup file names.
3122dd076b8SGabor KovesdanThe values of the
3132dd076b8SGabor Kovesdan.Ev PATCH_VERSION_CONTROL
3142dd076b8SGabor Kovesdanand
3152dd076b8SGabor Kovesdan.Ev VERSION_CONTROL
3162dd076b8SGabor Kovesdanenvironment variables and the argument to the
3172dd076b8SGabor Kovesdan.Fl V
3182dd076b8SGabor Kovesdanoption are like the GNU Emacs
3192dd076b8SGabor Kovesdan.Dq version-control
3202dd076b8SGabor Kovesdanvariable; they also recognize synonyms that are more descriptive.
3212dd076b8SGabor KovesdanThe valid values are (unique abbreviations are accepted):
3222dd076b8SGabor Kovesdan.Bl -tag -width Ds -offset indent
3232dd076b8SGabor Kovesdan.It Cm t , numbered
3242dd076b8SGabor KovesdanAlways make numbered backups.
3252dd076b8SGabor Kovesdan.It Cm nil , existing
3262dd076b8SGabor KovesdanMake numbered backups of files that already have them,
3272dd076b8SGabor Kovesdansimple backups of the others.
3282dd076b8SGabor Kovesdan.It Cm never , simple
3292dd076b8SGabor KovesdanAlways make simple backups.
330300ca9a8SConrad Meyer.It Cm none
331300ca9a8SConrad MeyerDo not make backups.
3322dd076b8SGabor Kovesdan.El
3332dd076b8SGabor Kovesdan.It Fl v , Fl Fl version
3342dd076b8SGabor KovesdanCauses
3352dd076b8SGabor Kovesdan.Nm
3362dd076b8SGabor Kovesdanto print out its revision header and patch level.
3372dd076b8SGabor Kovesdan.It Xo
3382dd076b8SGabor Kovesdan.Fl x Ar number ,
3392dd076b8SGabor Kovesdan.Fl Fl debug Ar number
3402dd076b8SGabor Kovesdan.Xc
3412dd076b8SGabor KovesdanSets internal debugging flags, and is of interest only to
3422dd076b8SGabor Kovesdan.Nm
3432dd076b8SGabor Kovesdanpatchers.
3442dd076b8SGabor Kovesdan.It Xo
3452dd076b8SGabor Kovesdan.Fl z Ar backup-ext ,
3462dd076b8SGabor Kovesdan.Fl Fl suffix Ar backup-ext
3472dd076b8SGabor Kovesdan.Xc
3482dd076b8SGabor KovesdanCauses the next argument to be interpreted as the backup extension, to be
3492dd076b8SGabor Kovesdanused in place of
3502dd076b8SGabor Kovesdan.Qq .orig .
3512dd076b8SGabor Kovesdan.It Fl Fl posix
3522dd076b8SGabor KovesdanEnables strict
353e56ef7d3SXin LI.St -p1003.1-2008
3542dd076b8SGabor Kovesdanconformance, specifically:
3552dd076b8SGabor Kovesdan.Bl -enum
3562dd076b8SGabor Kovesdan.It
3572dd076b8SGabor KovesdanBackup files are not created unless the
3582dd076b8SGabor Kovesdan.Fl b
3592dd076b8SGabor Kovesdanoption is specified.
3602dd076b8SGabor Kovesdan.It
3612dd076b8SGabor KovesdanIf unspecified, the file name used is the first of the old, new and
3622dd076b8SGabor Kovesdanindex files that exists.
3632dd076b8SGabor Kovesdan.El
3642dd076b8SGabor Kovesdan.El
3652dd076b8SGabor Kovesdan.Ss Patch Application
3662dd076b8SGabor Kovesdan.Nm
3672dd076b8SGabor Kovesdanwill try to skip any leading garbage, apply the diff,
3682dd076b8SGabor Kovesdanand then skip any trailing garbage.
3692dd076b8SGabor KovesdanThus you could feed an article or message containing a
3702dd076b8SGabor Kovesdandiff listing to
3712dd076b8SGabor Kovesdan.Nm ,
3722dd076b8SGabor Kovesdanand it should work.
3732dd076b8SGabor KovesdanIf the entire diff is indented by a consistent amount,
3742dd076b8SGabor Kovesdanthis will be taken into account.
3752dd076b8SGabor Kovesdan.Pp
3762dd076b8SGabor KovesdanWith context diffs, and to a lesser extent with normal diffs,
3772dd076b8SGabor Kovesdan.Nm
3782dd076b8SGabor Kovesdancan detect when the line numbers mentioned in the patch are incorrect,
3792dd076b8SGabor Kovesdanand will attempt to find the correct place to apply each hunk of the patch.
3802dd076b8SGabor KovesdanAs a first guess, it takes the line number mentioned for the hunk, plus or
3812dd076b8SGabor Kovesdanminus any offset used in applying the previous hunk.
3822dd076b8SGabor KovesdanIf that is not the correct place,
3832dd076b8SGabor Kovesdan.Nm
3842dd076b8SGabor Kovesdanwill scan both forwards and backwards for a set of lines matching the context
3852dd076b8SGabor Kovesdangiven in the hunk.
3862dd076b8SGabor KovesdanFirst
3872dd076b8SGabor Kovesdan.Nm
3882dd076b8SGabor Kovesdanlooks for a place where all lines of the context match.
389e678759cSXin LIIf no such place is found, and it is a context diff, and the maximum fuzz factor
3902dd076b8SGabor Kovesdanis set to 1 or more, then another scan takes place ignoring the first and last
3912dd076b8SGabor Kovesdanline of context.
3922dd076b8SGabor KovesdanIf that fails, and the maximum fuzz factor is set to 2 or more,
3932dd076b8SGabor Kovesdanthe first two and last two lines of context are ignored,
3942dd076b8SGabor Kovesdanand another scan is made.
3952dd076b8SGabor Kovesdan.Pq The default maximum fuzz factor is 2 .
3962dd076b8SGabor Kovesdan.Pp
3972dd076b8SGabor KovesdanIf
3982dd076b8SGabor Kovesdan.Nm
3992dd076b8SGabor Kovesdancannot find a place to install that hunk of the patch, it will put the hunk
4002dd076b8SGabor Kovesdanout to a reject file, which normally is the name of the output file plus
4012dd076b8SGabor Kovesdan.Qq .rej .
4022dd076b8SGabor Kovesdan(Note that the rejected hunk will come out in context diff form whether the
4032dd076b8SGabor Kovesdaninput patch was a context diff or a normal diff.
4042dd076b8SGabor KovesdanIf the input was a normal diff, many of the contexts will simply be null.)
4052dd076b8SGabor KovesdanThe line numbers on the hunks in the reject file may be different than
4062dd076b8SGabor Kovesdanin the patch file: they reflect the approximate location patch thinks the
4072dd076b8SGabor Kovesdanfailed hunks belong in the new file rather than the old one.
4082dd076b8SGabor Kovesdan.Pp
4092dd076b8SGabor KovesdanAs each hunk is completed, you will be told whether the hunk succeeded or
4102dd076b8SGabor Kovesdanfailed, and which line (in the new file)
4112dd076b8SGabor Kovesdan.Nm
4122dd076b8SGabor Kovesdanthought the hunk should go on.
4132dd076b8SGabor KovesdanIf this is different from the line number specified in the diff,
4142dd076b8SGabor Kovesdanyou will be told the offset.
4152dd076b8SGabor KovesdanA single large offset MAY be an indication that a hunk was installed in the
4162dd076b8SGabor Kovesdanwrong place.
4172dd076b8SGabor KovesdanYou will also be told if a fuzz factor was used to make the match, in which
4182dd076b8SGabor Kovesdancase you should also be slightly suspicious.
4192dd076b8SGabor Kovesdan.Ss Filename Determination
4202dd076b8SGabor KovesdanIf no original file is specified on the command line,
4212dd076b8SGabor Kovesdan.Nm
4222dd076b8SGabor Kovesdanwill try to figure out from the leading garbage what the name of the file
4232dd076b8SGabor Kovesdanto edit is.
4242dd076b8SGabor KovesdanWhen checking a prospective file name, pathname components are stripped
4252dd076b8SGabor Kovesdanas specified by the
4262dd076b8SGabor Kovesdan.Fl p
4272dd076b8SGabor Kovesdanoption and the file's existence and writability are checked relative
4282dd076b8SGabor Kovesdanto the current working directory (or the directory specified by the
4292dd076b8SGabor Kovesdan.Fl d
4302dd076b8SGabor Kovesdanoption).
4312dd076b8SGabor Kovesdan.Pp
4322dd076b8SGabor KovesdanIf the diff is a context or unified diff,
4332dd076b8SGabor Kovesdan.Nm
4342dd076b8SGabor Kovesdanis able to determine the old and new file names from the diff header.
4352dd076b8SGabor KovesdanFor context diffs, the
4362dd076b8SGabor Kovesdan.Dq old
4372dd076b8SGabor Kovesdanfile is specified in the line beginning with
4382dd076b8SGabor Kovesdan.Qq ***
4392dd076b8SGabor Kovesdanand the
4402dd076b8SGabor Kovesdan.Dq new
4412dd076b8SGabor Kovesdanfile is specified in the line beginning with
4422dd076b8SGabor Kovesdan.Qq --- .
4432dd076b8SGabor KovesdanFor a unified diff, the
4442dd076b8SGabor Kovesdan.Dq old
4452dd076b8SGabor Kovesdanfile is specified in the line beginning with
4462dd076b8SGabor Kovesdan.Qq ---
4472dd076b8SGabor Kovesdanand the
4482dd076b8SGabor Kovesdan.Dq new
4492dd076b8SGabor Kovesdanfile is specified in the line beginning with
4502dd076b8SGabor Kovesdan.Qq +++ .
4512dd076b8SGabor KovesdanIf there is an
4522dd076b8SGabor Kovesdan.Qq Index :
4532dd076b8SGabor Kovesdanline in the leading garbage (regardless of the diff type),
4542dd076b8SGabor Kovesdan.Nm
4552dd076b8SGabor Kovesdanwill use the file name from that line as the
4562dd076b8SGabor Kovesdan.Dq index
4572dd076b8SGabor Kovesdanfile.
4582dd076b8SGabor Kovesdan.Pp
4592dd076b8SGabor Kovesdan.Nm
4602dd076b8SGabor Kovesdanwill choose the file name by performing the following steps, with the first
4612dd076b8SGabor Kovesdanmatch used:
4622dd076b8SGabor Kovesdan.Bl -enum
4632dd076b8SGabor Kovesdan.It
4642dd076b8SGabor KovesdanIf
4652dd076b8SGabor Kovesdan.Nm
4662dd076b8SGabor Kovesdanis operating in strict
467e56ef7d3SXin LI.St -p1003.1-2008
4682dd076b8SGabor Kovesdanmode, the first of the
4692dd076b8SGabor Kovesdan.Dq old ,
4702dd076b8SGabor Kovesdan.Dq new
4712dd076b8SGabor Kovesdanand
4722dd076b8SGabor Kovesdan.Dq index
4732dd076b8SGabor Kovesdanfile names that exist is used.
4742dd076b8SGabor KovesdanOtherwise,
4752dd076b8SGabor Kovesdan.Nm
4762dd076b8SGabor Kovesdanwill examine either the
4772dd076b8SGabor Kovesdan.Dq old
4782dd076b8SGabor Kovesdanand
4792dd076b8SGabor Kovesdan.Dq new
4802dd076b8SGabor Kovesdanfile names or, for a non-context diff, the
4812dd076b8SGabor Kovesdan.Dq index
4822dd076b8SGabor Kovesdanfile name, and choose the file name with the fewest path components,
4832dd076b8SGabor Kovesdanthe shortest basename, and the shortest total file name length (in that order).
4842dd076b8SGabor Kovesdan.It
4852dd076b8SGabor KovesdanIf no suitable file was found to patch, the patch file is a context or
4862dd076b8SGabor Kovesdanunified diff, and the old file was zero length, the new file name is
4872dd076b8SGabor Kovesdancreated and used.
4882dd076b8SGabor Kovesdan.It
4892dd076b8SGabor KovesdanIf the file name still cannot be determined,
4902dd076b8SGabor Kovesdan.Nm
4912dd076b8SGabor Kovesdanwill prompt the user for the file name to use.
4922dd076b8SGabor Kovesdan.El
4932dd076b8SGabor Kovesdan.Pp
4942dd076b8SGabor KovesdanAdditionally, if the leading garbage contains a
4952dd076b8SGabor Kovesdan.Qq Prereq:\ \&
4962dd076b8SGabor Kovesdanline,
4972dd076b8SGabor Kovesdan.Nm
4982dd076b8SGabor Kovesdanwill take the first word from the prerequisites line (normally a version
4992dd076b8SGabor Kovesdannumber) and check the input file to see if that word can be found.
5002dd076b8SGabor KovesdanIf not,
5012dd076b8SGabor Kovesdan.Nm
5022dd076b8SGabor Kovesdanwill ask for confirmation before proceeding.
5032dd076b8SGabor Kovesdan.Pp
5042dd076b8SGabor KovesdanThe upshot of all this is that you should be able to say, while in a news
5052dd076b8SGabor Kovesdaninterface, the following:
5062dd076b8SGabor Kovesdan.Pp
5072dd076b8SGabor Kovesdan.Dl | patch -d /usr/src/local/blurfl
5082dd076b8SGabor Kovesdan.Pp
5092dd076b8SGabor Kovesdanand patch a file in the blurfl directory directly from the article containing
5102dd076b8SGabor Kovesdanthe patch.
5112dd076b8SGabor Kovesdan.Ss Backup Files
5122dd076b8SGabor KovesdanBy default, the patched version is put in place of the original, with
5132dd076b8SGabor Kovesdanthe original file backed up to the same name with the extension
5142dd076b8SGabor Kovesdan.Qq .orig ,
5152dd076b8SGabor Kovesdanor as specified by the
5162dd076b8SGabor Kovesdan.Fl B ,
5172dd076b8SGabor Kovesdan.Fl V ,
5182dd076b8SGabor Kovesdanor
5192dd076b8SGabor Kovesdan.Fl z
5202dd076b8SGabor Kovesdanoptions.
5212dd076b8SGabor KovesdanThe extension used for making backup files may also be specified in the
5222dd076b8SGabor Kovesdan.Ev SIMPLE_BACKUP_SUFFIX
5232dd076b8SGabor Kovesdanenvironment variable, which is overridden by the options above.
5242dd076b8SGabor Kovesdan.Pp
5252dd076b8SGabor KovesdanIf the backup file is a symbolic or hard link to the original file,
5262dd076b8SGabor Kovesdan.Nm
5272dd076b8SGabor Kovesdancreates a new backup file name by changing the first lowercase letter
5282dd076b8SGabor Kovesdanin the last component of the file's name into uppercase.
5292dd076b8SGabor KovesdanIf there are no more lowercase letters in the name,
5302dd076b8SGabor Kovesdanit removes the first character from the name.
5312dd076b8SGabor KovesdanIt repeats this process until it comes up with a
5322dd076b8SGabor Kovesdanbackup file that does not already exist or is not linked to the original file.
5332dd076b8SGabor Kovesdan.Pp
5342dd076b8SGabor KovesdanYou may also specify where you want the output to go with the
5352dd076b8SGabor Kovesdan.Fl o
5362dd076b8SGabor Kovesdanoption; if that file already exists, it is backed up first.
5372dd076b8SGabor Kovesdan.Ss Notes For Patch Senders
5382dd076b8SGabor KovesdanThere are several things you should bear in mind if you are going to
5392dd076b8SGabor Kovesdanbe sending out patches:
5402dd076b8SGabor Kovesdan.Pp
5412dd076b8SGabor KovesdanFirst, you can save people a lot of grief by keeping a
5422dd076b8SGabor Kovesdan.Pa patchlevel.h
5432dd076b8SGabor Kovesdanfile which is patched to increment the patch level as the first diff in the
5442dd076b8SGabor Kovesdanpatch file you send out.
5452dd076b8SGabor KovesdanIf you put a
5462dd076b8SGabor Kovesdan.Qq Prereq :
547b1edef17SJoel Dahlline in with the patch, it will not let them apply
5482dd076b8SGabor Kovesdanpatches out of order without some warning.
5492dd076b8SGabor Kovesdan.Pp
550b1edef17SJoel DahlSecond, make sure you have specified the file names right, either in a
5512dd076b8SGabor Kovesdancontext diff header, or with an
5522dd076b8SGabor Kovesdan.Qq Index :
5532dd076b8SGabor Kovesdanline.
5542dd076b8SGabor KovesdanIf you are patching something in a subdirectory, be sure to tell the patch
5552dd076b8SGabor Kovesdanuser to specify a
5562dd076b8SGabor Kovesdan.Fl p
5572dd076b8SGabor Kovesdanoption as needed.
5582dd076b8SGabor Kovesdan.Pp
5592dd076b8SGabor KovesdanThird, you can create a file by sending out a diff that compares a
5602dd076b8SGabor Kovesdannull file to the file you want to create.
561*50dacbf6SKyle EvansIf the file you want to create already exists in the target directory when the
562*50dacbf6SKyle Evansdiff is applied, then
563*50dacbf6SKyle Evans.Nm
564*50dacbf6SKyle Evanswill identify the patch as potentially reversed and offer to reverse the patch.
5652dd076b8SGabor Kovesdan.Pp
5662dd076b8SGabor KovesdanFourth, take care not to send out reversed patches, since it makes people wonder
5672dd076b8SGabor Kovesdanwhether they already applied the patch.
5682dd076b8SGabor Kovesdan.Pp
5692dd076b8SGabor KovesdanFifth, while you may be able to get away with putting 582 diff listings into
5702dd076b8SGabor Kovesdanone file, it is probably wiser to group related patches into separate files in
5712dd076b8SGabor Kovesdancase something goes haywire.
5722dd076b8SGabor Kovesdan.Sh ENVIRONMENT
5732dd076b8SGabor Kovesdan.Bl -tag -width "PATCH_VERSION_CONTROL" -compact
5742dd076b8SGabor Kovesdan.It Ev POSIXLY_CORRECT
5752dd076b8SGabor KovesdanWhen set,
5762dd076b8SGabor Kovesdan.Nm
5772dd076b8SGabor Kovesdanbehaves as if the
5782dd076b8SGabor Kovesdan.Fl Fl posix
5792dd076b8SGabor Kovesdanoption has been specified.
5802dd076b8SGabor Kovesdan.It Ev SIMPLE_BACKUP_SUFFIX
5812dd076b8SGabor KovesdanExtension to use for backup file names instead of
5822dd076b8SGabor Kovesdan.Qq .orig .
5832dd076b8SGabor Kovesdan.It Ev TMPDIR
5842dd076b8SGabor KovesdanDirectory to put temporary files in; default is
5852dd076b8SGabor Kovesdan.Pa /tmp .
5862dd076b8SGabor Kovesdan.It Ev PATCH_VERSION_CONTROL
5872dd076b8SGabor KovesdanSelects when numbered backup files are made.
5882dd076b8SGabor Kovesdan.It Ev VERSION_CONTROL
5892dd076b8SGabor KovesdanSame as
5902dd076b8SGabor Kovesdan.Ev PATCH_VERSION_CONTROL .
5912dd076b8SGabor Kovesdan.El
5922dd076b8SGabor Kovesdan.Sh FILES
5932dd076b8SGabor Kovesdan.Bl -tag -width "$TMPDIR/patch*" -compact
5942dd076b8SGabor Kovesdan.It Pa $TMPDIR/patch*
5952dd076b8SGabor Kovesdan.Nm
5962dd076b8SGabor Kovesdantemporary files
5972dd076b8SGabor Kovesdan.It Pa /dev/tty
5982dd076b8SGabor Kovesdanused to read input when
5992dd076b8SGabor Kovesdan.Nm
6002dd076b8SGabor Kovesdanprompts the user
6012dd076b8SGabor Kovesdan.El
602e56ef7d3SXin LI.Sh EXIT STATUS
603e56ef7d3SXin LIThe
604e56ef7d3SXin LI.Nm
605e56ef7d3SXin LIutility exits with one of the following values:
606e56ef7d3SXin LI.Pp
607e56ef7d3SXin LI.Bl -tag -width Ds -offset indent -compact
608e56ef7d3SXin LI.It 0
609e56ef7d3SXin LISuccessful completion.
610e56ef7d3SXin LI.It 1
611e56ef7d3SXin LIOne or more lines were written to a reject file.
612e56ef7d3SXin LI.It \*(Gt1
613e56ef7d3SXin LIAn error occurred.
614e56ef7d3SXin LI.El
615e56ef7d3SXin LI.Pp
616e56ef7d3SXin LIWhen applying a set of patches in a loop it behooves you to check this
617b1edef17SJoel Dahlexit status so you do not apply a later patch to a partially patched file.
6182dd076b8SGabor Kovesdan.Sh DIAGNOSTICS
6192dd076b8SGabor KovesdanToo many to list here, but generally indicative that
6202dd076b8SGabor Kovesdan.Nm
6212dd076b8SGabor Kovesdancouldn't parse your patch file.
6222dd076b8SGabor Kovesdan.Pp
6232dd076b8SGabor KovesdanThe message
6242dd076b8SGabor Kovesdan.Qq Hmm...
6252dd076b8SGabor Kovesdanindicates that there is unprocessed text in the patch file and that
6262dd076b8SGabor Kovesdan.Nm
6272dd076b8SGabor Kovesdanis attempting to intuit whether there is a patch in that text and, if so,
6282dd076b8SGabor Kovesdanwhat kind of patch it is.
6292dd076b8SGabor Kovesdan.Sh SEE ALSO
6302dd076b8SGabor Kovesdan.Xr diff 1
6312dd076b8SGabor Kovesdan.Sh STANDARDS
6322dd076b8SGabor KovesdanThe
6332dd076b8SGabor Kovesdan.Nm
6342dd076b8SGabor Kovesdanutility is compliant with the
635e56ef7d3SXin LI.St -p1003.1-2008
6369f00ccd3SPedro F. Giffunispecification,
6379f00ccd3SPedro F. Giffuniexcept as detailed above for the
6382dd076b8SGabor Kovesdan.Fl -posix
6399f00ccd3SPedro F. Giffunioption.
6402dd076b8SGabor Kovesdan.Pp
6412dd076b8SGabor KovesdanThe flags
642e56ef7d3SXin LI.Op Fl BCEFfstVvxz
6432dd076b8SGabor Kovesdanand
6442dd076b8SGabor Kovesdan.Op Fl -posix
6452dd076b8SGabor Kovesdanare extensions to that specification.
6462dd076b8SGabor Kovesdan.Sh AUTHORS
6472dd076b8SGabor Kovesdan.An Larry Wall
6482dd076b8SGabor Kovesdanwith many other contributors.
6492dd076b8SGabor Kovesdan.Sh CAVEATS
6502dd076b8SGabor Kovesdan.Nm
6512dd076b8SGabor Kovesdancannot tell if the line numbers are off in an ed script, and can only detect
6522dd076b8SGabor Kovesdanbad line numbers in a normal diff when it finds a
6532dd076b8SGabor Kovesdan.Qq change
6542dd076b8SGabor Kovesdanor a
6552dd076b8SGabor Kovesdan.Qq delete
6562dd076b8SGabor Kovesdancommand.
6572dd076b8SGabor KovesdanA context diff using fuzz factor 3 may have the same problem.
6582dd076b8SGabor KovesdanUntil a suitable interactive interface is added, you should probably do
6592dd076b8SGabor Kovesdana context diff in these cases to see if the changes made sense.
6602dd076b8SGabor KovesdanOf course, compiling without errors is a pretty good indication that the patch
6612dd076b8SGabor Kovesdanworked, but not always.
6622dd076b8SGabor Kovesdan.Pp
6632dd076b8SGabor Kovesdan.Nm
6642dd076b8SGabor Kovesdanusually produces the correct results, even when it has to do a lot of
6652dd076b8SGabor Kovesdanguessing.
6662dd076b8SGabor KovesdanHowever, the results are guaranteed to be correct only when the patch is
6672dd076b8SGabor Kovesdanapplied to exactly the same version of the file that the patch was
6682dd076b8SGabor Kovesdangenerated from.
6692dd076b8SGabor Kovesdan.Sh BUGS
6702dd076b8SGabor KovesdanCould be smarter about partial matches, excessively deviant offsets and
6712dd076b8SGabor Kovesdanswapped code, but that would take an extra pass.
6722dd076b8SGabor Kovesdan.Pp
6732dd076b8SGabor KovesdanCheck patch mode
6742dd076b8SGabor Kovesdan.Pq Fl C
6752dd076b8SGabor Kovesdanwill fail if you try to check several patches in succession that build on
6762dd076b8SGabor Kovesdaneach other.
6772dd076b8SGabor KovesdanThe entire
6782dd076b8SGabor Kovesdan.Nm
6792dd076b8SGabor Kovesdancode would have to be restructured to keep temporary files around so that it
6802dd076b8SGabor Kovesdancan handle this situation.
6812dd076b8SGabor Kovesdan.Pp
6822dd076b8SGabor KovesdanIf code has been duplicated (for instance with #ifdef OLDCODE ... #else ...
6832dd076b8SGabor Kovesdan#endif),
6842dd076b8SGabor Kovesdan.Nm
6852dd076b8SGabor Kovesdanis incapable of patching both versions, and, if it works at all, will likely
6862dd076b8SGabor Kovesdanpatch the wrong one, and tell you that it succeeded to boot.
6872dd076b8SGabor Kovesdan.Pp
688b1edef17SJoel DahlIf you apply a patch you have already applied,
6892dd076b8SGabor Kovesdan.Nm
6902dd076b8SGabor Kovesdanwill think it is a reversed patch, and offer to un-apply the patch.
6912dd076b8SGabor KovesdanThis could be construed as a feature.
692