home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / mach / amiga / tools / patchtls.lha / diff_patch / patch.doc < prev    next >
Encoding:
Text File  |  1992-09-07  |  18.1 KB  |  529 lines

  1.  
  2.  
  3.  
  4. PATCH(1)                 USER COMMANDS                   PATCH(1)
  5.  
  6.  
  7.  
  8. NAME
  9.      patch - a program for applying a diff file to an original
  10.  
  11. SYNOPSIS
  12.      patch [options] orig patchfile [+ [options] orig]
  13.  
  14.      but usually just
  15.  
  16.      patch <patchfile
  17.  
  18. DESCRIPTION
  19.      _P_a_t_c_h will take a patch file  containing  any  of  the  four
  20.      forms of difference listing produced by the _d_i_f_f program and
  21.      apply those differences to an  original  file,  producing  a
  22.      patched  version.  By default, the patched version is put in
  23.      place of the original, with the original file backed  up  to
  24.      the  same  name  with  the extension ".orig" ("~" on systems
  25.      that do not support long filenames), or as specified by  the
  26.      -b,  -B,  or  -V  switches.   The  extension used for making
  27.      backup   files   may    also    be    specified    in    the
  28.      SIMPLE_BACKUP_SUFFIX environment variable, which is overrid-
  29.      den by above switches.
  30.  
  31.      If the backup file  already  exists,  patch  creates  a  new
  32.      backup  file  name by changing the first lowercase letter in
  33.      the last component of the file's name  into  uppercase.   If
  34.      there  are no more lowercase letters in the name, it removes
  35.      the first character from the name.  It repeats this  process
  36.      until  it  comes up with a backup file that does not already
  37.      exist.
  38.  
  39.      _p_a_t_c_h removes  output  files  that  are  empty  after  being
  40.      patched.
  41.  
  42.      You may also specify where you want the output to go with  a
  43.      -o  switch;  if  that  file  already exists, it is backed up
  44.      first.
  45.  
  46.      If _p_a_t_c_h_f_i_l_e is omitted, or is a hyphen, the patch  will  be
  47.      read from standard input.
  48.  
  49.      Upon startup, patch will attempt to determine  the  type  of
  50.      the  diff  listing, unless over-ruled by a -c, -e, -n, or -u
  51.      switch.  Context diffs (old-style, new-style,  and  unified)
  52.      and  normal  diffs  are applied by the _p_a_t_c_h program itself,
  53.      while ed diffs are simply fed to the _e_d editor via a pipe.
  54.  
  55.      _P_a_t_c_h will try to skip any leading garbage, apply the  diff,
  56.      and  then skip any trailing garbage.  Thus you could feed an
  57.      article or message containing a diff listing to  _p_a_t_c_h,  and
  58.      it  should  work.   If the entire diff is indented by a con-
  59.      sistent amount, this will be taken into account.
  60.  
  61.  
  62.  
  63. Sun Release 4.1        Last change: LOCAL                       1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. PATCH(1)                 USER COMMANDS                   PATCH(1)
  71.  
  72.  
  73.  
  74.      With context diffs, and  to  a  lesser  extent  with  normal
  75.      diffs,  _p_a_t_c_h  can detect when the line numbers mentioned in
  76.      the patch are  incorrect,  and  will  attempt  to  find  the
  77.      correct  place  to apply each hunk of the patch.  As a first
  78.      guess, it takes the line number mentioned for the hunk, plus
  79.      or  minus any offset used in applying the previous hunk.  If
  80.      that is not the correct place, _p_a_t_c_h will scan both forwards
  81.      and  backwards for a set of lines matching the context given
  82.      in the hunk.  First _p_a_t_c_h looks for a place where all  lines
  83.      of the context match.  If no such place is found, and it's a
  84.      context diff, and the maximum fuzz factor is  set  to  1  or
  85.      more,  then  another scan takes place ignoring the first and
  86.      last line of context.  If that fails, and the  maximum  fuzz
  87.      factor is set to 2 or more, the first two and last two lines
  88.      of context are ignored, and  another  scan  is  made.   (The
  89.      default  maximum  fuzz  factor is 2.) If _p_a_t_c_h cannot find a
  90.      place to install that hunk of the patch,  it  will  put  the
  91.      hunk out to a reject file, which normally is the name of the
  92.      output file plus ".rej" ("#" on systems that do not  support
  93.      long filenames).  (Note that the rejected hunk will come out
  94.      in context diff form whether the input patch was  a  context
  95.      diff or a normal diff.  If the input was a normal diff, many
  96.      of the contexts will simply be null.) The  line  numbers  on
  97.      the  hunks  in  the reject file may be different than in the
  98.      patch file: they  reflect  the  approximate  location  patch
  99.      thinks  the  failed hunks belong in the new file rather than
  100.      the old one.
  101.  
  102.      As each hunk is completed, you will be told whether the hunk
  103.      succeeded  or failed, and which line (in the new file) _p_a_t_c_h
  104.      thought the hunk should go on.  If this  is  different  from
  105.      the  line  number specified in the diff you will be told the
  106.      offset.  A single large offset MAY be an indication  that  a
  107.      hunk  was  installed  in  the wrong place.  You will also be
  108.      told if a fuzz factor was used to make the match,  in  which
  109.      case you should also be slightly suspicious.
  110.  
  111.      If no original file is specified on the command line,  _p_a_t_c_h
  112.      will  try  to  figure  out from the leading garbage what the
  113.      name of the file to edit is.  In the  header  of  a  context
  114.      diff,  the filename is found from lines beginning with "***"
  115.      or "---", with the shortest name of an  existing  file  win-
  116.      ning.  Only context diffs have lines like that, but if there
  117.      is an "Index:" line in the leading garbage, _p_a_t_c_h  will  try
  118.      to use the filename from that line.  The context diff header
  119.      takes precedence over an Index line.  If no filename can  be
  120.      intuited from the leading garbage, you will be asked for the
  121.      name of the file to patch.
  122.  
  123.      If the original file cannot be found or is read-only, but  a
  124.      suitable  SCCS  or  RCS file is handy, _p_a_t_c_h will attempt to
  125.      get or check out the file.
  126.  
  127.  
  128.  
  129. Sun Release 4.1        Last change: LOCAL                       2
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. PATCH(1)                 USER COMMANDS                   PATCH(1)
  137.  
  138.  
  139.  
  140.      Additionally, if the leading garbage contains a  "Prereq:  "
  141.      line,  _p_a_t_c_h will take the first word from the prerequisites
  142.      line (normally a version number) and check the input file to
  143.      see  if  that word can be found.  If not, _p_a_t_c_h will ask for
  144.      confirmation before proceeding.
  145.  
  146.      The upshot of all this is that you should be  able  to  say,
  147.      while in a news interface, the following:
  148.  
  149.           | patch -d /usr/src/local/blurfl
  150.  
  151.      and patch a file in the blurfl directory directly  from  the
  152.      article containing the patch.
  153.  
  154.      If the patch file contains more than one patch,  _p_a_t_c_h  will
  155.      try  to  apply  each  of  them as if they came from separate
  156.      patch files.  This means, among other  things,  that  it  is
  157.      assumed  that  the  name of the file to patch must be deter-
  158.      mined for each diff listing, and  that  the  garbage  before
  159.      each  diff  listing  will be examined for interesting things
  160.      such as filenames and revision level,  as  mentioned  previ-
  161.      ously.   You  can  give  switches (and another original file
  162.      name) for the second and subsequent  patches  by  separating
  163.      the  corresponding  argument  lists by a '+'.  (The argument
  164.      list for a second or subsequent patch may not specify a  new
  165.      patch file, however.)
  166.  
  167.      _P_a_t_c_h recognizes the following switches:
  168.  
  169.      -b   causes the next  argument  to  be  interpreted  as  the
  170.           backup  extension,  to  be  used in place of ".orig" or
  171.           "~".
  172.  
  173.      -B   causes the next argument to be interpreted as a  prefix
  174.           to  the backup file name. If this argument is specified
  175.           any argument from -b will be ignored.
  176.  
  177.      -c   forces _p_a_t_c_h to interpret the patch file as  a  context
  178.           diff.
  179.  
  180.      -d   causes _p_a_t_c_h to interpret the next argument as a direc-
  181.           tory, and cd to it before doing anything else.
  182.  
  183.      -D   causes _p_a_t_c_h to use the "#ifdef...#endif" construct  to
  184.           mark  changes.   The argument following will be used as
  185.           the differentiating symbol.  Note that,  unlike  the  C
  186.           compiler,  there must be a space between the -D and the
  187.           argument.
  188.  
  189.      -e   forces _p_a_t_c_h to interpret  the  patch  file  as  an  ed
  190.           script.
  191.  
  192.  
  193.  
  194.  
  195. Sun Release 4.1        Last change: LOCAL                       3
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. PATCH(1)                 USER COMMANDS                   PATCH(1)
  203.  
  204.  
  205.  
  206.      -f   forces _p_a_t_c_h to assume that the user knows exactly what
  207.           he  or  she is doing, and to not ask any questions.  It
  208.           does not suppress  commentary,  however.   Use  -s  for
  209.           that.
  210.  
  211.      -F<number>
  212.           sets the maximum fuzz factor.  This switch only applies
  213.           to context diffs, and causes _p_a_t_c_h to ignore up to that
  214.           many lines in looking for places  to  install  a  hunk.
  215.           Note  that a larger fuzz factor increases the odds of a
  216.           faulty patch.  The default fuzz factor is 2, and it may
  217.           not  be set to more than the number of lines of context
  218.           in the context diff, ordinarily 3.
  219.  
  220.      -l   causes the pattern matching to be done loosely, in case
  221.           the  tabs  and  spaces  have  been munged in your input
  222.           file.  Any sequence of whitespace in the  pattern  line
  223.           will  match  any  sequence  in  the input file.  Normal
  224.           characters must still match exactly.  Each line of  the
  225.           context must still match a line in the input file.
  226.  
  227.      -n   forces _p_a_t_c_h to interpret the patch file  as  a  normal
  228.           diff.
  229.  
  230.      -N   causes _p_a_t_c_h to  ignore  patches  that  it  thinks  are
  231.           reversed or already applied.  See also -R .
  232.  
  233.      -o   causes the next argument to be interpreted as the  out-
  234.           put file name.
  235.  
  236.      -p<number>
  237.           sets the pathname strip count, which controls how path-
  238.           names  found in the patch file are treated, in case the
  239.           you keep your files in a different directory  than  the
  240.           person  who sent out the patch.  The strip count speci-
  241.           fies how many slashes are to be stripped from the front
  242.           of the pathname.  (Any intervening directory names also
  243.           go away.) For example, supposing the  filename  in  the
  244.           patch file was
  245.  
  246.                /u/howard/src/blurfl/blurfl.c
  247.  
  248.           setting -p or -p0 gives the entire pathname unmodified,
  249.           -p1 gives
  250.  
  251.                u/howard/src/blurfl/blurfl.c
  252.  
  253.           without the leading slash, -p4 gives
  254.  
  255.                blurfl/blurfl.c
  256.  
  257.           and not specifying -p at all just gives you "blurfl.c",
  258.  
  259.  
  260.  
  261. Sun Release 4.1        Last change: LOCAL                       4
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. PATCH(1)                 USER COMMANDS                   PATCH(1)
  269.  
  270.  
  271.  
  272.           unless  all  of  the  directories  in  the leading path
  273.           (u/howard/src/blurfl) exist and that path is  relative,
  274.           in  which  case you get the entire pathname unmodified.
  275.           Whatever you end up with is looked for  either  in  the
  276.           current directory, or the directory specified by the -d
  277.           switch.
  278.  
  279.      -r   causes the next  argument  to  be  interpreted  as  the
  280.           reject file name.
  281.  
  282.      -R   tells _p_a_t_c_h that this patch was created  with  the  old
  283.           and new files swapped.  (Yes, I'm afraid that does hap-
  284.           pen occasionally, human nature being what it is.) _P_a_t_c_h
  285.           will  attempt  to swap each hunk around before applying
  286.           it.  Rejects will come out in the swapped format.   The
  287.           -R  switch  will  not work with ed diff scripts because
  288.           there is too  little  information  to  reconstruct  the
  289.           reverse operation.
  290.  
  291.           If the first hunk of a patch fails, _p_a_t_c_h will  reverse
  292.           the  hunk  to see if it can be applied that way.  If it
  293.           can, you will be asked if  you  want  to  have  the  -R
  294.           switch set.  If it can't, the patch will continue to be
  295.           applied normally.  (Note: this method cannot  detect  a
  296.           reversed  patch if it is a normal diff and if the first
  297.           command is an  append  (i.e.  it  should  have  been  a
  298.           delete)  since  appends always succeed, due to the fact
  299.           that a null context will match anywhere.  Luckily, most
  300.           patches add or change lines rather than delete them, so
  301.           most reversed normal diffs will begin  with  a  delete,
  302.           which will fail, triggering the heuristic.)
  303.  
  304.      -s   makes _p_a_t_c_h do  its  work  silently,  unless  an  error
  305.           occurs.
  306.  
  307.      -S   causes _p_a_t_c_h to ignore this patch from the patch  file,
  308.           but continue on looking for the next patch in the file.
  309.           Thus
  310.  
  311.                patch -S + -S + <patchfile
  312.  
  313.           will ignore the first and second of three patches.
  314.  
  315.      -u   forces _p_a_t_c_h to interpret the patch file as  a  unified
  316.           context diff (a unidiff).
  317.  
  318.      -v   causes _p_a_t_c_h to print out its revision header and patch
  319.           level.
  320.  
  321.      -V   causes the next argument to be interpreted as a  method
  322.           for  creating  backup  file names.  The type of backups
  323.           made  can  also  be  given   in   the   VERSION_CONTROL
  324.  
  325.  
  326.  
  327. Sun Release 4.1        Last change: LOCAL                       5
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. PATCH(1)                 USER COMMANDS                   PATCH(1)
  335.  
  336.  
  337.  
  338.           environment  variable,  which  is  overridden  by  this
  339.           option.  The -B option overrides this  option,  causing
  340.           the  prefix  to  always  be used for making backup file
  341.           names.  The value of  the  VERSION_CONTROL  environment
  342.           variable and the argument to the -V option are like the
  343.           GNU Emacs `version-control' variable; they also  recog-
  344.           nize  synonyms  that  are  more descriptive.  The valid
  345.           values are (unique abbreviations are accepted):
  346.  
  347.           `t' or `numbered'
  348.                Always make numbered backups.
  349.  
  350.           `nil' or `existing'
  351.                Make numbered backups of files that  already  have
  352.                them,  simple  backups of the others.  This is the
  353.                default.
  354.  
  355.           `never' or `simple'
  356.                Always make simple backups.
  357.  
  358.      -x<number>
  359.           sets internal debugging flags, and is of interest  only
  360.           to _p_a_t_c_h patchers.
  361.  
  362. AUTHOR
  363.      Larry Wall <lwall@netlabs.com>
  364.      with many other contributors.
  365.  
  366. ENVIRONMENT
  367.      TMPDIR
  368.           Directory to put temporary files in; default is /tmp.
  369.  
  370.      SIMPLE_BACKUP_SUFFIX
  371.           Extension to use  for  backup  file  names  instead  of
  372.           ".orig" or "~".
  373.  
  374.      VERSION_CONTROL
  375.           Selects when numbered backup files are made.
  376.  
  377. FILES
  378.      $TMPDIR/patch*
  379.  
  380. SEE ALSO
  381.      diff(1)
  382.  
  383. NOTES FOR PATCH SENDERS
  384.      There are several things you should bear in mind if you  are
  385.      going to be sending out patches.  First, you can save people
  386.      a lot of grief by  keeping  a  patchlevel.h  file  which  is
  387.      patched  to  increment  the patch level as the first diff in
  388.      the patch file you send out.  If you put a Prereq:  line  in
  389.      with the patch, it won't let them apply patches out of order
  390.  
  391.  
  392.  
  393. Sun Release 4.1        Last change: LOCAL                       6
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. PATCH(1)                 USER COMMANDS                   PATCH(1)
  401.  
  402.  
  403.  
  404.      without some warning.  Second, make  sure  you've  specified
  405.      the  filenames  right,  either  in a context diff header, or
  406.      with an Index: line.  If you are  patching  something  in  a
  407.      subdirectory, be sure to tell the patch user to specify a -p
  408.      switch as needed.  Third, you can create a file  by  sending
  409.      out a diff that compares a null file to the file you want to
  410.      create.  This will only work if the file you want to  create
  411.      doesn't exist already in the target directory.  Fourth, take
  412.      care not to send out reversed patches, since it makes people
  413.      wonder whether they already applied the patch.  Fifth, while
  414.      you may be able to get away with putting 582  diff  listings
  415.      into one file, it is probably wiser to group related patches
  416.      into separate files in case something goes haywire.
  417.  
  418. DIAGNOSTICS
  419.      Too many to list here, but generally indicative  that  _p_a_t_c_h
  420.      couldn't parse your patch file.
  421.  
  422.      The message "Hmm..." indicates  that  there  is  unprocessed
  423.      text  in  the  patch  file  and  that _p_a_t_c_h is attempting to
  424.      intuit whether there is a patch in that  text  and,  if  so,
  425.      what kind of patch it is.
  426.  
  427.      _P_a_t_c_h will exit with a non-zero status if any  reject  files
  428.      were  created.   When applying a set of patches in a loop it
  429.      behooves you to check this exit status so you don't apply  a
  430.      later patch to a partially patched file.
  431.  
  432. CAVEATS
  433.      _P_a_t_c_h cannot tell if the line  numbers  are  off  in  an  ed
  434.      script,  and  can  only  detect bad line numbers in a normal
  435.      diff when it finds a "change" or a "delete" command.  A con-
  436.      text  diff  using  fuzz  factor 3 may have the same problem.
  437.      Until a suitable interactive interface is added, you  should
  438.      probably  do  a  context  diff  in these cases to see if the
  439.      changes made sense.  Of course, compiling without errors  is
  440.      a  pretty  good  indication  that  the patch worked, but not
  441.      always.
  442.  
  443.      _P_a_t_c_h usually produces the correct results, even when it has
  444.      to   do  a  lot  of  guessing.   However,  the  results  are
  445.      guaranteed to be correct only when the patch is  applied  to
  446.      exactly the same version of the file that the patch was gen-
  447.      erated from.
  448.  
  449. BUGS
  450.      Could be smarter about partial matches, excessively  deviant
  451.      offsets and swapped code, but that would take an extra pass.
  452.  
  453.      If code has been duplicated (for instance with  #ifdef  OLD-
  454.      CODE  ... #else ...  #endif), _p_a_t_c_h is incapable of patching
  455.      both versions, and, if it works at all,  will  likely  patch
  456.  
  457.  
  458.  
  459. Sun Release 4.1        Last change: LOCAL                       7
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. PATCH(1)                 USER COMMANDS                   PATCH(1)
  467.  
  468.  
  469.  
  470.      the wrong one, and tell you that it succeeded to boot.
  471.  
  472.      If you apply a patch  you've  already  applied,  _p_a_t_c_h  will
  473.      think  it  is  a  reversed  patch, and offer to un-apply the
  474.      patch.  This could be construed as a feature.
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525. Sun Release 4.1        Last change: LOCAL                       8
  526.  
  527.  
  528.  
  529.