perlhack.html
来自「perl教程」· HTML 代码 · 共 1,154 行 · 第 1/5 页
HTML
1,154 行
</dd>
</li>
</dl>
<dt><strong><a name="item_rsync_27ing_the_patches">rsync'ing the patches</a></strong>
<dd>
<p>The source tree is maintained by the pumpking who applies patches to
the files in the tree. These patches are either created by the
pumpking himself using <code>diff -c</code> after updating the file manually or
by applying patches sent in by posters on the perl5-porters list.
These patches are also saved and rsync'able, so you can apply them
yourself to the source files.</p>
</dd>
<dd>
<p>Presuming you are in a directory where your patches reside, you can
get them in sync with</p>
</dd>
<dd>
<pre>
<span class="comment"># rsync -avz rsync://public.activestate.com/perl-current-diffs/ .</span>
</pre>
</dd>
<dd>
<p>This makes sure the latest available patch is downloaded to your
patch directory.</p>
</dd>
<dd>
<p>It's then up to you to apply these patches, using something like</p>
</dd>
<dd>
<pre>
<span class="comment"># last=`ls -t *.gz | sed q`</span>
<span class="comment"># rsync -avz rsync://public.activestate.com/perl-current-diffs/ .</span>
<span class="comment"># find . -name '*.gz' -newer $last -exec gzcat {} \; >blead.patch</span>
<span class="comment"># cd ../perl-current</span>
<span class="comment"># patch -p1 -N <../perl-current-diffs/blead.patch</span>
</pre>
</dd>
<dd>
<p>or, since this is only a hint towards how it works, use CPAN-patchaperl
from Andreas K鰊ig to have better control over the patching process.</p>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="why_rsync_the_source_tree">Why rsync the source tree</a></h2>
<dl>
<dt><strong><a name="item_it_27s_easier_to_rsync_the_source_tree">It's easier to rsync the source tree</a></strong>
<dd>
<p>Since you don't have to apply the patches yourself, you are sure all
files in the source tree are in the right state.</p>
</dd>
</li>
<dt><strong><a name="item_it_27s_more_reliable">It's more reliable</a></strong>
<dd>
<p>While both the rsync-able source and patch areas are automatically
updated every few minutes, keep in mind that applying patches may
sometimes mean careful hand-holding, especially if your version of
the <code>patch</code> program does not understand how to deal with new files,
files with 8-bit characters, or files without trailing newlines.</p>
</dd>
</li>
</dl>
<p>
</p>
<h2><a name="why_rsync_the_patches">Why rsync the patches</a></h2>
<dl>
<dt><strong><a name="item_it_27s_easier_to_rsync_the_patches">It's easier to rsync the patches</a></strong>
<dd>
<p>If you have more than one machine that you want to keep in track with
bleadperl, it's easier to rsync the patches only once and then apply
them to all the source trees on the different machines.</p>
</dd>
<dd>
<p>In case you try to keep in pace on 5 different machines, for which
only one of them has access to the WAN, rsync'ing all the source
trees should than be done 5 times over the NFS. Having
rsync'ed the patches only once, I can apply them to all the source
trees automatically. Need you say more ;-)</p>
</dd>
</li>
<dt><strong><a name="item_it_27s_a_good_reference">It's a good reference</a></strong>
<dd>
<p>If you do not only like to have the most recent development branch,
but also like to <strong>fix</strong> bugs, or extend features, you want to dive
into the sources. If you are a seasoned perl core diver, you don't
need no manuals, tips, roadmaps, perlguts.pod or other aids to find
your way around. But if you are a starter, the patches may help you
in finding where you should start and how to change the bits that
bug you.</p>
</dd>
<dd>
<p>The file <strong>Changes</strong> is updated on occasions the pumpking sees as his
own little sync points. On those occasions, he releases a tar-ball of
the current source tree (i.e. <a href="mailto:perl@7582.tar.gz),">perl@7582.tar.gz),</a> which will be an
excellent point to start with when choosing to use the 'rsync the
patches' scheme. Starting with perl@7582, which means a set of source
files on which the latest applied patch is number 7582, you apply all
succeeding patches available from then on (7583, 7584, ...).</p>
</dd>
<dd>
<p>You can use the patches later as a kind of search archive.</p>
</dd>
<dl>
<dt><strong><a name="item_finding_a_start_point">Finding a start point</a></strong>
<dd>
<p>If you want to fix/change the behaviour of function/feature Foo, just
scan the patches for patches that mention Foo either in the subject,
the comments, or the body of the fix. A good chance the patch shows
you the files that are affected by that patch which are very likely
to be the starting point of your journey into the guts of perl.</p>
</dd>
</li>
<dt><strong><a name="item_finding_how_to_fix_a_bug">Finding how to fix a bug</a></strong>
<dd>
<p>If you've found <em>where</em> the function/feature Foo misbehaves, but you
don't know how to fix it (but you do know the change you want to
make), you can, again, peruse the patches for similar changes and
look how others apply the fix.</p>
</dd>
</li>
<dt><strong><a name="item_finding_the_source_of_misbehaviour">Finding the source of misbehaviour</a></strong>
<dd>
<p>When you keep in sync with bleadperl, the pumpking would love to
<em>see</em> that the community efforts really work. So after each of his
sync points, you are to 'make test' to check if everything is still
in working order. If it is, you do 'make ok', which will send an OK
report to <a href="mailto:perlbug@perl.org.">perlbug@perl.org.</a> (If you do not have access to a mailer
from the system you just finished successfully 'make test', you can
do 'make okfile', which creates the file <code>perl.ok</code>, which you can
than take to your favourite mailer and mail yourself).</p>
</dd>
<dd>
<p>But of course, as always, things will not always lead to a success
path, and one or more test do not pass the 'make test'. Before
sending in a bug report (using 'make nok' or 'make nokfile'), check
the mailing list if someone else has reported the bug already and if
so, confirm it by replying to that message. If not, you might want to
trace the source of that misbehaviour <strong>before</strong> sending in the bug,
which will help all the other porters in finding the solution.</p>
</dd>
<dd>
<p>Here the saved patches come in very handy. You can check the list of
patches to see which patch changed what file and what change caused
the misbehaviour. If you note that in the bug report, it saves the
one trying to solve it, looking for that point.</p>
</dd>
</li>
</dl>
<p>If searching the patches is too bothersome, you might consider using
perl's bugtron to find more information about discussions and
ramblings on posted bugs.</p>
<p>If you want to get the best of both worlds, rsync both the source
tree for convenience, reliability and ease and rsync the patches
for reference.</p>
</dl>
<p>
</p>
<h2><a name="working_with_the_source">Working with the source</a></h2>
<p>Because you cannot use the Perforce client, you cannot easily generate
diffs against the repository, nor will merges occur when you update
via rsync. If you edit a file locally and then rsync against the
latest source, changes made in the remote copy will <em>overwrite</em> your
local versions!</p>
<p>The best way to deal with this is to maintain a tree of symlinks to
the rsync'd source. Then, when you want to edit a file, you remove
the symlink, copy the real file into the other tree, and edit it. You
can then diff your edited file against the original to generate a
patch, and you can safely update the original tree.</p>
<p>Perl's <em>Configure</em> script can generate this tree of symlinks for you.
The following example assumes that you have used rsync to pull a copy
of the Perl source into the <em>perl-rsync</em> directory. In the directory
above that one, you can execute the following commands:</p>
<pre>
mkdir perl-dev
cd perl-dev
../perl-rsync/Configure -Dmksymlinks -Dusedevel -D"optimize=-g"</pre>
<p>This will start the Perl configuration process. After a few prompts,
you should see something like this:</p>
<pre>
Symbolic links are supported.</pre>
<pre>
Checking how to test for symbolic links...
Your builtin 'test -h' may be broken.
Trying external '/usr/bin/test -h'.
You can test for symbolic links with '/usr/bin/test -h'.</pre>
<pre>
Creating the symbolic links...
(First creating the subdirectories...)
(Then creating the symlinks...)</pre>
<p>The specifics may vary based on your operating system, of course.
After you see this, you can abort the <em>Configure</em> script, and you
will see that the directory you are in has a tree of symlinks to the
<em>perl-rsync</em> directories and files.</p>
<p>If you plan to do a lot of work with the Perl source, here are some
Bourne shell script functions that can make your life easier:</p>
<pre>
<span class="variable">function</span> <span class="variable">edit</span> <span class="operator">{</span>
<span class="keyword">if</span> <span class="operator">[</span> <span class="operator">-</span><span class="variable">L</span> <span class="variable">$1</span> <span class="operator">]</span><span class="operator">;</span> <span class="variable">then</span>
<span class="variable">mv</span> <span class="variable">$1</span> <span class="variable">$1</span><span class="operator">.</span><span class="variable">orig</span>
<span class="variable">cp</span> <span class="variable">$1</span><span class="operator">.</span><span class="variable">orig</span> <span class="variable">$1</span>
<span class="variable">vi</span> <span class="variable">$1</span>
<span class="keyword">else</span>
<span class="operator">/</span><span class="variable">bin</span><span class="operator">/</span><span class="variable">vi</span> <span class="variable">$1</span>
<span class="variable">fi</span>
<span class="operator">}</span>
</pre>
<pre>
<span class="variable">function</span> <span class="variable">unedit</span> <span class="operator">{</span>
<span class="keyword">if</span> <span class="operator">[</span> <span class="operator">-</span><span class="variable">L</span> <span class="variable">$1</span><span class="operator">.</span><span class="variable">orig</span> <span class="operator">]</span><span class="operator">;</span> <span class="variable">then</span>
<span class="variable">rm</span> <span class="variable">$1</span>
<span class="variable">mv</span> <span class="variable">$1</span><span class="operator">.</span><span class="variable">orig</span> <span class="variable">$1</span>
<span class="variable">fi</span>
<span class="operator">}</span>
</pre>
<p>Replace "vi" with your favorite flavor of editor.</p>
<p>Here is another function which will quickly generate a patch for the
files which have been edited in your symlink tree:</p>
<pre>
<span class="variable">mkpatchorig</span><span class="operator">()</span> <span class="operator">{</span>
<span class="keyword">local</span> <span class="variable">diffopts</span>
<span class="keyword">for</span> <span class="variable">f</span> <span class="variable">in</span> <span class="string">`find . -name '*.orig' | sed s,^\./,,`</span>
<span class="keyword">do</span>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?