2010/09/01: GNU patch and -p0

The GNU version of patch describes the option -p as follows.


      -pnum  or  --strip=num
          Strip  the  smallest prefix containing num leading slashes from each
          file name found in the patch file.  A sequence of one or more  adja-
          cent  slashes  is counted as a single slash.  This controls how file
          names found in the patch file are treated, in  case  you  keep  your
          files  in  a  different  directory  than the person who sent out the
          patch.  For example, supposing the file name in the patch file was

             /u/howard/src/blurfl/blurfl.c

          setting -p0 gives the entire file name unmodified, -p1 gives

             u/howard/src/blurfl/blurfl.c

          without the leading slash, -p4 gives

             blurfl/blurfl.c

          and 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 option.

The BSD version describes this option similar, except that the last paragraph is slightly different.


          and not specifying -p at all just gives you "blurfl.c", unless all
          of the directories in the leading path (u/howard/src/blurfl) exist
          and that path is relative, in which case you get the entire  path-
          name unmodified.  Whatever you end up with is looked for either in
          the current directory,  or  the  directory  specified  by  the  -d
          option.

In practical terms this means that if you have a patch starting with


--- doc/Makefile.in.orig	2010-01-25 00:32:06.000000000 +0100
+++ doc/Makefile.in	2010-02-13 22:07:07.508968660 +0100
@@ -272,11 +272,11 @@
...

on a BSD System you can simply say


patch < patch-doc-Makefile.in

and it will apply to ./doc/Makefile.in; on GNU Systems, patch will try to apply the patch to ./Makefile.in.

Summary: On GNU systems always use patch with -p0