source: trunk/essentials/dev-lang/perl/Porting/patching.pod

Last change on this file was 3181, checked in by bird, 19 years ago

perl 5.8.8

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