home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / DIFFPT.ZIP / PATCH.MAN < prev    next >
Text File  |  1991-07-01  |  15KB  |  316 lines

  1. NAME
  2.      patch - a program for applying a diff file to an original
  3.  
  4. SYNOPSIS
  5.      patch [options] orig patchfile [+ [options] orig]
  6.  
  7.      but usually just
  8.  
  9.      patch <patchfile
  10.  
  11. DESCRIPTION
  12.      Patch will take a patch file containing any of the four
  13.      forms of difference listing produced by the diff program and
  14.      apply those differences to an original file, producing a
  15.      patched version.  By default, the patched version is put in
  16.      place of the original, with the original file backed up to
  17.      the same name with the extension ".orig" or "~" , or as
  18.      specified by the -b switch.  You may also specify where you
  19.      want the output to go with a -o switch.  If patchfile is
  20.      omitted, or is a hyphen, the patch will be read from stan-
  21.      dard input.
  22.  
  23.      Upon startup, patch will attempt to determine the type of
  24.      the diff listing, unless over-ruled by a -c, -e, or -n
  25.      switch.  Context diffs (old-style, new-style, and unified) and
  26.      normal diffs are applied by the patch program itself, while ed
  27.      diffs are simply fed to the ed editor via a pipe.
  28.  
  29.      Patch will try to skip any leading garbage, apply the diff,
  30.      and then skip any trailing garbage.  Thus you could feed an
  31.      article or message containing a diff listing to patch, and
  32.      it should work.  If the entire diff is indented by a con-
  33.      sistent amount, this will be taken into account.
  34.  
  35.      With context diffs, and to a lesser extent with normal
  36.      diffs, patch can detect when the line numbers mentioned in
  37.      the patch are incorrect, and will attempt to find the
  38.      correct place to apply each hunk of the patch.  As a first
  39.      guess, it takes the line number mentioned for the hunk, plus
  40.      or minus any offset used in applying the previous hunk.  If
  41.      that is not the correct place, patch will scan both forwards
  42.      and backwards for a set of lines matching the context given
  43.      in the hunk.  First patch looks for a place where all lines
  44.      of the context match.  If no such place is found, and it's a
  45.      context diff, and the maximum fuzz factor is set to 1 or
  46.      more, then another scan takes place ignoring the first and
  47.      last line of context.  If that fails, and the maximum fuzz
  48.      factor is set to 2 or more, the first two and last two lines
  49.      of context are ignored, and another scan is made.  (The
  50.      default maximum fuzz factor is 2.) If patch cannot find a
  51.      place to install that hunk of the patch, it will put the
  52.      hunk out to a reject file, which normally is the name of the
  53.      output file plus ".rej" or "#" .  (Note that the rejected
  54.      hunk will come out in context diff form whether the input
  55.      patch was a context diff or a normal diff.  If the input was
  56.      a normal diff, many of the contexts will simply be null.)
  57.      The line numbers on the hunks in the reject file may be dif-
  58.      ferent than in the patch file: they reflect the approximate
  59.      location patch thinks the failed hunks belong in the new
  60.      file rather than the old one.
  61.  
  62.      As each hunk is completed, you will be told whether the hunk
  63.      succeeded or failed, and which line (in the new file) patch
  64.      thought the hunk should go on.  If this is different from
  65.      the line number specified in the diff you will be told the
  66.      offset.  A single large offset MAY be an indication that a
  67.      hunk was installed in the wrong place.  You will also be
  68.      told if a fuzz factor was used to make the match, in which
  69.      case you should also be slightly suspicious.
  70.  
  71.      If no original file is specified on the command line, patch
  72.      will try to figure out from the leading garbage what the
  73.      name of the file to edit is.  In the header of a context
  74.      diff, the filename is found from lines beginning with "***"
  75.      or "---", with the shortest name of an existing file win-
  76.      ning.  Only context diffs have lines like that, but if there
  77.      is an "Index:" line in the leading garbage, patch will try
  78.      to use the filename from that line.  The context diff header
  79.      takes precedence over an Index line.  If no filename can be
  80.      intuited from the leading garbage, you will be asked for the
  81.      name of the file to patch.
  82.  
  83.      (If the original file cannot be found, but a suitable SCCS
  84.      or RCS file is handy, patch will attempt to get or check out
  85.      the file.)
  86.  
  87.      Additionally, if the leading garbage contains a "Prereq: "
  88.      line, patch will take the first word from the prerequisites
  89.      line (normally a version number) and check the input file to
  90.      see if that word can be found.  If not, patch will ask for
  91.      confirmation before proceeding.
  92.  
  93.      The upshot of all this is that you should be able to say,
  94.      while in a news interface, the following:
  95.  
  96.           | patch -d /usr/src/local/blurfl
  97.  
  98.      and patch a file in the blurfl directory directly from the
  99.      article containing the patch.
  100.  
  101.      If the patch file contains more than one patch, patch will
  102.      try to apply each of them as if they came from separate
  103.      patch files.  This means, among other things, that it is
  104.      assumed that the name of the file to patch must be
  105.      determined for each diff listing, and that the garbage
  106.      before each diff listing will be examined for interesting
  107.      things such as filenames and revision level, as mentioned
  108.      previously.  You can give switches (and another original
  109.      file name) for the second and subsequent patches by separat-
  110.      ing the corresponding argument lists by a '+'.  (The argu-
  111.      ment list for a second or subsequent patch may not specify a
  112.      new patch file, however.)
  113.  
  114.      Patch recognizes the following switches:
  115.  
  116.      -b   causes the next argument to be interpreted as the
  117.           backup extension, to be used in place of ".orig" or
  118.           "~".
  119.  
  120.      -B   causes the next argument to be interpreted as a prefix
  121.           to the backup file name. If this argument is specified
  122.           any argument from -b will be ignored.  This argument is
  123.           an extension to Larry Wall's patch v2.0.1.4, patchlevel
  124.           8, made by M. Greim (greim@sbsvax.uucp).
  125.  
  126.      -c   forces patch to interpret the patch file as a context
  127.           diff.
  128.  
  129.      -d   causes patch to interpret the next argument as a direc-
  130.           tory, and cd to it before doing anything else.
  131.  
  132.      -D   causes patch to use the "#ifdef...#endif" construct to
  133.           mark changes.  The argument following will be used as
  134.           the differentiating symbol.  Note that, unlike the C
  135.           compiler, there must be a space between the -D and the
  136.           argument.
  137.  
  138.      -e   forces patch to interpret the patch file as an ed
  139.           script.
  140.  
  141.      -f   forces patch to assume that the user knows exactly what
  142.           he or she is doing, and to not ask any questions.  It
  143.           does not suppress commentary, however.  Use -s for
  144.           that.
  145.  
  146.      -F<number>
  147.           sets the maximum fuzz factor.  This switch only applies
  148.           to context diffs, and causes patch to ignore up to that
  149.           many lines in looking for places to install a hunk.
  150.           Note that a larger fuzz factor increases the odds of a
  151.           faulty patch.  The default fuzz factor is 2, and it may
  152.           not be set to more than the number of lines of context
  153.           in the context diff, ordinarily 3.
  154.  
  155.      -l   causes the pattern matching to be done loosely, in case
  156.           the tabs and spaces have been munged in your input
  157.           file.  Any sequence of whitespace in the pattern line
  158.           will match any sequence in the input file.  Normal
  159.           characters must still match exactly.  Each line of the
  160.           context must still match a line in the input file.
  161.  
  162.      -n   forces patch to interpret the patch file as a normal
  163.           diff.
  164.  
  165.      -N   causes patch to ignore patches that it thinks are
  166.           reversed or already applied.  See also -R .
  167.  
  168.      -o   causes the next argument to be interpreted as the out-
  169.           put file name.
  170.  
  171.      -p<number>
  172.           sets the pathname strip count, which controls how path-
  173.           names found in the patch file are treated, in case the
  174.           you keep your files in a different directory than the
  175.           person who sent out the patch.  The strip count speci-
  176.           fies how many slashes are to be stripped from the front
  177.           of the pathname.  (Any intervening directory names also
  178.           go away.) For example, supposing the filename in the
  179.           patch file was
  180.  
  181.                /u/howard/src/blurfl/blurfl.c
  182.  
  183.           setting -p or -p0 gives the entire pathname unmodified,
  184.           -p1 gives
  185.  
  186.                u/howard/src/blurfl/blurfl.c
  187.  
  188.           without the leading slash, -p4 gives
  189.  
  190.                blurfl/blurfl.c
  191.  
  192.           and not specifying -p at all just gives you "blurfl.c".
  193.           Whatever you end up with is looked for either in the
  194.           current directory, or the directory specified by the -d
  195.           switch.
  196.  
  197.      -r   causes the next argument to be interpreted as the
  198.           reject file name.
  199.  
  200.      -R   tells patch that this patch was created with the old
  201.           and new files swapped.  (Yes, I'm afraid that does hap-
  202.           pen occasionally, human nature being what it is.) Patch
  203.           will attempt to swap each hunk around before applying
  204.           it.  Rejects will come out in the swapped format.  The
  205.           -R switch will not work with ed diff scripts because
  206.           there is too little information to reconstruct the
  207.           reverse operation.
  208.  
  209.           If the first hunk of a patch fails, patch will reverse
  210.           the hunk to see if it can be applied that way.  If it
  211.           can, you will be asked if you want to have the -R
  212.           switch set.  If it can't, the patch will continue to be
  213.           applied normally.  (Note: this method cannot detect a
  214.           reversed patch if it is a normal diff and if the first
  215.           command is an append (i.e. it should have been a
  216.           delete) since appends always succeed, due to the fact
  217.           that a null context will match anywhere.  Luckily, most
  218.           patches add or change lines rather than delete them, so
  219.           most reversed normal diffs will begin with a delete,
  220.           which will fail, triggering the heuristic.)
  221.  
  222.      -s   makes patch do its work silently, unless an error
  223.           occurs.
  224.  
  225.      -S   causes patch to ignore this patch from the patch file,
  226.           but continue on looking for the next patch in the file.
  227.           Thus
  228.  
  229.                patch -S + -S + <patchfile
  230.  
  231.           will ignore the first and second of three patches.
  232.  
  233.      -u   forces patch to interpret the patch file as a unified
  234.           context diff (a unidiff).
  235.  
  236.      -v   causes patch to print out it's revision header and
  237.           patch level.
  238.  
  239.      -x<number>
  240.           sets internal debugging flags, and is of interest only
  241.           to patch patchers.
  242.  
  243. ENVIRONMENT
  244.      No environment variables are used by patch.
  245.  
  246. FILES
  247.      /tmp/patch*
  248.  
  249. SEE ALSO
  250.      diff(1)
  251.  
  252. NOTES FOR PATCH SENDERS
  253.      There are several things you should bear in mind if you are
  254.      going to be sending out patches.  First, you can save people
  255.      a lot of grief by keeping a patchlevel.h file which is
  256.      patched to increment the patch level as the first diff in
  257.      the patch file you send out.  If you put a Prereq: line in
  258.      with the patch, it won't let them apply patches out of order
  259.      without some warning.  Second, make sure you've specified
  260.      the filenames right, either in a context diff header, or
  261.      with an Index: line.  If you are patching something in a
  262.      subdirectory, be sure to tell the patch user to specify a -p
  263.      switch as needed.  Third, you can create a file by sending
  264.      out a diff that compares a null file to the file you want to
  265.      create.  This will only work if the file you want to create
  266.      doesn't exist already in the target directory.  Fourth, take
  267.      care not to send out reversed patches, since it makes people
  268.      wonder whether they already applied the patch.  Fifth, while
  269.      you may be able to get away with putting 582 diff listings
  270.      into one file, it is probably wiser to group related patches
  271.      into separate files in case something goes haywire.
  272.  
  273. DIAGNOSTICS
  274.      Too many to list here, but generally indicative that patch
  275.      couldn't parse your patch file.
  276.  
  277.      The message "Hmm..." indicates that there is unprocessed
  278.      text in the patch file and that patch is attempting to
  279.      intuit whether there is a patch in that text and, if so,
  280.      what kind of patch it is.
  281.  
  282.      Patch will exit with a non-zero status if any reject files
  283.      were created.  When applying a set of patches in a loop it
  284.      behooves you to check this exit status so you don't apply a
  285.      later patch to a partially patched file.
  286.  
  287. CAVEATS
  288.      Patch cannot tell if the line numbers are off in an ed
  289.      script, and can only detect bad line numbers in a normal
  290.      diff when it finds a "change" or a "delete" command.  A con-
  291.      text diff using fuzz factor 3 may have the same problem.
  292.      Until a suitable interactive interface is added, you should
  293.      probably do a context diff in these cases to see if the
  294.      changes made sense.  Of course, compiling without errors is
  295.      a pretty good indication that the patch worked, but not
  296.      always.
  297.  
  298.      Patch usually produces the correct results, even when it has
  299.      to do a lot of guessing.  However, the results are
  300.      guaranteed to be correct only when the patch is applied to
  301.      exactly the same version of the file that the patch was gen-
  302.      erated from.
  303.  
  304. BUGS
  305.      Could be smarter about partial matches, excessively deviant
  306.      offsets and swapped code, but that would take an extra pass.
  307.  
  308.      If code has been duplicated (for instance with #ifdef OLD-
  309.      CODE ... #else ...  #endif), patch is incapable of patching
  310.      both versions, and, if it works at all, will likely patch
  311.      the wrong one, and tell you that it succeeded to boot.
  312.  
  313.      If you apply a patch you've already applied, patch will
  314.      think it is a reversed patch, and offer to un-apply the
  315.      patch.  This could be construed as a feature.
  316.