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