45f01dec2a5da58e94fd6023a676f46592eb5146
[p5sagit/p5-mst-13.2.git] / pod / perlrepository.pod
1 =for comment
2 Consistent formatting of this file is achieved with:
3   perl ./Porting/podtidy pod/perlrepository.pod
4
5 =head1 NAME
6
7 perlrepository - Using the Perl source repository
8
9 =head1 SYNOPSIS
10
11 All of Perl's source code is kept centrally in a Git repository at
12 I<perl5.git.perl.org>. The repository contains many Perl revisions
13 from Perl 1 onwards and all the revisions from Perforce, the version
14 control system we were using previously. This repository is accessible
15 in different ways.
16
17 The full repository takes up about 80MB of disk space. A check out of
18 the blead branch (that is, the master branch, which contains bleadperl,
19 the development version of perl 5) takes up about 160MB of disk space
20 (including the repository). A build of bleadperl takes up about 200MB
21 (including the repository and the check out).
22
23 =head1 GETTING ACCESS TO THE REPOSITORY
24
25 =head2 READ ACCESS VIA THE WEB
26
27 You may access the repository over the web. This allows you to browse
28 the tree, see recent commits, subscribe to RSS feeds for the changes,
29 search for particular commits and more. You may access it at:
30
31   http://perl5.git.perl.org/perl.git
32
33 A mirror of the repository is found at:
34
35   http://github.com/github/perl
36
37 =head2 READ ACCESS VIA GIT
38
39 You will need a copy of Git for your computer. You can fetch a copy of
40 the repository using the Git protocol (which uses port 9418):
41
42   git clone git://perl5.git.perl.org/perl.git perl-git
43
44 This clones the repository and makes a local copy in the F<perl-git>
45 directory.
46
47 If your local network does not allow you to use port 9418, then you can
48 fetch a copy of the repository over HTTP (this is slower):
49
50   git clone http://perl5.git.perl.org/perl.git perl-http
51
52 This clones the repository and makes a local copy in the F<perl-http>
53 directory.
54
55 =head2 WRITE ACCESS TO THE REPOSITORY
56
57 If you are a committer, then you can fetch a copy of the repository
58 that you can push back on with:
59
60   git clone ssh://perl5.git.perl.org/gitroot/perl.git perl-ssh
61
62 This clones the repository and makes a local copy in the F<perl-ssh>
63 directory.
64
65 If you cloned using the git protocol, which is faster than ssh, then you will need to
66 modify your config in order to enable pushing. Edit F<.git/config>
67 where you will see something like:
68
69   [remote "origin"]
70   url = git://perl5.git.perl.org/perl.git
71
72 change that to something like this:
73
74   [remote "origin"]
75   url = ssh://perl5.git.perl.org/gitroot/perl.git
76
77 NOTE: there are symlinks set up so that the /gitroot is optional and
78 since SSH is the default protocol you can actually shorten the "url" to
79 C<perl5.git.perl.org:/perl.git>.
80
81 You can also set up your user name and e-mail address. For example
82
83   % git config user.name "Leon Brocard"
84   % git config user.email acme@astray.com
85
86 It is also possible to keep C<origin> as a git remote, and add a new
87 remote for ssh access:
88
89   % git remote add camel perl5.git.perl.org:/perl.git
90
91 This allows you to update your local repository by pulling from
92 C<origin>, which is faster and doesn't require you to authenticate, and
93 to push your changes back with the C<camel> remote:
94
95   % git fetch camel
96   % git push camel
97
98 The C<fetch> command just updates the C<camel> refs, as the objects
99 themselves should have been fetched when pulling from C<origin>.
100
101 =head1 OVERVIEW OF THE REPOSITORY
102
103 Once you have changed into the repository directory, you can inspect
104 it.
105
106 After a clone the repository will contain a single local branch, which
107 will be the current branch as well, as indicated by the asterisk.
108
109   % git branch
110   * blead
111
112 Using the -a switch to C<branch> will also show the remote tracking
113 branches in the repository:
114
115   % git branch -a
116   * blead
117     origin/HEAD
118     origin/blead
119   ...
120
121 The branches that begin with "origin" correspond to the "git remote"
122 that you cloned from (which is named "origin"). Each branch on the
123 remote will be exactly tracked by theses branches. You should NEVER do
124 work on these remote tracking branches. You only ever do work in a
125 local branch. Local branches can be configured to automerge (on pull)
126 from a designated remote tracking branch. This is the case with the
127 default branch C<blead> which will be configured to merge from the
128 remote tracking branch C<origin/blead>.
129
130 You can see recent commits:
131
132   % git log
133
134 And pull new changes from the repository, and update your local
135 repository (must be clean first)
136
137   % git pull
138
139 Assuming we are on the branch C<blead> immediately after a pull, this
140 command would be more or less equivalent to:
141
142   % git fetch
143   % git merge origin/blead
144
145 In fact if you want to update your local repository without touching
146 your working directory you do:
147
148   % git fetch
149
150 And if you want to update your remote-tracking branches for all defined
151 remotes simultaneously you can do
152
153   % git remote update
154
155 Neither of these last two commands will update your working directory,
156 however both will update the remote-tracking branches in your
157 repository.
158
159 To switch to another branch:
160
161   % git checkout origin/maint-5.8-dor
162
163 To make a local branch of a remote branch:
164
165   % git checkout -b maint-5.10 origin/maint-5.10
166
167 To switch back to blead:
168
169   % git checkout blead
170
171 =head2 FINDING OUT YOUR STATUS
172
173 The most common git command you will use will probably be
174
175   % git status
176
177 This command will produce as output a description of the current state
178 of the repository, including modified files and unignored untracked
179 files, and in addition it will show things like what files have been
180 staged for the next commit, and usually some useful information about
181 how to change things. For instance the following:
182
183   $ git status
184   # On branch blead
185   # Your branch is ahead of 'origin/blead' by 1 commit.
186   #
187   # Changes to be committed:
188   #   (use "git reset HEAD <file>..." to unstage)
189   #
190   #       modified:   pod/perlrepository.pod
191   #
192   # Changed but not updated:
193   #   (use "git add <file>..." to update what will be committed)
194   #
195   #       modified:   pod/perlrepository.pod
196   #
197   # Untracked files:
198   #   (use "git add <file>..." to include in what will be committed)
199   #
200   #       deliberate.untracked
201
202 This shows that there were changes to this document staged for commit,
203 and that there were further changes in the working directory not yet
204 staged. It also shows that there was an untracked file in the working
205 directory, and as you can see shows how to change all of this. It also
206 shows that there is one commit on the working branch C<blead> which has
207 not been pushed to the C<origin> remote yet. B<NOTE>: that this output
208 is also what you see as a template if you do not provide a message to
209 C<git commit>.
210
211 Assuming we commit all the mentioned changes above:
212
213   % git commit -a -m'explain git status and stuff about remotes'
214   Created commit daf8e63: explain git status and stuff about remotes
215    1 files changed, 83 insertions(+), 3 deletions(-)
216
217 We can re-run git status and see something like this:
218
219   % git status
220   # On branch blead
221   # Your branch is ahead of 'origin/blead' by 2 commits.
222   #
223   # Untracked files:
224   #   (use "git add <file>..." to include in what will be committed)
225   #
226   #       deliberate.untracked
227   nothing added to commit but untracked files present (use "git add" to track)
228
229
230 When in doubt, before you do anything else, check your status and read
231 it carefully, many questions are answered directly by the git status
232 output.
233
234 =head1 SUBMITTING A PATCH
235
236 If you have a patch in mind for Perl, you should first get a copy of
237 the repository:
238
239   % git clone git://perl5.git.perl.org/perl.git perl-git
240
241 Then change into the directory:
242
243   % cd perl-git
244
245 Alternatively, if you already have a Perl repository, you should ensure
246 that you're on the I<blead> branch, and your repository is up to date:
247
248   % git checkout blead
249   % git pull
250
251 (It's preferable to patch against the latest blead version, since
252 patches are usually integrated from blead to the maintenance branches.
253 This does not apply, obviously, in the rare case where your patch is
254 specific to a maintaince release.)
255
256 Now that we have everything up to date, we need to create a temporary
257 new branch for these changes and switch into it:
258
259   % git checkout -b orange
260
261 which is the short form of
262
263   % git branch orange
264   % git checkout orange
265
266 Then make your changes. For example, if Leon Brocard changes his name
267 to Orange Brocard, we should change his name in the AUTHORS file:
268
269   % perl -pi -e 's{Leon Brocard}{Orange Brocard}' AUTHORS
270
271 You can see what files are changed:
272
273   % git status
274   # On branch orange
275   # Changes to be committed:
276   #   (use "git reset HEAD <file>..." to unstage)
277   #
278   #     modified:   AUTHORS
279   #
280
281 And you can see the changes:
282
283   % git diff
284   diff --git a/AUTHORS b/AUTHORS
285   index 293dd70..722c93e 100644
286   --- a/AUTHORS
287   +++ b/AUTHORS
288   @@ -541,7 +541,7 @@    Lars Hecking                   <lhecking@nmrc.ucc.ie>
289    Laszlo Molnar                  <laszlo.molnar@eth.ericsson.se>
290    Leif Huhn                      <leif@hale.dkstat.com>
291    Len Johnson                    <lenjay@ibm.net>
292   -Leon Brocard                   <acme@astray.com>
293   +Orange Brocard                 <acme@astray.com>
294    Les Peters                     <lpeters@aol.net>
295    Lesley Binks                   <lesley.binks@gmail.com>
296    Lincoln D. Stein               <lstein@cshl.org>
297
298 Now commit your change locally:
299
300   % git commit -a -m 'Rename Leon Brocard to Orange Brocard'
301   Created commit 6196c1d: Rename Leon Brocard to Orange Brocard
302    1 files changed, 1 insertions(+), 1 deletions(-)
303
304 You can examine your last commit with:
305
306   % git show HEAD
307
308 and if you are not happy with either the description or the patch
309 itself you can fix it up by editing the files once more and then
310 issue:
311
312   % git commit -a --amend
313
314 Now you should create a patch file for all your local changes:
315
316   % git format-patch origin
317   0001-Rename-Leon-Brocard-to-Orange-Brocard.patch
318
319 You should now send an email to perl5-porters@perl.org with a
320 description of your changes, and include this patch file as an
321 attachment.
322
323 If you want to delete your temporary branch, you may do so with:
324
325   % git checkout blead
326   % git branch -d orange
327   error: The branch 'orange' is not an ancestor of your current HEAD.
328   If you are sure you want to delete it, run 'git branch -D orange'.
329   % git branch -D orange
330   Deleted branch orange.
331
332 =head2 A note on derived files
333
334 Be aware that many files in the distribution are derivative--avoid
335 patching them, because git won't see the changes to them, and the build
336 process will overwrite them. Patch the originals instead.  Most
337 utilities (like perldoc) are in this category, i.e. patch
338 utils/perldoc.PL rather than utils/perldoc. Similarly, don't create
339 patches for files under $src_root/ext from their copies found in
340 $install_root/lib.  If you are unsure about the proper location of a
341 file that may have gotten copied while building the source
342 distribution, consult the C<MANIFEST>.
343
344 =head2 A note on binary files
345
346 Since the patch(1) utility cannot deal with binary files, it's
347 important that you either avoid the use of binary files in your patch,
348 generate the files dynamically, or that you encode any binary files
349 using the F<uupacktool.pl> utility.
350
351 Assuming you needed to include a gzip-encoded file for a module's test
352 suite, you might do this as follows using the F<uupacktool.pl> utility:
353
354     $ perl uupacktool.pl -v -p -D lib/Some/Module/t/src/t.gz
355     Writing lib/Some/Module/t/src/t.gz into lib/Some/Module/t/src/t.gz.packed
356
357 This will replace the C<t.gz> file with an encoded counterpart. During
358 C<make test>, before any tests are run, perl's Makefile will restore
359 all the C<.packed> files mentioned in the MANIFEST to their original
360 name. This means that the test suite does not need to be aware of this
361 packing scheme and will not need to be altered.
362
363 =head2 Getting your patch accepted
364
365 The first thing you should include with your patch is a description of
366 the problem that the patch corrects.  If it is a code patch (rather
367 than a documentation patch) you should also include a small test case
368 that illustrates the bug (a patch to an existing test file is
369 preferred).
370
371 If you are submitting a code patch there are several other things that
372 you need to do.
373
374 =over 4
375
376 =item Comments, Comments, Comments
377
378 Be sure to adequately comment your code.  While commenting every line
379 is unnecessary, anything that takes advantage of side effects of
380 operators, that creates changes that will be felt outside of the
381 function being patched, or that others may find confusing should be
382 documented.  If you are going to err, it is better to err on the side
383 of adding too many comments than too few.
384
385 =item Style
386
387 In general, please follow the particular style of the code you are
388 patching.
389
390 In particular, follow these general guidelines for patching Perl
391 sources:
392
393     8-wide tabs (no exceptions!)
394     4-wide indents for code, 2-wide indents for nested CPP #defines
395     try hard not to exceed 79-columns
396     ANSI C prototypes
397     uncuddled elses and "K&R" style for indenting control constructs
398     no C++ style (//) comments
399     mark places that need to be revisited with XXX (and revisit often!)
400     opening brace lines up with "if" when conditional spans multiple
401         lines; should be at end-of-line otherwise
402     in function definitions, name starts in column 0 (return value is on
403         previous line)
404     single space after keywords that are followed by parens, no space
405         between function name and following paren
406     avoid assignments in conditionals, but if they're unavoidable, use
407         extra paren, e.g. "if (a && (b = c)) ..."
408     "return foo;" rather than "return(foo);"
409     "if (!foo) ..." rather than "if (foo == FALSE) ..." etc.
410
411 =item Testsuite
412
413 When submitting a patch you should make every effort to also include an
414 addition to perl's regression tests to properly exercise your patch. 
415 Your testsuite additions should generally follow these guidelines
416 (courtesy of Gurusamy Sarathy <gsar@activestate.com>):
417
418     Know what you're testing.  Read the docs, and the source.
419     Tend to fail, not succeed.
420     Interpret results strictly.
421     Use unrelated features (this will flush out bizarre interactions).
422     Use non-standard idioms (otherwise you are not testing TIMTOWTDI).
423     Avoid using hardcoded test numbers whenever possible (the
424       EXPECTED/GOT found in t/op/tie.t is much more maintainable,
425       and gives better failure reports).
426     Give meaningful error messages when a test fails.
427     Avoid using qx// and system() unless you are testing for them.  If you
428       do use them, make sure that you cover _all_ perl platforms.
429     Unlink any temporary files you create.
430     Promote unforeseen warnings to errors with $SIG{__WARN__}.
431     Be sure to use the libraries and modules shipped with the version
432       being tested, not those that were already installed.
433     Add comments to the code explaining what you are testing for.
434     Make updating the '1..42' string unnecessary.  Or make sure that
435       you update it.
436     Test _all_ behaviors of a given operator, library, or function:
437       - All optional arguments
438       - Return values in various contexts (boolean, scalar, list, lvalue)
439       - Use both global and lexical variables
440       - Don't forget the exceptional, pathological cases.
441
442 =back
443
444 =head1 ACCEPTING A PATCH
445
446 If you have received a patch file generated using the above section,
447 you should try out the patch.
448
449 First we need to create a temporary new branch for these changes and
450 switch into it:
451
452   % git checkout -b experimental
453
454 Patches that were formatted by C<git format-patch> are applied with
455 C<git am>:
456
457   % git am 0001-Rename-Leon-Brocard-to-Orange-Brocard.patch
458   Applying Rename Leon Brocard to Orange Brocard
459
460 If just a raw diff is provided, it is also possible use this two-step
461 process:
462
463   % git apply bugfix.diff
464   % git commit -a -m "Some fixing" --author="That Guy <that.guy@internets.com>"
465
466 Now we can inspect the change:
467
468   % git show HEAD
469   commit b1b3dab48344cff6de4087efca3dbd63548ab5e2
470   Author: Leon Brocard <acme@astray.com>
471   Date:   Fri Dec 19 17:02:59 2008 +0000
472
473     Rename Leon Brocard to Orange Brocard
474
475   diff --git a/AUTHORS b/AUTHORS
476   index 293dd70..722c93e 100644
477   --- a/AUTHORS
478   +++ b/AUTHORS
479   @@ -541,7 +541,7 @@ Lars Hecking                        <lhecking@nmrc.ucc.ie>
480    Laszlo Molnar                  <laszlo.molnar@eth.ericsson.se>
481    Leif Huhn                      <leif@hale.dkstat.com>
482    Len Johnson                    <lenjay@ibm.net>
483   -Leon Brocard                   <acme@astray.com>
484   +Orange Brocard                 <acme@astray.com>
485    Les Peters                     <lpeters@aol.net>
486    Lesley Binks                   <lesley.binks@gmail.com>
487    Lincoln D. Stein               <lstein@cshl.org>
488
489 If you are a committer to Perl and you think the patch is good, you can
490 then merge it into blead then push it out to the main repository:
491
492   % git checkout blead
493   % git merge experimental
494   % git push
495
496 If you want to delete your temporary branch, you may do so with:
497
498   % git checkout blead
499   % git branch -d experimental
500   error: The branch 'experimental' is not an ancestor of your current HEAD.
501   If you are sure you want to delete it, run 'git branch -D experimental'.
502   % git branch -D experimental
503   Deleted branch experimental.
504
505 =head1 CLEANING A WORKING DIRECTORY
506
507 The command C<git clean> can with varying arguments be used as a
508 replacement for C<make clean>.
509
510 To reset your working directory to a pristine condition you can do:
511
512   git clean -dxf
513
514 However, be aware this will delete ALL untracked content. You can use
515
516   git clean -Xf
517
518 to remove all ignored untracked files, such as build and test
519 byproduct, but leave any  manually created files alone.
520
521 If you only want to cancel some uncommitted edits, you can use C<git
522 checkout> and give it a list of files to be reverted, or C<git
523 checkout -f> to revert them all.
524
525 If you want to cancel one or several commits, you can use C<git reset>.
526
527 =head1 BISECTING
528
529 C<git> provides a built-in way to determine, with a binary search in
530 the history, which commit should be blamed for introducing a given bug.
531
532 Suppose that we have a script F<~/testcase.pl> that exits with C<0>
533 when some behaviour is correct, and with C<1> when it's faulty. We need
534 an helper script that automates building C<perl> and running the
535 testcase:
536
537   % cat ~/run
538   #!/bin/sh
539   git clean -dxf
540   # If you can use ccache, add -Dcc=ccache\ gcc -Dld=gcc to the Configure line
541   sh Configure -des -Dusedevel -Doptimize="-g" || exit 125
542   make || exit 125
543   ./perl -Ilib ~/testcase.pl
544
545 This script may return C<125> to indicate that the corresponding commit
546 should be skipped. Otherwise, it returns the status of
547 F<~/testcase.pl>.
548
549 We first enter in bisect mode with:
550
551   % git bisect start
552
553 For example, if the bug is present on C<HEAD> but wasn't in 5.10.0,
554 C<git> will learn about this when you enter:
555
556   % git bisect bad
557   % git bisect good perl-5.10.0
558   Bisecting: 853 revisions left to test after this
559
560 This results in checking out the median commit between C<HEAD> and
561 C<perl-5.10.0>. We can then run the bisecting process with:
562
563   % git bisect run ~/run
564
565 When the first bad commit is isolated, C<git bisect> will tell you so:
566
567   ca4cfd28534303b82a216cfe83a1c80cbc3b9dc5 is first bad commit
568   commit ca4cfd28534303b82a216cfe83a1c80cbc3b9dc5
569   Author: Dave Mitchell <davem@fdisolutions.com>
570   Date:   Sat Feb 9 14:56:23 2008 +0000
571
572       [perl #49472] Attributes + Unknown Error
573       ...
574
575   bisect run success
576
577 You can peek into the bisecting process with C<git bisect log> and
578 C<git bisect visualize>. C<git bisect reset> will get you out of bisect
579 mode.
580
581 Please note that the first C<good> state must be an ancestor of the
582 first C<bad> state. If you want to search for the commit that I<solved>
583 some bug, you have to negate your test case (i.e. exit with C<1> if OK
584 and C<0> if not) and still mark the lower bound as C<good> and the
585 upper as C<bad>. The "first bad commit" has then to be understood as
586 the "first commit where the bug is solved".
587
588 C<git help bisect> has much more information on how you can tweak your
589 binary searches.
590
591 =head1 SUBMITTING A PATCH VIA GITHUB
592
593 GitHub is a website that makes it easy to fork and publish projects
594 with Git. First you should set up a GitHub account and log in.
595
596 Perl's git repository is mirrored on GitHub at this page:
597
598   http://github.com/github/perl/tree/blead
599
600 Visit the page and click the "fork" button. This clones the Perl git
601 repository for you and provides you with "Your Clone URL" from which
602 you should clone:
603
604   % git clone git@github.com:USERNAME/perl.git perl-github
605
606 We shall make the same patch as above, creating a new branch:
607
608   % cd perl-github
609   % git remote add upstream git://github.com/github/perl.git
610   % git pull upstream blead
611   % git checkout -b orange
612   % perl -pi -e 's{Leon Brocard}{Orange Brocard}' AUTHORS
613   % git commit -a -m 'Rename Leon Brocard to Orange Brocard'
614   % git push origin orange
615
616 The orange branch has been pushed to GitHub, so you should now send an
617 email to perl5-porters@perl.org with a description of your changes and
618 the following information:
619
620   http://github.com/USERNAME/perl/tree/orange
621   git@github.com:USERNAME/perl.git branch orange
622
623 =head1 COMMITTING TO MAINTENANCE VERSIONS
624
625 To commit to a maintenance version of perl, you need to create a local
626 tracking branch:
627
628   % git checkout --track -b maint-5.005 origin/maint-5.005
629
630 This creates a local branch named C<maint-5.005>, which tracks the
631 remote branch C<origin/maint-5.005>. Then you can pull, commit, merge
632 and push as before.
633
634 You can also cherry-pick commits from blead and another branch, by
635 using the C<git cherry-pick> command. It is recommended to use the
636 B<-x> option to C<git cherry-pick> in order to record the SHA1 of the
637 original commit in the new commit message.
638
639 =head1 SEE ALSO
640
641 The git documentation, accessible via C<git help command>.
642