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