home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d02xx / d0296.lha / Patch / patch.doc < prev    next >
Text File  |  1989-12-28  |  19KB  |  397 lines

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