2 Consistent formatting of this file is achieved with:
3 perl ./Porting/podtidy pod/perlrepository.pod
7 perlrepository - Using the Perl source repository
11 All of Perl's source code is kept centrally in a Git repository. The
12 repository contains many Perl revisions from Perl 1 onwards and all the
13 revisions from Perforce, the version control system we were using
14 previously. This repository is accessible in different ways.
16 The full repository takes up about 80MB of disk space. A check out of
17 the blead branch (that is, the master branch, which contains bleadperl,
18 the development version of perl 5) takes up about 160MB of disk space
19 (including the repository). A build of bleadperl takes up about 200MB
20 (including the repository and the check out).
22 =head1 GETTING ACCESS TO THE REPOSITORY
24 =head2 READ ACCESS VIA THE WEB
26 You may access this over the web. This allows you to browse the tree,
27 see recent commits, search for particular commits and more. You may
30 http://perl5.git.perl.org/perl.git
32 =head2 READ ACCESS VIA GIT
34 You will need a copy of Git for your computer. You can fetch a copy of
35 the repository using the Git protocol (which uses port 9418):
37 git clone git://perl5.git.perl.org/perl.git perl-git
39 This clones the repository and makes a local copy in the F<perl-git>
42 If your local network does not allow you to use port 9418, then you can
43 fetch a copy of the repository over HTTP (this is slower):
45 git clone http://perl5.git.perl.org/perl.git perl-http
47 This clones the repository and makes a local copy in the F<perl-http>
50 =head2 WRITE ACCESS TO THE REPOSITORY
52 If you are a committer, then you can fetch a copy of the repository
53 that you can push back on with:
55 git clone ssh://perl5.git.perl.org/gitroot/perl.git perl-ssh
57 This clones the repository and makes a local copy in the F<perl-ssh>
60 If you clone using git, which is faster than ssh, then you will need to
61 modify your config in order to enable pushing. Edit F<.git/config>
62 where you will see something like:
65 url = git://perl5.git.perl.org/perl.git
67 change that to something like this:
70 url = ssh://perl5.git.perl.org/gitroot/perl.git
72 NOTE: there are symlinks set up so that the /gitroot is actually
75 You can also set up your user name and e-mail address. For example
77 % git config user.name "Leon Brocard"
78 % git config user.email acme@astray.com
80 It is also possible to keep C<origin> as a git remote, and add a new
81 remote for ssh access:
83 % git remote add camel user@camel:/gitroot/perl.git
85 This allows you to update your local repository by pulling from
86 C<origin>, which is faster and doesn't require you to authenticate, and
87 to push your changes back with the C<camel> remote:
92 The C<fetch> command just updates the C<camel> refs, as the objects
93 themselves should have been fetched when pulling from C<origin>.
95 =head1 OVERVIEW OF THE REPOSITORY
97 Once you have changed into the repository directory, you can inspect
100 After a clone the repository will contain a single local branch, which
101 will be the current branch as well, as indicated by the asterisk.
106 Using the -a switch to C<branch> will also show the remote tracking
107 branches in the repository:
115 The branches that begin with "origin" correspond to the "git remote"
116 that you cloned from (which is named "origin"). Each branch on the
117 remote will be exactly tracked by theses branches. You should NEVER do
118 work on these remote tracking branches. You only ever do work in a
119 local branch. Local branches can be configured to automerge (on pull)
120 from a designated remote tracking branch. This is the case with the
121 default branch C<blead> which will be configured to merge from the
122 remote tracking branch C<origin/blead>.
124 You can see recent commits:
128 And pull new changes from the repository, and update your local
129 repository (must be clean first)
133 Assuming we are on the branch C<blead> immediately after a pull, this
134 command would be more or less equivalent to:
137 % git merge origin/blead
139 In fact if you want to update your local repository without touching
140 your working directory you do:
144 And if you want to update your remote-tracking branches for all defined
145 remotes simultaneously you can do
149 Neither of these last two commands will update your working directory,
150 however both will update the remote-tracking branches in your
153 To switch to another branch:
155 % git checkout origin/maint-5.8-dor
157 To make a local branch of a remote branch:
159 % git checkout -b maint-5.10 origin/maint-5.10
161 To switch back to blead:
165 =head2 FINDING OUT YOUR STATUS
167 The most common git command you will use will probably be
171 This command will produce as output a description of the current state
172 of the repository, including modified files and unignored untracked
173 files, and in addition it will show things like what files have been
174 staged for the next commit, and usually some useful information about
175 how to change things. For instance the following:
179 # Your branch is ahead of 'origin/blead' by 1 commit.
181 # Changes to be committed:
182 # (use "git reset HEAD <file>..." to unstage)
184 # modified: pod/perlrepository.pod
186 # Changed but not updated:
187 # (use "git add <file>..." to update what will be committed)
189 # modified: pod/perlrepository.pod
192 # (use "git add <file>..." to include in what will be committed)
194 # deliberate.untracked
196 This shows that there were changes to this document staged for commit,
197 and that there were further changes in the working directory not yet
198 staged. It also shows that there was an untracked file in the working
199 directory, and as you can see shows how to change all of this. It also
200 shows that there is one commit on the working branch C<blead> which has
201 not been pushed to the C<origin> remote yet. B<NOTE>: that this output
202 is also what you see as a template if you do not provide a message to
205 Assuming we commit all the mentioned changes above:
207 % git commit -a -m'explain git status and stuff about remotes'
208 Created commit daf8e63: explain git status and stuff about remotes
209 1 files changed, 83 insertions(+), 3 deletions(-)
211 We can re-run git status and see something like this:
215 # Your branch is ahead of 'origin/blead' by 2 commits.
218 # (use "git add <file>..." to include in what will be committed)
220 # deliberate.untracked
221 nothing added to commit but untracked files present (use "git add" to track)
224 When in doubt, before you do anything else, check your status and read
225 it carefully, many questions are answered directly by the git status
228 =head1 SUBMITTING A PATCH
230 If you have a patch in mind for Perl, you should first get a copy of
233 % git clone git://perl5.git.perl.org/perl.git perl-git
235 Then change into the directory:
239 Alternatively, if you already have a Perl repository, you should ensure
240 that you're on the I<blead> branch, and your repository is up to date:
245 (It's preferable to patch against the latest blead version, since
246 patches are usually integrated from blead to the maintenance branches.
247 This does not apply, obviously, in the rare case where your patch is
248 specific to a maintaince release.)
250 Now that we have everything up to date, we need to create a temporary
251 new branch for these changes and switch into it:
253 % git checkout -b orange
255 which is the short form of
258 % git checkout orange
260 Then make your changes. For example, if Leon Brocard changes his name
261 to Orange Brocard, we should change his name in the AUTHORS file:
263 % perl -pi -e 's{Leon Brocard}{Orange Brocard}' AUTHORS
265 You can see what files are changed:
269 # Changes to be committed:
270 # (use "git reset HEAD <file>..." to unstage)
275 And you can see the changes:
278 diff --git a/AUTHORS b/AUTHORS
279 index 293dd70..722c93e 100644
282 @@ -541,7 +541,7 @@ Lars Hecking <lhecking@nmrc.ucc.ie>
283 Laszlo Molnar <laszlo.molnar@eth.ericsson.se>
284 Leif Huhn <leif@hale.dkstat.com>
285 Len Johnson <lenjay@ibm.net>
286 -Leon Brocard <acme@astray.com>
287 +Orange Brocard <acme@astray.com>
288 Les Peters <lpeters@aol.net>
289 Lesley Binks <lesley.binks@gmail.com>
290 Lincoln D. Stein <lstein@cshl.org>
292 Now commit your change locally:
295 % git commit -m 'Rename Leon Brocard to Orange Brocard'
296 Created commit 6196c1d: Rename Leon Brocard to Orange Brocard
297 1 files changed, 1 insertions(+), 1 deletions(-)
299 Now you should create a patch file for all your local changes:
301 % git format-patch origin
302 0001-Rename-Leon-Brocard-to-Orange-Brocard.patch
304 You should now send an email to perl5-porters@perl.org with a
305 description of your changes, and attach this patch file as an
308 If you want to delete your temporary branch, you may do so with:
311 % git branch -d orange
312 error: The branch 'orange' is not an ancestor of your current HEAD.
313 If you are sure you want to delete it, run 'git branch -D orange'.
314 % git branch -D orange
315 Deleted branch orange.
317 =head2 A note on derived files
319 Be aware that many files in the distribution are derivative--avoid
320 patching them, because git won't see the changes to them, and the build
321 process will overwrite them. Patch the originals instead. Most
322 utilities (like perldoc) are in this category, i.e. patch
323 utils/perldoc.PL rather than utils/perldoc. Similarly, don't create
324 patches for files under $src_root/ext from their copies found in
325 $install_root/lib. If you are unsure about the proper location of a
326 file that may have gotten copied while building the source
327 distribution, consult the C<MANIFEST>.
329 =head2 A note on binary files
331 Since the patch(1) utility cannot deal with binary files, it's
332 important that you either avoid the use of binary files in your patch,
333 generate the files dynamically, or that you encode any binary files
334 using the F<uupacktool.pl> utility.
336 Assuming you needed to include a gzip-encoded file for a module's test
337 suite, you might do this as follows using the F<uupacktool.pl> utility:
339 $ perl uupacktool.pl -v -p -D lib/Some/Module/t/src/t.gz
340 Writing lib/Some/Module/t/src/t.gz into lib/Some/Module/t/src/t.gz.packed
342 This will replace the C<t.gz> file with an encoded counterpart. During
343 C<make test>, before any tests are run, perl's Makefile will restore
344 all the C<.packed> files mentioned in the MANIFEST to their original
345 name. This means that the test suite does not need to be aware of this
346 packing scheme and will not need to be altered.
348 =head2 Getting your patch accepted
350 The first thing you should include with your patch is a description of
351 the problem that the patch corrects. If it is a code patch (rather
352 than a documentation patch) you should also include a small test case
353 that illustrates the bug (a patch to an existing test file is
356 If you are submitting a code patch there are several other things that
361 =item Comments, Comments, Comments
363 Be sure to adequately comment your code. While commenting every line
364 is unnecessary, anything that takes advantage of side effects of
365 operators, that creates changes that will be felt outside of the
366 function being patched, or that others may find confusing should be
367 documented. If you are going to err, it is better to err on the side
368 of adding too many comments than too few.
372 In general, please follow the particular style of the code you are
375 In particular, follow these general guidelines for patching Perl
378 8-wide tabs (no exceptions!)
379 4-wide indents for code, 2-wide indents for nested CPP #defines
380 try hard not to exceed 79-columns
382 uncuddled elses and "K&R" style for indenting control constructs
383 no C++ style (//) comments
384 mark places that need to be revisited with XXX (and revisit often!)
385 opening brace lines up with "if" when conditional spans multiple
386 lines; should be at end-of-line otherwise
387 in function definitions, name starts in column 0 (return value is on
389 single space after keywords that are followed by parens, no space
390 between function name and following paren
391 avoid assignments in conditionals, but if they're unavoidable, use
392 extra paren, e.g. "if (a && (b = c)) ..."
393 "return foo;" rather than "return(foo);"
394 "if (!foo) ..." rather than "if (foo == FALSE) ..." etc.
398 When submitting a patch you should make every effort to also include an
399 addition to perl's regression tests to properly exercise your patch.
400 Your testsuite additions should generally follow these guidelines
401 (courtesy of Gurusamy Sarathy <gsar@activestate.com>):
403 Know what you're testing. Read the docs, and the source.
404 Tend to fail, not succeed.
405 Interpret results strictly.
406 Use unrelated features (this will flush out bizarre interactions).
407 Use non-standard idioms (otherwise you are not testing TIMTOWTDI).
408 Avoid using hardcoded test numbers whenever possible (the
409 EXPECTED/GOT found in t/op/tie.t is much more maintainable,
410 and gives better failure reports).
411 Give meaningful error messages when a test fails.
412 Avoid using qx// and system() unless you are testing for them. If you
413 do use them, make sure that you cover _all_ perl platforms.
414 Unlink any temporary files you create.
415 Promote unforeseen warnings to errors with $SIG{__WARN__}.
416 Be sure to use the libraries and modules shipped with the version
417 being tested, not those that were already installed.
418 Add comments to the code explaining what you are testing for.
419 Make updating the '1..42' string unnecessary. Or make sure that
421 Test _all_ behaviors of a given operator, library, or function:
422 - All optional arguments
423 - Return values in various contexts (boolean, scalar, list, lvalue)
424 - Use both global and lexical variables
425 - Don't forget the exceptional, pathological cases.
429 =head1 ACCEPTING A PATCH
431 If you have received a patch file generated using the above section,
432 you should try out the patch.
434 First we need to create a temporary new branch for these changes and
437 % git checkout -b experimental
439 Patches that were formatted by C<git format-patch> are applied with
442 % git am 0001-Rename-Leon-Brocard-to-Orange-Brocard.patch
443 Applying Rename Leon Brocard to Orange Brocard
445 If just a raw diff is provided, it is also possible use this two-step
448 % git apply bugfix.diff
449 % git commit -am "Some fixing" --author="That Guy <that.guy@internets.com>"
451 Now we can inspect the change:
454 commit b1b3dab48344cff6de4087efca3dbd63548ab5e2
455 Author: Leon Brocard <acme@astray.com>
456 Date: Fri Dec 19 17:02:59 2008 +0000
458 Rename Leon Brocard to Orange Brocard
462 diff --git a/AUTHORS b/AUTHORS
463 index 293dd70..722c93e 100644
466 @@ -541,7 +541,7 @@ Lars Hecking <lhecking@nmrc.ucc.ie>
467 Laszlo Molnar <laszlo.molnar@eth.ericsson.se>
468 Leif Huhn <leif@hale.dkstat.com>
469 Len Johnson <lenjay@ibm.net>
470 -Leon Brocard <acme@astray.com>
471 +Orange Brocard <acme@astray.com>
472 Les Peters <lpeters@aol.net>
473 Lesley Binks <lesley.binks@gmail.com>
474 Lincoln D. Stein <lstein@cshl.org>
476 If you are a committer to Perl and you think the patch is good, you can
477 then merge it into blead then push it out to the main repository:
480 % git merge experimental
483 If you want to delete your temporary branch, you may do so with:
486 % git branch -d experimental
487 error: The branch 'experimental' is not an ancestor of your current HEAD.
488 If you are sure you want to delete it, run 'git branch -D experimental'.
489 % git branch -D experimental
490 Deleted branch experimental.
492 =head1 CLEANING A WORKING DIRECTORY
494 The command C<git clean> can with varying arguments be used as a
495 replacement for make-clean.
497 To reset your working directory to a pristine condition you can do:
501 However, be aware this will delete ALL untracked content. You can use
505 to remove all ignored untracked files, such as build and test
506 byproduct, but leave any manually created files alone.
508 If you only want to cancel some uncommitted edits, you can use C<git
509 checkout> and give it a list of files to be reverted.
511 If you want to cancel one or several commits, you can use C<git reset>.
515 C<git> provides a built-in way to determine, with a binary search in
516 the history, which commit should be blamed for introducing a given bug.
518 Suppose that we have a script F<~/testcase.pl> that exits with C<0>
519 when some behaviour is correct, and with C<1> when it's faulty. We need
520 an helper script that automates building C<perl> and running the
526 # If you can use ccache, add -Dcc=ccache\ gcc -Dld=gcc to the Configure line
527 sh Configure -des -Dusedevel -Doptimize="-g" || exit 125
529 ./perl -Ilib ~/testcase.pl
531 This script may return C<125> to indicate that the corresponding commit
532 should be skipped. Otherwise, it returns the status of
535 We first enter in bisect mode with:
539 For example, if the bug is present on C<HEAD> but wasn't in 5.10.0,
540 C<git> will learn about this when you enter:
543 % git bisect good perl-5.10.0
544 Bisecting: 853 revisions left to test after this
546 This results in checking out the median commit between C<HEAD> and
547 C<perl-5.10.0>. We can then run the bisecting process with:
549 % git bisect run ~/run
551 When the first bad commit is isolated, C<git bisect> will tell you so:
553 ca4cfd28534303b82a216cfe83a1c80cbc3b9dc5 is first bad commit
554 commit ca4cfd28534303b82a216cfe83a1c80cbc3b9dc5
555 Author: Dave Mitchell <davem@fdisolutions.com>
556 Date: Sat Feb 9 14:56:23 2008 +0000
558 [perl #49472] Attributes + Unknown Error
563 You can peek into the bisecting process with C<git bisect log> and
564 C<git bisect visualize>. C<git bisect reset> will get you out of bisect
567 Please note that the first C<good> state must be an ancestor of the
568 first C<bad> state. If you want to search for the commit that I<solved>
569 some bug, you have to negate your test case (i.e. exit with C<1> if OK
570 and C<0> if not) and still mark the lower bound as C<good> and the
571 upper as C<bad>. The "first bad commit" has then to be understood as
572 the "first commit where the bug is solved".
574 C<git help bisect> has much more information on how you can tweak your
577 =head1 COMMITTING TO MAINTENANCE VERSIONS
579 To commit to a maintenance version of perl, you need to create a local
582 % git checkout --track -b maint-5.005 origin/maint-5.005
584 This creates a local branch named C<maint-5.005>, which tracks the
585 remote branch C<origin/maint-5.005>. Then you can pull, commit, merge
588 You can also cherry-pick commits from blead and another branch, by
589 using the C<git cherry-pick> command. It is recommended to use the
590 B<-x> option to C<git cherry-pick> in order to record the SHA1 of the
591 original commit in the new commit message.
595 The git documentation, accessible via C<git help command>.