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