| 1 | =head1 Name
|
|---|
| 2 |
|
|---|
| 3 | patching.pod - Appropriate format for patches to the perl source tree
|
|---|
| 4 |
|
|---|
| 5 | =head2 Where to get this document
|
|---|
| 6 |
|
|---|
| 7 | The latest version of this document is available from
|
|---|
| 8 | http://perrin.dimensional.com/perl/perlpatch.html
|
|---|
| 9 |
|
|---|
| 10 | =head2 How to contribute to this document
|
|---|
| 11 |
|
|---|
| 12 | You may mail corrections, additions, and suggestions to me
|
|---|
| 13 | at [email protected] but the preferred method would be
|
|---|
| 14 | to follow the instructions set forth in this document and
|
|---|
| 15 | submit a patch 8-).
|
|---|
| 16 |
|
|---|
| 17 | =head1 Description
|
|---|
| 18 |
|
|---|
| 19 | =head2 Why this document exists
|
|---|
| 20 |
|
|---|
| 21 | As an open source project Perl relies on patches and contributions from
|
|---|
| 22 | its users to continue functioning properly and to root out the inevitable
|
|---|
| 23 | bugs. But, some users are unsure as to the I<right> way to prepare a patch
|
|---|
| 24 | and end up submitting seriously malformed patches. This makes it very
|
|---|
| 25 | difficult for the current maintainer to integrate said patches into their
|
|---|
| 26 | distribution. This document sets out usage guidelines for patches in an
|
|---|
| 27 | attempt to make everybody's life easier.
|
|---|
| 28 |
|
|---|
| 29 | =head2 Common problems
|
|---|
| 30 |
|
|---|
| 31 | The most common problems appear to be patches being mangled by certain
|
|---|
| 32 | mailers (I won't name names, but most of these seem to be originating on
|
|---|
| 33 | boxes running a certain popular commercial operating system). Other problems
|
|---|
| 34 | include patches not rooted in the appropriate place in the directory structure,
|
|---|
| 35 | and patches not produced using standard utilities (such as diff).
|
|---|
| 36 |
|
|---|
| 37 | =head1 Proper Patch Guidelines
|
|---|
| 38 |
|
|---|
| 39 | =head2 What to patch
|
|---|
| 40 |
|
|---|
| 41 | Generally speaking you should patch the latest development release
|
|---|
| 42 | of perl. The maintainers of the individual branches will see to it
|
|---|
| 43 | that patches are picked up and applied as appropriate.
|
|---|
| 44 |
|
|---|
| 45 | =head2 How to prepare your patch
|
|---|
| 46 |
|
|---|
| 47 | =over 4
|
|---|
| 48 |
|
|---|
| 49 | =item Creating your patch
|
|---|
| 50 |
|
|---|
| 51 | First, back up the original files. This can't be stressed enough,
|
|---|
| 52 | back everything up _first_.
|
|---|
| 53 |
|
|---|
| 54 | Also, please create patches against a clean distribution of the perl source.
|
|---|
| 55 | This ensures that everyone else can apply your patch without clobbering their
|
|---|
| 56 | source tree.
|
|---|
| 57 |
|
|---|
| 58 | =item diff
|
|---|
| 59 |
|
|---|
| 60 | While individual tastes vary (and are not the point here) patches should
|
|---|
| 61 | be created using either C<-u> or C<-c> arguments to diff. These produce,
|
|---|
| 62 | respectively, unified diffs (where the changed line appears immediately next
|
|---|
| 63 | to the original) and context diffs (where several lines surrounding the changes
|
|---|
| 64 | are included). See the manpage for diff for more details.
|
|---|
| 65 |
|
|---|
| 66 | When GNU diff is available, the pumpkins would prefer you use C<-u -p>
|
|---|
| 67 | (--unified --show-c-function) as arguments for optimal control. The
|
|---|
| 68 | examples below will only use -u.
|
|---|
| 69 |
|
|---|
| 70 | The preferred method for creating a unified diff suitable for feeding
|
|---|
| 71 | to the patch program is:
|
|---|
| 72 |
|
|---|
| 73 | diff -u old-file new-file > patch-file
|
|---|
| 74 |
|
|---|
| 75 | Note the order of files. See below for how to create a patch from
|
|---|
| 76 | two directory trees.
|
|---|
| 77 |
|
|---|
| 78 | If your patch is for wider consumption, it may be better to create it as
|
|---|
| 79 | a context diff as some machines have broken patch utilities that choke on
|
|---|
| 80 | unified diffs. A context diff is made using C<diff -c> rather than
|
|---|
| 81 | C<diff -u>.
|
|---|
| 82 |
|
|---|
| 83 | GNU diff has many desirable features not provided by most vendor-supplied
|
|---|
| 84 | diffs. Some examples using GNU diff:
|
|---|
| 85 |
|
|---|
| 86 | # generate a patch for a newly added file
|
|---|
| 87 | % diff -u /dev/null new/file
|
|---|
| 88 |
|
|---|
| 89 | # generate a patch to remove a file (patch > v2.4 will remove it cleanly)
|
|---|
| 90 | % diff -u old/goner /dev/null
|
|---|
| 91 |
|
|---|
| 92 | # get additions, deletions along with everything else, recursively
|
|---|
| 93 | % diff -ruN olddir newdir
|
|---|
| 94 |
|
|---|
| 95 | # ignore whitespace
|
|---|
| 96 | % diff -bu a/file b/file
|
|---|
| 97 |
|
|---|
| 98 | # show function name in every hunk (safer, more informative)
|
|---|
| 99 | % diff -u -p old/file new/file
|
|---|
| 100 | % diff -u -F '^[_a-zA-Z0-9]+ *(' old/file new/file
|
|---|
| 101 |
|
|---|
| 102 | # show sub name in perl files and modules
|
|---|
| 103 | % diff -u -F '^sub' old/file.pm new/file.pm
|
|---|
| 104 |
|
|---|
| 105 | # show header in doc patches
|
|---|
| 106 | % diff -u -F '^=head' old/file.pod new/file.pod
|
|---|
| 107 |
|
|---|
| 108 | =item Derived Files
|
|---|
| 109 |
|
|---|
| 110 | Many files in the distribution are derivative--avoid patching them.
|
|---|
| 111 | Patch the originals instead. Most utilities (like perldoc) are in
|
|---|
| 112 | this category, i.e. patch utils/perldoc.PL rather than utils/perldoc.
|
|---|
| 113 | Similarly, don't create patches for files under $src_root/ext from
|
|---|
| 114 | their copies found in $install_root/lib. If you are unsure about the
|
|---|
| 115 | proper location of a file that may have gotten copied while building
|
|---|
| 116 | the source distribution, consult the C<MANIFEST>.
|
|---|
| 117 |
|
|---|
| 118 | =item Filenames
|
|---|
| 119 |
|
|---|
| 120 | The most usual convention when submitting patches for a single file is to make
|
|---|
| 121 | your changes to a copy of the file with the same name as the original. Rename
|
|---|
| 122 | the original file in such a way that it is obvious what is being patched
|
|---|
| 123 | ($file.dist or $file.old seem to be popular).
|
|---|
| 124 |
|
|---|
| 125 | If you are submitting patches that affect multiple files then you should
|
|---|
| 126 | backup the entire directory tree (to $source_root.old/ for example). This
|
|---|
| 127 | will allow C<diff -ruN old-dir new-dir> to create all the patches at once.
|
|---|
| 128 |
|
|---|
| 129 | =item Directories
|
|---|
| 130 |
|
|---|
| 131 | IMPORTANT: Patches should be generated from the source root directory, not
|
|---|
| 132 | from the directory that the patched file resides in. This ensures that the
|
|---|
| 133 | maintainer patches the proper file.
|
|---|
| 134 |
|
|---|
| 135 | For larger patches that are dealing with multiple files or
|
|---|
| 136 | directories, Johan Vromans has written a powerful utility: makepatch.
|
|---|
| 137 | See the JV directory on CPAN for the current version. If you have this
|
|---|
| 138 | program available, it is recommended to create a duplicate of the perl
|
|---|
| 139 | directory tree against which you are intending to provide a patch and
|
|---|
| 140 | let makepatch figure out all the changes you made to your copy of the
|
|---|
| 141 | sources. As perl comes with a MANIFEST file, you need not delete
|
|---|
| 142 | object files and other derivative files from the two directory trees,
|
|---|
| 143 | makepatch is smart about them.
|
|---|
| 144 |
|
|---|
|
|---|