POD: Use F<> for F<utils/perldoc> and F<utils/perldoc.PL>
[p5sagit/p5-mst-13.2.git] / pod / perlrepository.pod
CommitLineData
0549aefb 1=for comment
2Consistent formatting of this file is achieved with:
3 perl ./Porting/podtidy pod/perlrepository.pod
4
d7dd28b6 5=head1 NAME
6
7perlrepository - Using the Perl source repository
8
9=head1 SYNOPSIS
10
dc3c3040 11All of Perl's source code is kept centrally in a Git repository at
c26da522 12I<perl5.git.perl.org>. The repository contains many Perl revisions from
13Perl 1 onwards and all the revisions from Perforce, the version control
14system we were using previously. This repository is accessible in
15different ways.
d7dd28b6 16
17The full repository takes up about 80MB of disk space. A check out of
7f4ffa9d 18the blead branch (that is, the main development branch, which contains
6a7cbfe8 19bleadperl, the development version of perl 5) takes up about 160MB of
20disk space (including the repository). A build of bleadperl takes up
21about 200MB (including the repository and the check out).
d7dd28b6 22
23=head1 GETTING ACCESS TO THE REPOSITORY
24
25=head2 READ ACCESS VIA THE WEB
26
dc3c3040 27You may access the repository over the web. This allows you to browse
28the tree, see recent commits, subscribe to RSS feeds for the changes,
29search for particular commits and more. You may access it at:
d7dd28b6 30
31 http://perl5.git.perl.org/perl.git
32
dc3c3040 33A mirror of the repository is found at:
34
45b194c5 35 http://github.com/mirrors/perl
dc3c3040 36
d7dd28b6 37=head2 READ ACCESS VIA GIT
38
39You will need a copy of Git for your computer. You can fetch a copy of
40the repository using the Git protocol (which uses port 9418):
41
e0b2b458 42 % git clone git://perl5.git.perl.org/perl.git perl-git
d7dd28b6 43
f755e97d 44This clones the repository and makes a local copy in the F<perl-git>
d7dd28b6 45directory.
46
47If your local network does not allow you to use port 9418, then you can
cf5e7595 48fetch a copy of the repository over HTTP (this is at least 4x slower):
d7dd28b6 49
e0b2b458 50 % git clone http://perl5.git.perl.org/perl.git perl-http
d7dd28b6 51
f755e97d 52This clones the repository and makes a local copy in the F<perl-http>
d7dd28b6 53directory.
54
55=head2 WRITE ACCESS TO THE REPOSITORY
56
6acba58e 57If you are a committer, then you can fetch a copy of the repository
58that you can push back on with:
d7dd28b6 59
e0b2b458 60 % git clone ssh://perl5.git.perl.org/perl.git perl-ssh
d7dd28b6 61
8f718e95 62This clones the repository and makes a local copy in the F<perl-ssh>
d7dd28b6 63directory.
64
c26da522 65If you cloned using the git protocol, which is faster than ssh, then
11ed6e28 66you will need to modify the URL for the origin remote to enable
67pushing. To do that edit F<.git/config> with L<git-config(1)> like
68this:
1a0f15d5 69
e0b2b458 70 % git config remote.origin.url ssh://perl5.git.perl.org/perl.git
d7dd28b6 71
9d77ce3f 72You can also set up your user name and e-mail address. Most people do
73this once globally in their F<~/.gitconfig> by doing something like:
184487f0 74
9d77ce3f 75 % git config --global user.name "Ævar Arnfjörð Bjarmason"
76 % git config --global user.email avarab@gmail.com
77
78However if you'd like to override that just for perl then execute then
79execute something like the following in F<perl-git>:
80
81 % git config user.email avar@cpan.org
184487f0 82
6acba58e 83It is also possible to keep C<origin> as a git remote, and add a new
84remote for ssh access:
f6c12373 85
dc3c3040 86 % git remote add camel perl5.git.perl.org:/perl.git
f6c12373 87
6acba58e 88This allows you to update your local repository by pulling from
f755e97d 89C<origin>, which is faster and doesn't require you to authenticate, and
6acba58e 90to push your changes back with the C<camel> remote:
f6c12373 91
92 % git fetch camel
93 % git push camel
94
6acba58e 95The C<fetch> command just updates the C<camel> refs, as the objects
96themselves should have been fetched when pulling from C<origin>.
f6c12373 97
3482f01a 98=head2 A NOTE ON CAMEL AND DROMEDARY
99
100The committers have SSH access to the two servers that serve
333f8875 101C<perl5.git.perl.org>. One is C<perl5.git.perl.org> itself (I<camel>),
102which is the 'master' repository. The second one is
103C<users.perl5.git.perl.org> (I<dromedary>), which can be used for
104general testing and development. Dromedary syncs the git tree from
105camel every few minutes, you should not push there. Both machines also
3482f01a 106have a full CPAN mirror in /srv/CPAN, please use this. To share files
107with the general public, dromedary serves your ~/public_html/ as
333f8875 108C<http://users.perl5.git.perl.org/~yourlogin/>
b47aa495 109
3482f01a 110These hosts have fairly strict firewalls to the outside. Outgoing, only
111rsync, ssh and git are allowed. For http and ftp, you can use
112http://webproxy:3128 as proxy. Incoming, the firewall tries to detect
113attacks and blocks IP addresses with suspicious activity. This
114sometimes (but very rarely) has false positives and you might get
115blocked. The quickest way to get unblocked is to notify the admins.
116
117These two boxes are owned, hosted, and operated by booking.com. You can
118reach the sysadmins in #p5p on irc.perl.org or via mail to
119C<perl5-porters@perl.org>
120
d7dd28b6 121=head1 OVERVIEW OF THE REPOSITORY
122
6acba58e 123Once you have changed into the repository directory, you can inspect
124it.
d7dd28b6 125
39219fd3 126After a clone the repository will contain a single local branch, which
50eca761 127will be the current branch as well, as indicated by the asterisk.
39219fd3 128
129 % git branch
130 * blead
131
f755e97d 132Using the -a switch to C<branch> will also show the remote tracking
6acba58e 133branches in the repository:
39219fd3 134
d9847473 135 % git branch -a
09081495 136 * blead
d7dd28b6 137 origin/HEAD
138 origin/blead
139 ...
140
6acba58e 141The branches that begin with "origin" correspond to the "git remote"
142that you cloned from (which is named "origin"). Each branch on the
143remote will be exactly tracked by theses branches. You should NEVER do
144work on these remote tracking branches. You only ever do work in a
145local branch. Local branches can be configured to automerge (on pull)
146from a designated remote tracking branch. This is the case with the
147default branch C<blead> which will be configured to merge from the
148remote tracking branch C<origin/blead>.
39219fd3 149
d7dd28b6 150You can see recent commits:
151
c2cf2042 152 % git log
d7dd28b6 153
6acba58e 154And pull new changes from the repository, and update your local
155repository (must be clean first)
d7dd28b6 156
157 % git pull
09081495 158
6acba58e 159Assuming we are on the branch C<blead> immediately after a pull, this
160command would be more or less equivalent to:
39219fd3 161
162 % git fetch
163 % git merge origin/blead
164
6acba58e 165In fact if you want to update your local repository without touching
166your working directory you do:
39219fd3 167
168 % git fetch
169
6acba58e 170And if you want to update your remote-tracking branches for all defined
171remotes simultaneously you can do
39219fd3 172
173 % git remote update
174
6acba58e 175Neither of these last two commands will update your working directory,
176however both will update the remote-tracking branches in your
177repository.
39219fd3 178
6051489b 179To make a local branch of a remote branch:
180
181 % git checkout -b maint-5.10 origin/maint-5.10
182
09081495 183To switch back to blead:
184
185 % git checkout blead
c2cf2042 186
39219fd3 187=head2 FINDING OUT YOUR STATUS
188
189The most common git command you will use will probably be
190
191 % git status
192
6acba58e 193This command will produce as output a description of the current state
194of the repository, including modified files and unignored untracked
195files, and in addition it will show things like what files have been
196staged for the next commit, and usually some useful information about
197how to change things. For instance the following:
39219fd3 198
199 $ git status
200 # On branch blead
201 # Your branch is ahead of 'origin/blead' by 1 commit.
202 #
203 # Changes to be committed:
204 # (use "git reset HEAD <file>..." to unstage)
205 #
206 # modified: pod/perlrepository.pod
207 #
208 # Changed but not updated:
209 # (use "git add <file>..." to update what will be committed)
210 #
211 # modified: pod/perlrepository.pod
212 #
213 # Untracked files:
214 # (use "git add <file>..." to include in what will be committed)
215 #
216 # deliberate.untracked
217
6acba58e 218This shows that there were changes to this document staged for commit,
219and that there were further changes in the working directory not yet
220staged. It also shows that there was an untracked file in the working
221directory, and as you can see shows how to change all of this. It also
0549aefb 222shows that there is one commit on the working branch C<blead> which has
223not been pushed to the C<origin> remote yet. B<NOTE>: that this output
224is also what you see as a template if you do not provide a message to
225C<git commit>.
7f6effc7 226
bdaf0bc6 227Assuming that you'd like to commit all the changes you've just made as a
228a single atomic unit, run this command:
229
230 % git commit -a
231
232(That C<-a> tells git to add every file you've changed to this commit.
ea9c0d74 233New files aren't automatically added to your commit when you use C<commit
234-a> If you want to add files or to commit some, but not all of your
235changes, have a look at the documentation for C<git add>.)
bdaf0bc6 236
e9360695 237Git will start up your favorite text editor, so that you can craft a
bdaf0bc6 238commit message for your change. See L</Commit message> below for more
239information about what makes a good commit message.
240
241Once you've finished writing your commit message and exited your editor,
242git will write your change to disk and tell you something like this:
7f6effc7 243
7f6effc7 244 Created commit daf8e63: explain git status and stuff about remotes
245 1 files changed, 83 insertions(+), 3 deletions(-)
246
bdaf0bc6 247
248If you re-run C<git status>, you should see something like this:
7f6effc7 249
250 % git status
251 # On branch blead
252 # Your branch is ahead of 'origin/blead' by 2 commits.
253 #
254 # Untracked files:
255 # (use "git add <file>..." to include in what will be committed)
256 #
257 # deliberate.untracked
258 nothing added to commit but untracked files present (use "git add" to track)
259
39219fd3 260
6acba58e 261When in doubt, before you do anything else, check your status and read
262it carefully, many questions are answered directly by the git status
263output.
39219fd3 264
c2cf2042 265=head1 SUBMITTING A PATCH
266
267If you have a patch in mind for Perl, you should first get a copy of
268the repository:
269
270 % git clone git://perl5.git.perl.org/perl.git perl-git
271
272Then change into the directory:
273
274 % cd perl-git
275
6acba58e 276Alternatively, if you already have a Perl repository, you should ensure
277that you're on the I<blead> branch, and your repository is up to date:
12322d22 278
279 % git checkout blead
280 % git pull
281
6a7cbfe8 282It's preferable to patch against the latest blead version, since this
283is where new development occurs for all changes other than critical bug
284fixes. Critical bug fix patches should be made against the relevant
7f4ffa9d 285maint branches, or should be submitted with a note indicating all the
286branches where the fix should be applied.
a44f43ac 287
6acba58e 288Now that we have everything up to date, we need to create a temporary
289new branch for these changes and switch into it:
b1fccde5 290
a9b05323 291 % git checkout -b orange
23f8d33e 292
a9b05323 293which is the short form of
294
b1fccde5 295 % git branch orange
296 % git checkout orange
297
0c24b290 298Creating a topic branch makes it easier for the maintainers to rebase
299or merge back into the master blead for a more linear history. If you
300don't work on a topic branch the maintainer has to manually cherry
301pick your changes onto blead before they can be applied.
302
303That'll get you scolded on perl5-porters, so don't do that. Be
304Awesome.
305
c2cf2042 306Then make your changes. For example, if Leon Brocard changes his name
307to Orange Brocard, we should change his name in the AUTHORS file:
308
309 % perl -pi -e 's{Leon Brocard}{Orange Brocard}' AUTHORS
310
311You can see what files are changed:
312
313 % git status
f755e97d 314 # On branch orange
c2cf2042 315 # Changes to be committed:
316 # (use "git reset HEAD <file>..." to unstage)
317 #
2699d634 318 # modified: AUTHORS
c2cf2042 319 #
320
c2cf2042 321And you can see the changes:
322
323 % git diff
324 diff --git a/AUTHORS b/AUTHORS
325 index 293dd70..722c93e 100644
326 --- a/AUTHORS
327 +++ b/AUTHORS
7df2e4bc 328 @@ -541,7 +541,7 @@ Lars Hecking <lhecking@nmrc.ucc.ie>
c2cf2042 329 Laszlo Molnar <laszlo.molnar@eth.ericsson.se>
330 Leif Huhn <leif@hale.dkstat.com>
331 Len Johnson <lenjay@ibm.net>
332 -Leon Brocard <acme@astray.com>
333 +Orange Brocard <acme@astray.com>
334 Les Peters <lpeters@aol.net>
335 Lesley Binks <lesley.binks@gmail.com>
336 Lincoln D. Stein <lstein@cshl.org>
337
338Now commit your change locally:
339
dc3c3040 340 % git commit -a -m 'Rename Leon Brocard to Orange Brocard'
c2cf2042 341 Created commit 6196c1d: Rename Leon Brocard to Orange Brocard
342 1 files changed, 1 insertions(+), 1 deletions(-)
343
dc3c3040 344You can examine your last commit with:
345
346 % git show HEAD
347
348and if you are not happy with either the description or the patch
c26da522 349itself you can fix it up by editing the files once more and then issue:
dc3c3040 350
351 % git commit -a --amend
352
c2cf2042 353Now you should create a patch file for all your local changes:
354
2af192ee 355 % git format-patch origin
c2cf2042 356 0001-Rename-Leon-Brocard-to-Orange-Brocard.patch
357
64a8e22b 358You should now send an email to either perlbug@perl.org or
359perl5-porters@perl.org with a description of your changes, and include
360this patch file as an attachment. The perlbug address is preferred,
361but use perl5-porters for patches intended for discussion.
362
363See the next section for how to configure and use git to send these
364emails for you.
c2cf2042 365
b1fccde5 366If you want to delete your temporary branch, you may do so with:
367
368 % git checkout blead
369 % git branch -d orange
370 error: The branch 'orange' is not an ancestor of your current HEAD.
371 If you are sure you want to delete it, run 'git branch -D orange'.
372 % git branch -D orange
373 Deleted branch orange.
7df2e4bc 374
2d5f1d01 375=head2 Using git to send patch emails
376
64a8e22b 377In your ~/git/perl repository, set the destination email to perl's bug
378tracker:
379
380 $ git config sendemail.to perlbug@perl.org
381
382Or maybe perl5-porters (discussed above):
2d5f1d01 383
384 $ git config sendemail.to perl5-porters@perl.org
385
386Then you can use git directly to send your patch emails:
387
388 $ git send-email 0001-Rename-Leon-Brocard-to-Orange-Brocard.patch
389
333f8875 390You may need to set some configuration variables for your particular
391email service provider. For example, to set your global git config to
392send email via a gmail account:
2d5f1d01 393
394 $ git config --global sendemail.smtpserver smtp.gmail.com
395 $ git config --global sendemail.smtpssl 1
396 $ git config --global sendemail.smtpuser YOURUSERNAME@gmail.com
397
333f8875 398With this configuration, you will be prompted for your gmail password
399when you run 'git send-email'. You can also configure
400C<sendemail.smtppass> with your password if you don't care about having
401your password in the .gitconfig file.
2d5f1d01 402
a44f43ac 403=head2 A note on derived files
404
405Be aware that many files in the distribution are derivative--avoid
0549aefb 406patching them, because git won't see the changes to them, and the build
407process will overwrite them. Patch the originals instead. Most
408utilities (like perldoc) are in this category, i.e. patch
0be741b5 409F<utils/perldoc.PL> rather than F<utils/perldoc>. Similarly, don't create
0549aefb 410patches for files under $src_root/ext from their copies found in
411$install_root/lib. If you are unsure about the proper location of a
412file that may have gotten copied while building the source
413distribution, consult the C<MANIFEST>.
a44f43ac 414
ac1cbfb0 415As a special case, several files are regenerated by 'make regen' if
416your patch alters C<embed.fnc>. These are needed for compilation, but
417are included in the distribution so that you can build perl without
418needing another perl to generate the files. You must test with these
419regenerated files, but it is preferred that you instead note that
420'make regen is needed' in both the email and the commit message, and
421submit your patch without them. If you're submitting a series of
422patches, it might be best to submit the regenerated changes
423immediately after the source-changes that caused them, so as to have
424as little effect as possible on the bisectability of your patchset.
425
6e2cec71 426=for XXX
a44f43ac 427
6e2cec71 428What should we recommend about binary files now? Do we need anything?
a44f43ac 429
430=head2 Getting your patch accepted
431
bdaf0bc6 432If you are submitting a code patch there are several things that
a44f43ac 433you need to do.
434
435=over 4
436
bdaf0bc6 437=item Commit message
438
439As you craft each patch you intend to submit to the Perl core, it's
440important to write a good commit message.
441
442Your commit message should start with a description of the problem that
443the patch corrects or new functionality that the patch adds.
444
bdaf0bc6 445As a general rule of thumb, your commit message should let a programmer
446with a reasonable familiarity with the Perl core quickly understand what
447you were trying to do, how you were trying to do it and why the change
448matters to Perl.
449
450=over 4
451
452=item What
453
ac1cbfb0 454Your commit message should describe what part of the Perl core you're
455changing and what you expect your patch to do.
bdaf0bc6 456
457=item Why
458
459Perhaps most importantly, your commit message should describe why the
460change you are making is important. When someone looks at your change
461in six months or six years, your intent should be clear. If you're
462deprecating a feature with the intent of later simplifying another bit
463of code, say so. If you're fixing a performance problem or adding a new
464feature to support some other bit of the core, mention that.
465
466=item How
467
468While it's not necessary for documentation changes, new tests or
469trivial patches, it's often worth explaining how your change works.
470Even if it's clear to you today, it may not be clear to a porter next
471month or next year.
472
473=back
474
ea9c0d74 475A commit message isn't intended to take the place of comments in your
476code. Commit messages should describe the change you made, while code
80a0006a 477comments should describe the current state of the code. If you've just
478implemented a new feature, complete with doc, tests and well-commented
479code, a brief commit message will often suffice. If, however, you've
480just changed a single character deep in the parser or lexer, you might
ea9c0d74 481need to write a small novel to ensure that future readers understand
482what you did and why you did it.
483
a44f43ac 484=item Comments, Comments, Comments
485
0549aefb 486Be sure to adequately comment your code. While commenting every line
487is unnecessary, anything that takes advantage of side effects of
a44f43ac 488operators, that creates changes that will be felt outside of the
0549aefb 489function being patched, or that others may find confusing should be
490documented. If you are going to err, it is better to err on the side
491of adding too many comments than too few.
a44f43ac 492
493=item Style
494
0549aefb 495In general, please follow the particular style of the code you are
496patching.
a44f43ac 497
0549aefb 498In particular, follow these general guidelines for patching Perl
499sources:
a44f43ac 500
501 8-wide tabs (no exceptions!)
502 4-wide indents for code, 2-wide indents for nested CPP #defines
503 try hard not to exceed 79-columns
504 ANSI C prototypes
505 uncuddled elses and "K&R" style for indenting control constructs
506 no C++ style (//) comments
507 mark places that need to be revisited with XXX (and revisit often!)
508 opening brace lines up with "if" when conditional spans multiple
509 lines; should be at end-of-line otherwise
510 in function definitions, name starts in column 0 (return value is on
511 previous line)
512 single space after keywords that are followed by parens, no space
513 between function name and following paren
514 avoid assignments in conditionals, but if they're unavoidable, use
515 extra paren, e.g. "if (a && (b = c)) ..."
516 "return foo;" rather than "return(foo);"
517 "if (!foo) ..." rather than "if (foo == FALSE) ..." etc.
518
519=item Testsuite
520
bdaf0bc6 521If your patch changes code (rather than just changing documentation) you
522should also include one or more test cases which illustrate the bug you're
523fixing or validate the new functionality you're adding. In general,
524you should update an existing test file rather than create a new one.
525
0549aefb 526Your testsuite additions should generally follow these guidelines
527(courtesy of Gurusamy Sarathy <gsar@activestate.com>):
a44f43ac 528
529 Know what you're testing. Read the docs, and the source.
530 Tend to fail, not succeed.
531 Interpret results strictly.
532 Use unrelated features (this will flush out bizarre interactions).
533 Use non-standard idioms (otherwise you are not testing TIMTOWTDI).
534 Avoid using hardcoded test numbers whenever possible (the
535 EXPECTED/GOT found in t/op/tie.t is much more maintainable,
536 and gives better failure reports).
537 Give meaningful error messages when a test fails.
538 Avoid using qx// and system() unless you are testing for them. If you
539 do use them, make sure that you cover _all_ perl platforms.
540 Unlink any temporary files you create.
541 Promote unforeseen warnings to errors with $SIG{__WARN__}.
542 Be sure to use the libraries and modules shipped with the version
543 being tested, not those that were already installed.
544 Add comments to the code explaining what you are testing for.
545 Make updating the '1..42' string unnecessary. Or make sure that
546 you update it.
547 Test _all_ behaviors of a given operator, library, or function:
548 - All optional arguments
549 - Return values in various contexts (boolean, scalar, list, lvalue)
550 - Use both global and lexical variables
551 - Don't forget the exceptional, pathological cases.
552
553=back
554
7df2e4bc 555=head1 ACCEPTING A PATCH
556
557If you have received a patch file generated using the above section,
558you should try out the patch.
559
560First we need to create a temporary new branch for these changes and
561switch into it:
562
a9b05323 563 % git checkout -b experimental
7df2e4bc 564
6acba58e 565Patches that were formatted by C<git format-patch> are applied with
566C<git am>:
7df2e4bc 567
2af192ee 568 % git am 0001-Rename-Leon-Brocard-to-Orange-Brocard.patch
7df2e4bc 569 Applying Rename Leon Brocard to Orange Brocard
570
6acba58e 571If just a raw diff is provided, it is also possible use this two-step
572process:
09645c26 573
574 % git apply bugfix.diff
dc3c3040 575 % git commit -a -m "Some fixing" --author="That Guy <that.guy@internets.com>"
09645c26 576
7df2e4bc 577Now we can inspect the change:
578
dc3c3040 579 % git show HEAD
7df2e4bc 580 commit b1b3dab48344cff6de4087efca3dbd63548ab5e2
581 Author: Leon Brocard <acme@astray.com>
582 Date: Fri Dec 19 17:02:59 2008 +0000
583
584 Rename Leon Brocard to Orange Brocard
7df2e4bc 585
7df2e4bc 586 diff --git a/AUTHORS b/AUTHORS
587 index 293dd70..722c93e 100644
588 --- a/AUTHORS
589 +++ b/AUTHORS
590 @@ -541,7 +541,7 @@ Lars Hecking <lhecking@nmrc.ucc.ie>
591 Laszlo Molnar <laszlo.molnar@eth.ericsson.se>
592 Leif Huhn <leif@hale.dkstat.com>
593 Len Johnson <lenjay@ibm.net>
594 -Leon Brocard <acme@astray.com>
595 +Orange Brocard <acme@astray.com>
596 Les Peters <lpeters@aol.net>
597 Lesley Binks <lesley.binks@gmail.com>
598 Lincoln D. Stein <lstein@cshl.org>
599
600If you are a committer to Perl and you think the patch is good, you can
75fb7651 601then merge it into blead then push it out to the main repository:
7df2e4bc 602
603 % git checkout blead
d9847473 604 % git merge experimental
75fb7651 605 % git push
7df2e4bc 606
607If you want to delete your temporary branch, you may do so with:
608
609 % git checkout blead
610 % git branch -d experimental
611 error: The branch 'experimental' is not an ancestor of your current HEAD.
612 If you are sure you want to delete it, run 'git branch -D experimental'.
613 % git branch -D experimental
614 Deleted branch experimental.
b0d36535 615
616=head1 CLEANING A WORKING DIRECTORY
617
6acba58e 618The command C<git clean> can with varying arguments be used as a
dc3c3040 619replacement for C<make clean>.
b0d36535 620
621To reset your working directory to a pristine condition you can do:
622
e0b2b458 623 % git clean -dxf
b0d36535 624
625However, be aware this will delete ALL untracked content. You can use
626
e0b2b458 627 % git clean -Xf
b0d36535 628
6acba58e 629to remove all ignored untracked files, such as build and test
630byproduct, but leave any manually created files alone.
b0d36535 631
0549aefb 632If you only want to cancel some uncommitted edits, you can use C<git
c26da522 633checkout> and give it a list of files to be reverted, or C<git checkout
634-f> to revert them all.
f755e97d 635
636If you want to cancel one or several commits, you can use C<git reset>.
637
d82a90c1 638=head1 BISECTING
639
6acba58e 640C<git> provides a built-in way to determine, with a binary search in
641the history, which commit should be blamed for introducing a given bug.
d82a90c1 642
6acba58e 643Suppose that we have a script F<~/testcase.pl> that exits with C<0>
bdaf0bc6 644when some behaviour is correct, and with C<1> when it's faulty. You need
6acba58e 645an helper script that automates building C<perl> and running the
646testcase:
d82a90c1 647
648 % cat ~/run
649 #!/bin/sh
650 git clean -dxf
a4583001 651
652 # If you get './makedepend: 1: Syntax error: Unterminated quoted
653 # string' when bisecting versions of perl older than 5.9.5 this hack
654 # will work around the bug in makedepend.SH which was fixed in
655 # version 96a8704c. Make sure to comment out `git co makedepend.SH'
656 # below too.
657 git show blead:makedepend.SH > makedepend.SH
658
d82a90c1 659 # If you can use ccache, add -Dcc=ccache\ gcc -Dld=gcc to the Configure line
1d5fe431 660 # if Encode is not needed for the test, you can speed up the bisect by
661 # excluding it from the runs with -Dnoextensions=Encode
c0d1ef72 662 sh Configure -des -Dusedevel -Doptimize="-g"
663 test -f config.sh || exit 125
664 # Correct makefile for newer GNU gcc
665 perl -ni -we 'print unless /<(?:built-in|command)/' makefile x2p/makefile
666 # if you just need miniperl, replace test_prep with miniperl
d7923bfe 667 make test_prep
68814ba4 668 [ -x ./perl ] || exit 125
d82a90c1 669 ./perl -Ilib ~/testcase.pl
c0d1ef72 670 ret=$?
7930c68b 671 [ $ret -gt 127 ] && ret=127
a4583001 672 # git co makedepend.SH
c0d1ef72 673 git clean -dxf
674 exit $ret
d82a90c1 675
6acba58e 676This script may return C<125> to indicate that the corresponding commit
677should be skipped. Otherwise, it returns the status of
678F<~/testcase.pl>.
d82a90c1 679
bdaf0bc6 680You first enter in bisect mode with:
d82a90c1 681
682 % git bisect start
683
6acba58e 684For example, if the bug is present on C<HEAD> but wasn't in 5.10.0,
685C<git> will learn about this when you enter:
d82a90c1 686
687 % git bisect bad
688 % git bisect good perl-5.10.0
689 Bisecting: 853 revisions left to test after this
690
6acba58e 691This results in checking out the median commit between C<HEAD> and
bdaf0bc6 692C<perl-5.10.0>. You can then run the bisecting process with:
d82a90c1 693
694 % git bisect run ~/run
695
696When the first bad commit is isolated, C<git bisect> will tell you so:
697
698 ca4cfd28534303b82a216cfe83a1c80cbc3b9dc5 is first bad commit
699 commit ca4cfd28534303b82a216cfe83a1c80cbc3b9dc5
700 Author: Dave Mitchell <davem@fdisolutions.com>
701 Date: Sat Feb 9 14:56:23 2008 +0000
702
9469eb4a 703 [perl #49472] Attributes + Unknown Error
d82a90c1 704 ...
705
706 bisect run success
707
6acba58e 708You can peek into the bisecting process with C<git bisect log> and
709C<git bisect visualize>. C<git bisect reset> will get you out of bisect
710mode.
d82a90c1 711
6acba58e 712Please note that the first C<good> state must be an ancestor of the
713first C<bad> state. If you want to search for the commit that I<solved>
714some bug, you have to negate your test case (i.e. exit with C<1> if OK
715and C<0> if not) and still mark the lower bound as C<good> and the
716upper as C<bad>. The "first bad commit" has then to be understood as
717the "first commit where the bug is solved".
d82a90c1 718
6acba58e 719C<git help bisect> has much more information on how you can tweak your
720binary searches.
9d68b7ed 721
03050721 722=head1 SUBMITTING A PATCH VIA GITHUB
723
724GitHub is a website that makes it easy to fork and publish projects
725with Git. First you should set up a GitHub account and log in.
726
727Perl's git repository is mirrored on GitHub at this page:
728
45b194c5 729 http://github.com/mirrors/perl/tree/blead
03050721 730
731Visit the page and click the "fork" button. This clones the Perl git
732repository for you and provides you with "Your Clone URL" from which
733you should clone:
734
735 % git clone git@github.com:USERNAME/perl.git perl-github
736
bdaf0bc6 737The same patch as above, using github might look like this:
03050721 738
739 % cd perl-github
edb9e29e 740 % git remote add upstream git://perl5.git.perl.org/perl.git
03050721 741 % git pull upstream blead
742 % git checkout -b orange
743 % perl -pi -e 's{Leon Brocard}{Orange Brocard}' AUTHORS
dc3c3040 744 % git commit -a -m 'Rename Leon Brocard to Orange Brocard'
03050721 745 % git push origin orange
746
747The orange branch has been pushed to GitHub, so you should now send an
64a8e22b 748email (see L</SUBMITTING A PATCH>) with a description of your changes
749and the following information:
03050721 750
751 http://github.com/USERNAME/perl/tree/orange
752 git@github.com:USERNAME/perl.git branch orange
753
c26da522 754=head1 MERGING FROM A BRANCH VIA GITHUB
755
756If someone has provided a branch via GitHub and you are a committer,
5c9c28c6 757you should use the following in your perl-ssh directory:
c26da522 758
759 % git remote add dandv git://github.com/dandv/perl.git
fe442cc0 760 % git fetch dandv
c26da522 761
762Now you can see the differences between the branch and blead:
763
764 % git diff dandv/blead
765
766And you can see the commits:
767
768 % git log dandv/blead
769
770If you approve of a specific commit, you can cherry pick it:
771
2bab0636 772 % git cherry-pick 3adac458cb1c1d41af47fc66e67b49c8dec2323f
773
774Or you could just merge the whole branch if you like it all:
775
776 % git merge dandv/blead
c26da522 777
778And then push back to the repository:
779
780 % git push
781
ce2a8773 782
783=head1 TOPIC BRANCHES AND REWRITING HISTORY
784
785Individual committers should create topic branches under
333f8875 786B<yourname>/B<some_descriptive_name>. Other committers should check
787with a topic branch's creator before making any change to it.
ce2a8773 788
b16add97 789The simplest way to create a remote topic branch that works on all
790versions of git is to push the current head as a new branch on the
791remote, then check it out locally:
792
793 $ branch="$yourname/$some_descriptive_name"
794 $ git push origin HEAD:$branch
795 $ git checkout -b $branch origin/$branch
796
797Users of git 1.7 or newer can do it in a more obvious manner:
798
799 $ branch="$yourname/$some_descriptive_name"
800 $ git checkout -b $branch
801 $ git push origin -u $branch
33e5002f 802
ce2a8773 803If you are not the creator of B<yourname>/B<some_descriptive_name>, you
804might sometimes find that the original author has edited the branch's
805history. There are lots of good reasons for this. Sometimes, an author
333f8875 806might simply be rebasing the branch onto a newer source point.
807Sometimes, an author might have found an error in an early commit which
808they wanted to fix before merging the branch to blead.
ce2a8773 809
333f8875 810Currently the master repository is configured to forbid
811non-fast-forward merges. This means that the branches within can not
812be rebased and pushed as a single step.
ce2a8773 813
333f8875 814The only way you will ever be allowed to rebase or modify the history
815of a pushed branch is to delete it and push it as a new branch under
816the same name. Please think carefully about doing this. It may be
817better to sequentially rename your branches so that it is easier for
818others working with you to cherry-pick their local changes onto the new
819version. (XXX: needs explanation).
ce2a8773 820
821If you want to rebase a personal topic branch, you will have to delete
2699d634 822your existing topic branch and push as a new version of it. You can do
823this via the following formula (see the explanation about C<refspec>'s
824in the git push documentation for details) after you have rebased your
825branch:
826
827 # first rebase
828 $ git checkout $user/$topic
829 $ git fetch
830 $ git rebase origin/blead
831
832 # then "delete-and-push"
833 $ git push origin :$user/$topic
834 $ git push origin $user/$topic
835
836B<NOTE:> it is forbidden at the repository level to delete any of the
333f8875 837"primary" branches. That is any branch matching
838C<m!^(blead|maint|perl)!>. Any attempt to do so will result in git
839producing an error like this:
2699d634 840
841 $ git push origin :blead
842 *** It is forbidden to delete blead/maint branches in this repository
843 error: hooks/update exited with error code 1
844 error: hook declined to update refs/heads/blead
333f8875 845 To ssh://perl5.git.perl.org/perl
2699d634 846 ! [remote rejected] blead (hook declined)
333f8875 847 error: failed to push some refs to 'ssh://perl5.git.perl.org/perl'
2699d634 848
333f8875 849As a matter of policy we do B<not> edit the history of the blead and
850maint-* branches. If a typo (or worse) sneaks into a commit to blead or
851maint-*, we'll fix it in another commit. The only types of updates
852allowed on these branches are "fast-forward's", where all history is
853preserved.
2699d634 854
333f8875 855Annotated tags in the canonical perl.git repository will never be
856deleted or modified. Think long and hard about whether you want to push
857a local tag to perl.git before doing so. (Pushing unannotated tags is
2699d634 858not allowed.)
ce2a8773 859
9469eb4a 860=head1 COMMITTING TO MAINTENANCE VERSIONS
9d68b7ed 861
7f4ffa9d 862Maintenance versions should only be altered to add critical bug fixes.
863
9d68b7ed 864To commit to a maintenance version of perl, you need to create a local
865tracking branch:
866
867 % git checkout --track -b maint-5.005 origin/maint-5.005
868
0549aefb 869This creates a local branch named C<maint-5.005>, which tracks the
870remote branch C<origin/maint-5.005>. Then you can pull, commit, merge
871and push as before.
b0d36535 872
f755e97d 873You can also cherry-pick commits from blead and another branch, by
0549aefb 874using the C<git cherry-pick> command. It is recommended to use the
875B<-x> option to C<git cherry-pick> in order to record the SHA1 of the
876original commit in the new commit message.
f755e97d 877
e8589bfa 878=head1 GRAFTS
879
880The perl history contains one mistake which was not caught in the
ac036724 881conversion: a merge was recorded in the history between blead and
333f8875 882maint-5.10 where no merge actually occurred. Due to the nature of git,
883this is now impossible to fix in the public repository. You can remove
884this mis-merge locally by adding the following line to your
e8589bfa 885C<.git/info/grafts> file:
886
887 296f12bbbbaa06de9be9d09d3dcf8f4528898a49 434946e0cb7a32589ed92d18008aaa1d88515930
888
889It is particularly important to have this graft line if any bisecting
890is done in the area of the "merge" in question.
891
bdaf0bc6 892
893
f755e97d 894=head1 SEE ALSO
895
896The git documentation, accessible via C<git help command>.
0549aefb 897