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 | ||
3b8a5fb0 | 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 | |
3b8a5fb0 | 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 | |
3482f01a | 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 | |
11ed6e28 | 70 | git config remote.origin.url ssh://perl5.git.perl.org/perl.git |
d7dd28b6 | 71 | |
184487f0 NC |
72 | You 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 |
77 | It is also possible to keep C<origin> as a git remote, and add a new |
78 | remote for ssh access: | |
f6c12373 | 79 | |
dc3c3040 | 80 | % git remote add camel perl5.git.perl.org:/perl.git |
f6c12373 | 81 | |
6acba58e | 82 | This allows you to update your local repository by pulling from |
f755e97d | 83 | C<origin>, which is faster and doesn't require you to authenticate, and |
6acba58e | 84 | to push your changes back with the C<camel> remote: |
f6c12373 VP |
85 | |
86 | % git fetch camel | |
87 | % git push camel | |
88 | ||
6acba58e LB |
89 | The C<fetch> command just updates the C<camel> refs, as the objects |
90 | themselves should have been fetched when pulling from C<origin>. | |
f6c12373 | 91 | |
3482f01a DK |
92 | =head2 A NOTE ON CAMEL AND DROMEDARY |
93 | ||
94 | The committers have SSH access to the two servers that serve | |
333f8875 VP |
95 | C<perl5.git.perl.org>. One is C<perl5.git.perl.org> itself (I<camel>), |
96 | which is the 'master' repository. The second one is | |
97 | C<users.perl5.git.perl.org> (I<dromedary>), which can be used for | |
98 | general testing and development. Dromedary syncs the git tree from | |
99 | camel every few minutes, you should not push there. Both machines also | |
3482f01a DK |
100 | have a full CPAN mirror in /srv/CPAN, please use this. To share files |
101 | with the general public, dromedary serves your ~/public_html/ as | |
333f8875 | 102 | C<http://users.perl5.git.perl.org/~yourlogin/> |
b47aa495 | 103 | |
3482f01a DK |
104 | These hosts have fairly strict firewalls to the outside. Outgoing, only |
105 | rsync, ssh and git are allowed. For http and ftp, you can use | |
106 | http://webproxy:3128 as proxy. Incoming, the firewall tries to detect | |
107 | attacks and blocks IP addresses with suspicious activity. This | |
108 | sometimes (but very rarely) has false positives and you might get | |
109 | blocked. The quickest way to get unblocked is to notify the admins. | |
110 | ||
111 | These two boxes are owned, hosted, and operated by booking.com. You can | |
112 | reach the sysadmins in #p5p on irc.perl.org or via mail to | |
113 | C<perl5-porters@perl.org> | |
114 | ||
d7dd28b6 LB |
115 | =head1 OVERVIEW OF THE REPOSITORY |
116 | ||
6acba58e LB |
117 | Once you have changed into the repository directory, you can inspect |
118 | it. | |
d7dd28b6 | 119 | |
39219fd3 | 120 | After a clone the repository will contain a single local branch, which |
50eca761 | 121 | will be the current branch as well, as indicated by the asterisk. |
39219fd3 YO |
122 | |
123 | % git branch | |
124 | * blead | |
125 | ||
f755e97d | 126 | Using the -a switch to C<branch> will also show the remote tracking |
6acba58e | 127 | branches 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 |
135 | The branches that begin with "origin" correspond to the "git remote" |
136 | that you cloned from (which is named "origin"). Each branch on the | |
137 | remote will be exactly tracked by theses branches. You should NEVER do | |
138 | work on these remote tracking branches. You only ever do work in a | |
139 | local branch. Local branches can be configured to automerge (on pull) | |
140 | from a designated remote tracking branch. This is the case with the | |
141 | default branch C<blead> which will be configured to merge from the | |
142 | remote tracking branch C<origin/blead>. | |
39219fd3 | 143 | |
d7dd28b6 LB |
144 | You can see recent commits: |
145 | ||
c2cf2042 | 146 | % git log |
d7dd28b6 | 147 | |
6acba58e LB |
148 | And pull new changes from the repository, and update your local |
149 | repository (must be clean first) | |
d7dd28b6 LB |
150 | |
151 | % git pull | |
09081495 | 152 | |
6acba58e LB |
153 | Assuming we are on the branch C<blead> immediately after a pull, this |
154 | command would be more or less equivalent to: | |
39219fd3 YO |
155 | |
156 | % git fetch | |
157 | % git merge origin/blead | |
158 | ||
6acba58e LB |
159 | In fact if you want to update your local repository without touching |
160 | your working directory you do: | |
39219fd3 YO |
161 | |
162 | % git fetch | |
163 | ||
6acba58e LB |
164 | And if you want to update your remote-tracking branches for all defined |
165 | remotes simultaneously you can do | |
39219fd3 YO |
166 | |
167 | % git remote update | |
168 | ||
6acba58e LB |
169 | Neither of these last two commands will update your working directory, |
170 | however both will update the remote-tracking branches in your | |
171 | repository. | |
39219fd3 | 172 | |
09081495 LB |
173 | To switch to another branch: |
174 | ||
175 | % git checkout origin/maint-5.8-dor | |
176 | ||
6051489b NC |
177 | To make a local branch of a remote branch: |
178 | ||
179 | % git checkout -b maint-5.10 origin/maint-5.10 | |
180 | ||
09081495 LB |
181 | To switch back to blead: |
182 | ||
183 | % git checkout blead | |
c2cf2042 | 184 | |
39219fd3 YO |
185 | =head2 FINDING OUT YOUR STATUS |
186 | ||
187 | The most common git command you will use will probably be | |
188 | ||
189 | % git status | |
190 | ||
6acba58e LB |
191 | This command will produce as output a description of the current state |
192 | of the repository, including modified files and unignored untracked | |
193 | files, and in addition it will show things like what files have been | |
194 | staged for the next commit, and usually some useful information about | |
195 | how 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 |
216 | This shows that there were changes to this document staged for commit, |
217 | and that there were further changes in the working directory not yet | |
218 | staged. It also shows that there was an untracked file in the working | |
219 | directory, and as you can see shows how to change all of this. It also | |
0549aefb LB |
220 | shows that there is one commit on the working branch C<blead> which has |
221 | not been pushed to the C<origin> remote yet. B<NOTE>: that this output | |
222 | is also what you see as a template if you do not provide a message to | |
223 | C<git commit>. | |
7f6effc7 | 224 | |
bdaf0bc6 JV |
225 | Assuming that you'd like to commit all the changes you've just made as a |
226 | a 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 |
231 | New 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 | |
233 | changes, have a look at the documentation for C<git add>.) | |
bdaf0bc6 | 234 | |
e9360695 | 235 | Git will start up your favorite text editor, so that you can craft a |
bdaf0bc6 JV |
236 | commit message for your change. See L</Commit message> below for more |
237 | information about what makes a good commit message. | |
238 | ||
239 | Once you've finished writing your commit message and exited your editor, | |
240 | git 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 | |
246 | If 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 |
259 | When in doubt, before you do anything else, check your status and read |
260 | it carefully, many questions are answered directly by the git status | |
261 | output. | |
39219fd3 | 262 | |
c2cf2042 LB |
263 | =head1 SUBMITTING A PATCH |
264 | ||
265 | If you have a patch in mind for Perl, you should first get a copy of | |
266 | the repository: | |
267 | ||
268 | % git clone git://perl5.git.perl.org/perl.git perl-git | |
269 | ||
270 | Then change into the directory: | |
271 | ||
272 | % cd perl-git | |
273 | ||
6acba58e LB |
274 | Alternatively, if you already have a Perl repository, you should ensure |
275 | that 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 |
280 | It's preferable to patch against the latest blead version, since this |
281 | is where new development occurs for all changes other than critical bug | |
282 | fixes. Critical bug fix patches should be made against the relevant | |
7f4ffa9d RS |
283 | maint branches, or should be submitted with a note indicating all the |
284 | branches where the fix should be applied. | |
a44f43ac | 285 | |
6acba58e LB |
286 | Now that we have everything up to date, we need to create a temporary |
287 | new branch for these changes and switch into it: | |
b1fccde5 | 288 | |
a9b05323 | 289 | % git checkout -b orange |
23f8d33e | 290 | |
a9b05323 YO |
291 | which is the short form of |
292 | ||
b1fccde5 LB |
293 | % git branch orange |
294 | % git checkout orange | |
295 | ||
c2cf2042 LB |
296 | Then make your changes. For example, if Leon Brocard changes his name |
297 | to Orange Brocard, we should change his name in the AUTHORS file: | |
298 | ||
299 | % perl -pi -e 's{Leon Brocard}{Orange Brocard}' AUTHORS | |
300 | ||
301 | You 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 |
311 | And 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 | ||
328 | Now 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 |
334 | You can examine your last commit with: |
335 | ||
336 | % git show HEAD | |
337 | ||
338 | and if you are not happy with either the description or the patch | |
c26da522 | 339 | itself 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 |
343 | Now 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 | ||
348 | You should now send an email to perl5-porters@perl.org with a | |
dc3c3040 | 349 | description of your changes, and include this patch file as an |
333f8875 VP |
350 | attachment. (See the next section for how to configure and use git to |
351 | send these emails for you.) | |
c2cf2042 | 352 | |
b1fccde5 LB |
353 | If 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 |
364 | In your ~/git/perl repository, set the destination email to the |
365 | perl5-porters mailing list. | |
2d5f1d01 DG |
366 | |
367 | $ git config sendemail.to perl5-porters@perl.org | |
368 | ||
369 | Then 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 |
373 | You may need to set some configuration variables for your particular |
374 | email service provider. For example, to set your global git config to | |
375 | send 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 |
381 | With this configuration, you will be prompted for your gmail password |
382 | when you run 'git send-email'. You can also configure | |
383 | C<sendemail.smtppass> with your password if you don't care about having | |
384 | your password in the .gitconfig file. | |
2d5f1d01 | 385 | |
a44f43ac RGS |
386 | =head2 A note on derived files |
387 | ||
388 | Be aware that many files in the distribution are derivative--avoid | |
0549aefb LB |
389 | patching them, because git won't see the changes to them, and the build |
390 | process will overwrite them. Patch the originals instead. Most | |
391 | utilities (like perldoc) are in this category, i.e. patch | |
392 | utils/perldoc.PL rather than utils/perldoc. Similarly, don't create | |
393 | patches 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 | |
395 | file that may have gotten copied while building the source | |
396 | distribution, consult the C<MANIFEST>. | |
a44f43ac | 397 | |
ac1cbfb0 JC |
398 | As a special case, several files are regenerated by 'make regen' if |
399 | your patch alters C<embed.fnc>. These are needed for compilation, but | |
400 | are included in the distribution so that you can build perl without | |
401 | needing another perl to generate the files. You must test with these | |
402 | regenerated files, but it is preferred that you instead note that | |
403 | 'make regen is needed' in both the email and the commit message, and | |
404 | submit your patch without them. If you're submitting a series of | |
405 | patches, it might be best to submit the regenerated changes | |
406 | immediately after the source-changes that caused them, so as to have | |
407 | as little effect as possible on the bisectability of your patchset. | |
408 | ||
6e2cec71 | 409 | =for XXX |
a44f43ac | 410 | |
6e2cec71 | 411 | What should we recommend about binary files now? Do we need anything? |
a44f43ac RGS |
412 | |
413 | =head2 Getting your patch accepted | |
414 | ||
bdaf0bc6 | 415 | If you are submitting a code patch there are several things that |
a44f43ac RGS |
416 | you need to do. |
417 | ||
418 | =over 4 | |
419 | ||
bdaf0bc6 JV |
420 | =item Commit message |
421 | ||
422 | As you craft each patch you intend to submit to the Perl core, it's | |
423 | important to write a good commit message. | |
424 | ||
425 | Your commit message should start with a description of the problem that | |
426 | the patch corrects or new functionality that the patch adds. | |
427 | ||
bdaf0bc6 JV |
428 | As a general rule of thumb, your commit message should let a programmer |
429 | with a reasonable familiarity with the Perl core quickly understand what | |
430 | you were trying to do, how you were trying to do it and why the change | |
431 | matters to Perl. | |
432 | ||
433 | =over 4 | |
434 | ||
435 | =item What | |
436 | ||
ac1cbfb0 JC |
437 | Your commit message should describe what part of the Perl core you're |
438 | changing and what you expect your patch to do. | |
bdaf0bc6 JV |
439 | |
440 | =item Why | |
441 | ||
442 | Perhaps most importantly, your commit message should describe why the | |
443 | change you are making is important. When someone looks at your change | |
444 | in six months or six years, your intent should be clear. If you're | |
445 | deprecating a feature with the intent of later simplifying another bit | |
446 | of code, say so. If you're fixing a performance problem or adding a new | |
447 | feature to support some other bit of the core, mention that. | |
448 | ||
449 | =item How | |
450 | ||
451 | While it's not necessary for documentation changes, new tests or | |
452 | trivial patches, it's often worth explaining how your change works. | |
453 | Even if it's clear to you today, it may not be clear to a porter next | |
454 | month or next year. | |
455 | ||
456 | =back | |
457 | ||
ea9c0d74 JV |
458 | A commit message isn't intended to take the place of comments in your |
459 | code. Commit messages should describe the change you made, while code | |
80a0006a JV |
460 | comments should describe the current state of the code. If you've just |
461 | implemented a new feature, complete with doc, tests and well-commented | |
462 | code, a brief commit message will often suffice. If, however, you've | |
463 | just changed a single character deep in the parser or lexer, you might | |
ea9c0d74 JV |
464 | need to write a small novel to ensure that future readers understand |
465 | what you did and why you did it. | |
466 | ||
a44f43ac RGS |
467 | =item Comments, Comments, Comments |
468 | ||
0549aefb LB |
469 | Be sure to adequately comment your code. While commenting every line |
470 | is unnecessary, anything that takes advantage of side effects of | |
a44f43ac | 471 | operators, that creates changes that will be felt outside of the |
0549aefb LB |
472 | function being patched, or that others may find confusing should be |
473 | documented. If you are going to err, it is better to err on the side | |
474 | of adding too many comments than too few. | |
a44f43ac RGS |
475 | |
476 | =item Style | |
477 | ||
0549aefb LB |
478 | In general, please follow the particular style of the code you are |
479 | patching. | |
a44f43ac | 480 | |
0549aefb LB |
481 | In particular, follow these general guidelines for patching Perl |
482 | sources: | |
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 |
504 | If your patch changes code (rather than just changing documentation) you |
505 | should also include one or more test cases which illustrate the bug you're | |
506 | fixing or validate the new functionality you're adding. In general, | |
507 | you should update an existing test file rather than create a new one. | |
508 | ||
0549aefb LB |
509 | Your 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 | ||
540 | If you have received a patch file generated using the above section, | |
541 | you should try out the patch. | |
542 | ||
543 | First we need to create a temporary new branch for these changes and | |
544 | switch into it: | |
545 | ||
a9b05323 | 546 | % git checkout -b experimental |
7df2e4bc | 547 | |
6acba58e LB |
548 | Patches that were formatted by C<git format-patch> are applied with |
549 | C<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 |
554 | If just a raw diff is provided, it is also possible use this two-step |
555 | process: | |
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 |
560 | Now 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 | ||
583 | If you are a committer to Perl and you think the patch is good, you can | |
75fb7651 | 584 | then 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 | |
590 | If 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 | 601 | The command C<git clean> can with varying arguments be used as a |
dc3c3040 | 602 | replacement for C<make clean>. |
b0d36535 YO |
603 | |
604 | To reset your working directory to a pristine condition you can do: | |
605 | ||
606 | git clean -dxf | |
607 | ||
608 | However, be aware this will delete ALL untracked content. You can use | |
609 | ||
610 | git clean -Xf | |
611 | ||
6acba58e LB |
612 | to remove all ignored untracked files, such as build and test |
613 | byproduct, but leave any manually created files alone. | |
b0d36535 | 614 | |
0549aefb | 615 | If you only want to cancel some uncommitted edits, you can use C<git |
c26da522 LB |
616 | checkout> and give it a list of files to be reverted, or C<git checkout |
617 | -f> to revert them all. | |
f755e97d RGS |
618 | |
619 | If you want to cancel one or several commits, you can use C<git reset>. | |
620 | ||
d82a90c1 VP |
621 | =head1 BISECTING |
622 | ||
6acba58e LB |
623 | C<git> provides a built-in way to determine, with a binary search in |
624 | the history, which commit should be blamed for introducing a given bug. | |
d82a90c1 | 625 | |
6acba58e | 626 | Suppose that we have a script F<~/testcase.pl> that exits with C<0> |
bdaf0bc6 | 627 | when some behaviour is correct, and with C<1> when it's faulty. You need |
6acba58e LB |
628 | an helper script that automates building C<perl> and running the |
629 | testcase: | |
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 |
650 | This script may return C<125> to indicate that the corresponding commit |
651 | should be skipped. Otherwise, it returns the status of | |
652 | F<~/testcase.pl>. | |
d82a90c1 | 653 | |
bdaf0bc6 | 654 | You first enter in bisect mode with: |
d82a90c1 VP |
655 | |
656 | % git bisect start | |
657 | ||
6acba58e LB |
658 | For example, if the bug is present on C<HEAD> but wasn't in 5.10.0, |
659 | C<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 | 665 | This results in checking out the median commit between C<HEAD> and |
bdaf0bc6 | 666 | C<perl-5.10.0>. You can then run the bisecting process with: |
d82a90c1 VP |
667 | |
668 | % git bisect run ~/run | |
669 | ||
670 | When 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 |
682 | You can peek into the bisecting process with C<git bisect log> and |
683 | C<git bisect visualize>. C<git bisect reset> will get you out of bisect | |
684 | mode. | |
d82a90c1 | 685 | |
6acba58e LB |
686 | Please note that the first C<good> state must be an ancestor of the |
687 | first C<bad> state. If you want to search for the commit that I<solved> | |
688 | some bug, you have to negate your test case (i.e. exit with C<1> if OK | |
689 | and C<0> if not) and still mark the lower bound as C<good> and the | |
690 | upper as C<bad>. The "first bad commit" has then to be understood as | |
691 | the "first commit where the bug is solved". | |
d82a90c1 | 692 | |
6acba58e LB |
693 | C<git help bisect> has much more information on how you can tweak your |
694 | binary searches. | |
9d68b7ed | 695 | |
03050721 LB |
696 | =head1 SUBMITTING A PATCH VIA GITHUB |
697 | ||
698 | GitHub is a website that makes it easy to fork and publish projects | |
699 | with Git. First you should set up a GitHub account and log in. | |
700 | ||
701 | Perl's git repository is mirrored on GitHub at this page: | |
702 | ||
703 | http://github.com/github/perl/tree/blead | |
704 | ||
705 | Visit the page and click the "fork" button. This clones the Perl git | |
706 | repository for you and provides you with "Your Clone URL" from which | |
707 | you should clone: | |
708 | ||
709 | % git clone git@github.com:USERNAME/perl.git perl-github | |
710 | ||
bdaf0bc6 | 711 | The 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 | ||
721 | The orange branch has been pushed to GitHub, so you should now send an | |
722 | email to perl5-porters@perl.org with a description of your changes and | |
723 | the 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 | ||
730 | If someone has provided a branch via GitHub and you are a committer, | |
5c9c28c6 | 731 | you 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 | ||
736 | Now you can see the differences between the branch and blead: | |
737 | ||
738 | % git diff dandv/blead | |
739 | ||
740 | And you can see the commits: | |
741 | ||
742 | % git log dandv/blead | |
743 | ||
744 | If you approve of a specific commit, you can cherry pick it: | |
745 | ||
2bab0636 LB |
746 | % git cherry-pick 3adac458cb1c1d41af47fc66e67b49c8dec2323f |
747 | ||
748 | Or you could just merge the whole branch if you like it all: | |
749 | ||
750 | % git merge dandv/blead | |
c26da522 LB |
751 | |
752 | And then push back to the repository: | |
753 | ||
754 | % git push | |
755 | ||
ce2a8773 JV |
756 | |
757 | =head1 TOPIC BRANCHES AND REWRITING HISTORY | |
758 | ||
759 | Individual committers should create topic branches under | |
333f8875 VP |
760 | B<yourname>/B<some_descriptive_name>. Other committers should check |
761 | with a topic branch's creator before making any change to it. | |
ce2a8773 JV |
762 | |
763 | If you are not the creator of B<yourname>/B<some_descriptive_name>, you | |
764 | might sometimes find that the original author has edited the branch's | |
765 | history. There are lots of good reasons for this. Sometimes, an author | |
333f8875 VP |
766 | might simply be rebasing the branch onto a newer source point. |
767 | Sometimes, an author might have found an error in an early commit which | |
768 | they wanted to fix before merging the branch to blead. | |
ce2a8773 | 769 | |
333f8875 VP |
770 | Currently the master repository is configured to forbid |
771 | non-fast-forward merges. This means that the branches within can not | |
772 | be rebased and pushed as a single step. | |
ce2a8773 | 773 | |
333f8875 VP |
774 | The only way you will ever be allowed to rebase or modify the history |
775 | of a pushed branch is to delete it and push it as a new branch under | |
776 | the same name. Please think carefully about doing this. It may be | |
777 | better to sequentially rename your branches so that it is easier for | |
778 | others working with you to cherry-pick their local changes onto the new | |
779 | version. (XXX: needs explanation). | |
ce2a8773 JV |
780 | |
781 | If you want to rebase a personal topic branch, you will have to delete | |
2699d634 YO |
782 | your existing topic branch and push as a new version of it. You can do |
783 | this via the following formula (see the explanation about C<refspec>'s | |
784 | in the git push documentation for details) after you have rebased your | |
785 | branch: | |
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 | ||
796 | B<NOTE:> it is forbidden at the repository level to delete any of the | |
333f8875 VP |
797 | "primary" branches. That is any branch matching |
798 | C<m!^(blead|maint|perl)!>. Any attempt to do so will result in git | |
799 | producing 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 |
809 | As a matter of policy we do B<not> edit the history of the blead and |
810 | maint-* branches. If a typo (or worse) sneaks into a commit to blead or | |
811 | maint-*, we'll fix it in another commit. The only types of updates | |
812 | allowed on these branches are "fast-forward's", where all history is | |
813 | preserved. | |
2699d634 | 814 | |
333f8875 VP |
815 | Annotated tags in the canonical perl.git repository will never be |
816 | deleted or modified. Think long and hard about whether you want to push | |
817 | a local tag to perl.git before doing so. (Pushing unannotated tags is | |
2699d634 | 818 | not allowed.) |
ce2a8773 | 819 | |
9469eb4a | 820 | =head1 COMMITTING TO MAINTENANCE VERSIONS |
9d68b7ed | 821 | |
7f4ffa9d RS |
822 | Maintenance versions should only be altered to add critical bug fixes. |
823 | ||
9d68b7ed LB |
824 | To commit to a maintenance version of perl, you need to create a local |
825 | tracking branch: | |
826 | ||
827 | % git checkout --track -b maint-5.005 origin/maint-5.005 | |
828 | ||
0549aefb LB |
829 | This creates a local branch named C<maint-5.005>, which tracks the |
830 | remote branch C<origin/maint-5.005>. Then you can pull, commit, merge | |
831 | and push as before. | |
b0d36535 | 832 | |
f755e97d | 833 | You can also cherry-pick commits from blead and another branch, by |
0549aefb LB |
834 | using the C<git cherry-pick> command. It is recommended to use the |
835 | B<-x> option to C<git cherry-pick> in order to record the SHA1 of the | |
836 | original commit in the new commit message. | |
f755e97d | 837 | |
e8589bfa AV |
838 | =head1 GRAFTS |
839 | ||
840 | The perl history contains one mistake which was not caught in the | |
ac036724 | 841 | conversion: a merge was recorded in the history between blead and |
333f8875 VP |
842 | maint-5.10 where no merge actually occurred. Due to the nature of git, |
843 | this is now impossible to fix in the public repository. You can remove | |
844 | this mis-merge locally by adding the following line to your | |
e8589bfa AV |
845 | C<.git/info/grafts> file: |
846 | ||
847 | 296f12bbbbaa06de9be9d09d3dcf8f4528898a49 434946e0cb7a32589ed92d18008aaa1d88515930 | |
848 | ||
849 | It is particularly important to have this graft line if any bisecting | |
850 | is done in the area of the "merge" in question. | |
851 | ||
bdaf0bc6 JV |
852 | |
853 | ||
f755e97d RGS |
854 | =head1 SEE ALSO |
855 | ||
856 | The git documentation, accessible via C<git help command>. | |
0549aefb | 857 |