More About Patches
MQ uses the GNU patch command to apply patches, so it’s helpful to know a few more detailed aspects of how patch works, and about patches themselves.
The Strip Count
If you look at the file headers in a patch, you will notice that the pathnames usually have an extra component on the front that isn’t present in the actual pathname. This is a holdover from the way that people used to generate patches (people still do this, but it’s somewhat rare with modern revision control tools).
Alice would unpack a tarball, edit her files, then
decide that she wanted to create a patch. So she’d rename her working
directory, unpack the tarball again (hence the need for the rename),
and use the -r
and -N
options to diff to
recursively generate a patch between the unmodified directory and the
modified one. The result would be that the name of the unmodified
directory would be at the front of the left-hand path in every file
header, and the name of the modified directory would be at the front
of the right-hand path.
Since someone receiving a patch from the Alices of
the Net would be unlikely to have unmodified and modified directories
with exactly the same names, the patch command has
a -p
option that indicates the
number of leading pathname components to strip when trying to apply a
patch. This number is called the strip
count.
An option of -p1 means “use a strip count of one.” If patch sees a filename foo/bar/baz in a file header, it will strip foo and try to patch a file named bar/baz ...
Get Mercurial: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.