HP-UX Reference (11i v2 07/12) - 1 User Commands N-Z (vol 2)
p
patch(1) patch(1)
versions of the file being written to the output file.
-p number
sets the path name strip count, which controls how path names found in the patch file are
treated, in case the you keep your files in a different directory from the person who sent out the
patch. The strip count specifies how many slashes are to be stripped from the front of the path
name. (Any intervening directory names also go away.) For example, if the file name in the
patch file is /u/howard/src/blurfl/blurfl.c
,
•
-p or -p0 gives the entire path name unmodified.
• -p1 gives u/howard/src/blurfl/blurfl.c
, without the leading slash.
•
-p4 gives blurfl/blurfl.c
.
• Not specifying
-p at all just gives you
blurfl.c.
Whatever you end up with is looked for either in the current directory, or the directory specified
by the
-d switch.
-r rejectfile
causes the argument to be interpreted as the reject file name.
-R tells patch that this patch was created with the old and new files swapped. (Yes, I’m afraid
that does happen occasionally, human nature being what it is.)
patch will attempt to swap
each hunk around before applying it. Rejects will come out in the swapped format. The
-R
switch will not work with ed diff scripts because there is too little information to reconstruct the
reverse operation.
If the first hunk of a patch fails,
patch will reverse the hunk to see if it can be applied that
way. If it can, you will be asked if you want to have the -R
switch set. If it can’t, the patch will
continue to be applied normally. (Note: this method cannot detect a reversed patch if it is a nor-
mal diff and if the first command is an append (that is, it should have been a delete) since
appends always succeed, due to the fact that a null context will match anywhere. Luckily, most
patches add or change lines rather than delete them, so most reversed normal diffs will begin
with a delete, which will fail, triggering the heuristic.)
-s makes patch do its work silently, unless an error occurs. (This option is not supported by the
XPG4 version.)
-S causes patch to ignore this patch from the patch file, but continue on looking for the next patch
in the file. Thus
patch -S + -S + <patchfile
will ignore the first and second of three patches. (This option is not supported by the XPG4 ver-
sion.)
-v causes patch to print out it’s revision header and patch level. (This option is not supported by
the XPG4 version.)
-x number
sets internal debugging flags, and is of interest only to patch patchers. (This option is not sup-
ported by the XPG4 version.)
Notes for Patch Senders
There are several things you should bear in mind if you are going to be sending out patches. First, you can
save people a lot of grief by keeping a patchlevel.h file which is patched to increment the patch level
as the first diff in the patch file you send out. If you put a Prereq: line in with the patch, it won’t let
them apply patches out of order without some warning. Second, make sure you have specified the file
names right, either in a context diff header, or with an Index: line. If you are patching something in a
subdirectory, be sure to tell the patch user to specify a -p switch as needed. Third, you can create a file by
sending out a diff that compares a null file to the file you want to create. This will only work if the file you
want to create doesn’t exist already in the target directory. Fourth, take care not to send out reversed
patches, since it makes people wonder whether they already applied the patch. Fifth, while you may be
able to get away with putting 582 diff listings into one file, it is probably wiser to group related patches into
separate files in case something goes haywire.
136 Hewlett-Packard Company − 3 − HP-UX 11i Version 2: December 2007 Update