This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
threads - miscellaneous
[perl5.git] / Porting / repository.pod
1 =head1 NAME
2
3 repository - Using the Perl repository
4
5 =head1 Synopsis
6
7 First, we assume here that you have already decided that you will
8 need B<write> access to the repository.  If all you need is B<read>
9 access, there are much better ways to access the most current state of
10 the perl repository, or explore individual files and patches therein.
11 See L<perlhack> for details.
12
13 This document describes what a Perl Porter needs to do to start using
14 the Perl repository.
15
16 =head1 Prerequisites
17
18 You'll need to get hold of the following software.
19
20 =over 4
21
22 =item Perforce
23
24 Download a perforce client from:
25
26    http://www.perforce.com/perforce/loadprog.html
27
28 You'll probably also want to look at:
29
30    http://www.perforce.com/perforce/technical.html
31
32 where you can look at or download its documentation.
33
34 =item ssh
35
36 If you don't already have access to an ssh client, then look at its
37 home site C<http://www.cs.hut.fi/ssh> which mentions ftp sites from
38 which it's available. You only need to build the client parts (ssh
39 and ssh-keygen should suffice).
40
41 If you're on Windows then you might like to obtain Cygwin from:
42
43     http://cygwin.com/
44
45 which contains an ssh client.  (MSYS also contains an ssh client
46 but it seems to time-out and disconnect from the server and doesn't
47 understand the ServerAliveInterval setting described later that can
48 be used to stop Cygwin's ssh client from doing this.)
49
50 Alternatively, the "plink" program, part of PuTTY:
51
52     http://www.chiark.greenend.org.uk/~sgtatham/putty/
53
54 should also work fine for Windows users.
55
56 =back
57
58 =head1 Creating an SSH Key Pair
59
60 If you already use ssh and want to use the same key pair for perl
61 repository access then you can skip the rest of this section.
62 Otherwise, generate an ssh key pair for use with the repository
63 by typing the command
64
65     ssh-keygen
66
67 After generating a key pair and testing it, ssh-keygen will ask you
68 to enter a filename in which to save the key. The default it offers
69 will be the file F<~/.ssh/identity> which is suitable unless you
70 particularly want to keep separate ssh identities for some reason.
71 If so, you could save the perl repository private key in the file
72 F<~/.ssh/perl>, for example, but I will use the standard filename
73 in the remainder of the examples of this document.
74
75 After typing in the filename, it will prompt you to type in a
76 passphrase. The private key will itself be encrypted so that it is
77 usable only when that passphrase is typed. (When using ssh, you will
78 be prompted when it requires a pass phrase to unlock a private key.)
79 If you provide a blank passphrase then no passphrase will be needed
80 to unlock the key and, as a consequence, anyone who gains access to
81 the key file gains access to accounts protected with that key
82 (barring additional configuration to restrict access by IP address).
83
84 When you have typed the passphrase in twice, ssh-keygen will confirm
85 where it has saved the private key (in the filename you gave and
86 with permissions set to be only readable by you), what your public
87 key is (don't worry: you don't need to memorise it) and where it
88 has saved the corresponding public key. The public key is saved in
89 a filename corresponding to your private key's filename but with
90 ".pub" appended, usually F<~/.ssh/identity.pub>. That public key
91 can be (but need not be) world readable. It is not used by your
92 own system at all.
93
94 Note that the above process creates a key pair for ssh protocol 1.
95 You can request ssh protocol 2 (RSA) instead if you prefer (if your
96 particular ssh client supports it), via the command
97
98     ssh-keygen -t rsa
99
100 This will create private/public identity files called F<~/.ssh/id_rsa>
101 and F<~/.ssh/id_rsa.pub> respectively.  Protocol 2 offers a higher
102 level of security than protocol 1.  This is not required for access to
103 the Perl repository -- ssh is used for authentication rather than
104 encryption (the Perl sources are open anyway) -- but either protocol
105 is supported by the server.
106
107 B<IMPORTANT NOTE FOR CYGWIN USERS:>  In order to make the private key
108 files only readable by you you must include the string "ntea" in the
109 "CYGWIN" environment variable in the shell used to run C<chmod(1)>,
110 and in the shell used to run the ssh client itself later.  If "CYGWIN"
111 doesn't contain "ntea" then it will appear to the ssh client that the
112 file permissions are not set correctly, in which case the files will be
113 ignored and you won't be able to connect.
114
115 =head1 Notifying the Repository Keeper
116
117 Mail the contents of that public key file to the keeper of the perl
118 repository (see L</Contact Information> below).
119 When the key is added to the repository host's configuration file,
120 you will be able to connect to it with ssh by using the corresponding
121 private key file (after unlocking it with your chosen passphrase).
122
123 There is no harm in creating both protocol 1 and protocol 2 keys and
124 mailing them both in.  That way you'll be able to connect using either
125 protocol, which may be useful if you later find yourself using a client
126 that only supports one or the other protocol.
127
128 =head1 Connecting to the Repository
129
130 Connections to the repository are made by using ssh to provide a
131 TCP "tunnel" rather than by using ssh to login to or invoke any
132 ordinary commands on the repository.
133
134 The ssh (secure shell) protocol runs over port number 22, so if you
135 have a firewall installed at the client end then you must ensure that
136 it is configured to allow you to make an outgoing connection to port 22
137 on sickle.activestate.com.
138
139 When you want to start a session using the repository, use the command:
140
141     ssh -l perlrep -f -q -x -L 1666:127.0.0.1:1666 sickle.activestate.com foo
142
143 If you are not using the default filename of F<~/.ssh/identity> or
144 F<~/.ssh/id_rsa> to hold your perl repository private key then you'll
145 need to add the option B<-i filename> to tell ssh where it is. Unless
146 you chose a blank passphrase for that private key, ssh will prompt you
147 for the passphrase to unlock that key. Then ssh will fork and put itself
148 in the background, returning you (silently) to your shell prompt.
149
150 Note that the first time you connect you may see a message like
151 "The authenticity of host 'sickle.activestate.com' can't be established,"
152 and asking you if you want to continue.  Just answer yes and sickle's
153 details will be cached in a F<known_hosts> or F<known_hosts2> file.  You
154 will not see that message again unless you delete the cache file.
155
156 The tunnel for repository access is now ready for use.
157
158 For the sake of completeness (and for the case where the chosen
159 port of 1666 is already in use on your machine), I'll briefly
160 describe what all those ssh arguments are for.
161
162 =over 4
163
164 =item B<-l perlrep>
165
166 Use a remote username of perlrep. (The account on the repository which
167 provides the end-point of the ssh tunnel is named "perlrep".)
168
169 =item B<-f>
170
171 Tells ssh to fork and remain running in the background. Since ssh
172 is only being used for its tunnelling capabilities, the command
173 that ssh runs never does any I/O and can sit silently in the
174 background.
175
176 =item B<-q>
177
178 Tells ssh to be quiet. Without this option, ssh will output a
179 message each time you use a p4 command (since each p4 command
180 tunnels over the ssh connection to reach the repository).
181
182 =item B<-x>
183
184 Tells ssh not to bother to set up a tunnel for X11 connections.
185 The repository doesn't allow this anyway.
186
187 =item B<-L 1666:127.0.0.1:1666>
188
189 This is the important option. It tells ssh to listen out for
190 connections made to port 1666 on your local machine. When such
191 a connection is made, the ssh client tells the remote side
192 (the corresponding ssh daemon on the repository) to make a
193 connection to IP address 127.0.0.1, port 1666. Data flowing
194 along that connection is tunnelled over the ssh connection
195 (encrypted). The perforce daemon running on the repository
196 only accepts connections from localhost and that is exactly
197 where ssh-tunnelled connections appear to come from.
198
199 If port 1666 is already in use on your machine then you can
200 choose any non-privileged port (a number between 1024 and 65535)
201 which happens to be free on your machine. It's the first of the
202 three colon separated values that you should change. Picking
203 port 2345 would mean changing the option to
204 B<-L 2345:127.0.0.1:1666>. Whatever port number you choose should
205 be used for the value of the P4PORT environment variable (q.v.).
206
207 =item sickle.activestate.com
208
209 This is the canonical name of the host on which the perl repository
210 resides.
211
212 =item foo
213
214 This is a dummy place holder argument. Without an argument
215 here, ssh will try to perform an interactive login to the
216 repository which is not allowed. Ordinarily, this argument
217 is for the one-off command which is to be executed on the
218 remote host. However, the repository's ssh configuration
219 file uses the "command=" option to force a particular
220 command to run so the actual value of the argument is
221 ignored. The command that's actually run merely pauses and
222 waits for the ssh connection to drop, then exits.
223
224 =back
225
226 =head1 Problems
227
228 You should normally get a prompt that asks for the passphrase
229 for your RSA key when you connect with the ssh command shown
230 above.  If you see a prompt that looks like:
231
232     perlrep@sickle.activestate.com's password:
233
234 Then you either don't have a F<~/.ssh/identity> or F<~/.ssh/id_rsa>
235 file corresponding to your public key, or that file is not readable.
236 Fix the problem and try again.
237
238 If you only had the public key file for one protocol installed at the
239 server end then make sure your client is using the corresponding
240 protocol.  An ssh client that supports protocol 2 will probably choose
241 that by default, which will fail if the server end only has your public
242 key file for protocol 1.  Some ssh clients have "-1" and "-2" arguments
243 to force which protocol to use.
244
245 The "-v" (verbose) flag can be useful for seeing what protocol your
246 client is actually trying to connect with, and for spotting any other
247 problems.  The flag can be specified multiple times to increase
248 verbosity.  Note that specifying the "-q" flag as well might override
249 your request for verbose output, so drop the "-q" flag when trying this.
250
251 If you're using the Cygwin ssh client on Windows then you will probably
252 find that the connection times out after a short period of inactivity.
253 You will have to keep re-entering your passphrase to reconnect, which
254 gets annoying after a while.  In order to prevent these time-outs from
255 happening place the following two lines in the file F<~/.ssh/config>:
256
257         Host sickle.activestate.com
258         ServerAliveInterval 120
259
260 This causes the ssh client to send a message to the server every 120
261 seconds to check that the server is still alive.  The client will not
262 disconnect unless "ServerAliveCountMax" many of these messages go
263 unanswered.  Run C<man ssh_config> for more details.  Note also that
264 this option applies to protocol version 2 only.
265
266 =head1 Using the Perforce Client
267
268 Remember to read the documentation for Perforce. You need
269 to make sure that three environment variable are set
270 correctly before using the p4 client with the perl repository.
271
272 =over 4
273
274 =item P4PORT
275
276 Set this to localhost:1666 (the port for your ssh client to listen on)
277 unless that port is already in use on your host. If it is, see
278 the section above on the B<-L 1666:127.0.0.1:1666> option to ssh.
279
280 =item P4CLIENT
281
282 The value of this is the name by which Perforce knows your
283 host's workspace. You need to pick a name (normally, your
284 Perforce username, a dash, and your host's short name)
285 when you first start using the perl repository and then
286 stick with it.
287
288 Perforce keeps track of the files you have on your machine.  It
289 does this through your client. When you first sync a version of a
290 file, the file comes from the server to your machine.  If you sync
291 the same file again the server does nothing because it
292 knows you already have the file.
293
294 You should NOT use the same client on different machines.  If you do
295 you probably won't get the files you expect, and may end up with
296 nasty corruption.  Perforce allows you to have as many clients as
297 you want. For example, sally-home, sally-openbsd, sally-laptop.
298
299 Also, never change the client's root and view at the same time.
300 See C<http://www.perforce.com/perforce/doc.002/manuals/p4guide/04_details.html#1048341>
301
302 If you have multiple hosts sharing the same directory structure
303 via NFS then you may be able to get away with only one client name,
304 but be careful.
305
306 The C<p4 clients> command lists all currently known clients.
307
308 =item P4USER
309
310 This is the username by which perforce knows you. Use your
311 username if you have a well known or obvious one or else pick
312 a new one which other perl5-porters will recognise. There is
313 a licence limit on the number of these usernames, so be sure not
314 to use more than one.
315
316 It is very important to set a password for your Perforce username,
317 or else anyone can impersonate you.  Use the C<p4 passwd> command
318 to do this.  Once a password is set for your account, you'll need
319 to tell Perforce what it is. You can do this by setting the
320 environment variable P4PASSWD, or you can use the C<-P> flag
321 with the C<p4> command.
322
323 There are a few techniques you can use to avoid having to either
324 set an environment variable or type the password on every command.
325 One is to create a shell alias, for example, in bash, add something like
326     alias p4='p4 -P secret'
327 to your F<.bash_profile> file.  Another way is to create a small shell
328 script, for example
329     #!/bin/bash
330     p4 -P secret $@
331 And use this instead of running C<p4> directly.
332
333 With either of these, be sure the file containing your password
334 (the F<.bash_profile> or shell script file) is only readable by you.
335
336 The C<p4 users> command lists all currently known users.
337
338 =back
339
340 Note that on Windows P4PORT and P4USER are requested when installing
341 Perforce.  They are stored in the registry, so they do not need to be
342 set in the environment.
343
344 Once these three environment variables are set, you can use the
345 perforce p4 client exactly as described in its documentation.
346
347 After setting these variables and connecting to the repository
348 for the first time, you should use the C<p4 user> command to
349 set a valid email address for yourself.  Messages to the commit list
350 are sent (faked) from whatever email address you set here.
351
352 Also use the C<p4 client> command to specify your workspace
353 specifications for each individual client from which you will interact
354 with the repository.  The P4CLIENT environment variable, of course,
355 needs to be set to one of these client workspace names.
356
357 =head1 Ending a Repository Session
358
359 When you have finished a session using the repository, you
360 should kill off the ssh client process to break the tunnel.
361 Since ssh forked itself into the background, you'll need to use
362 something like ps with the appropriate options to find the ssh
363 process and then kill it manually. The default signal of
364 SIGTERM is fine.
365
366 =head1 Overview of the Repository
367
368 Please read at least the introductory sections of the Perforce
369 User Guide (and perhaps the Quick Start Guide as well) before
370 reading this section.
371
372 Every repository user typically "owns" a "branch" of the mainline
373 code in the repository.  They hold the "pumpkin" for things in this
374 area, and are usually the only user who will modify files there.
375 This is not strictly enforced in order to allow the flexibility
376 of other users stealing the pumpkin for short periods with the
377 owner's permission.
378
379 Here is (part of) the current structure of the repository:
380
381     /----+-----perl                  - Mainline development (bleadperl)
382          +-----perlio                - PerlIO Pumpkin's Perl
383          +-----vmsperl               - VMS Pumpkin's Perl
384          +-----maint-5.004------perl - Maintenance branches
385          +-----maint-5.005------perl
386          +-----maint-5.6--------perl
387          +-----maint-5.8--------perl
388          +-----pureperl---------pureperl
389
390 Perforce uses a branching model that simply tracks relationships
391 between files.  It does not care about directories at all, so
392 any file can be a branch of any other file--the fully qualified
393 depot path name (of the form //depot/foo/bar.c) uniquely determines
394 a file for the purpose of establishing branching relationships.
395 Since a branch usually involves hundreds of files, such relationships
396 are typically specified en masse using a branch map (try `p4 help branch`).
397 `p4 branches` lists the existing branches that have been set up.
398 `p4 branch -o branchname` can be used to view the map for a particular
399 branch, if you want to determine the ancestor for a particular set of
400 files.
401
402 The mainline (aka "trunk") code in the Perl repository is under
403 "//depot/perl/...".  Most branches typically map its entire
404 contents under a directory that goes by the same name as the branch
405 name.  Thus the contents of the perlio branch are to be found
406 in //depot/perlio.
407
408 Run `p4 client` to specify how the repository contents should map to
409 your local disk.  Most users will typically have a client map that
410 includes at least their entire branch and the contents of the mainline.
411
412 Run `p4 changes -l -m10` to check on the activity in the repository.
413 //depot/perl/Porting/genlog is useful to get an annotated changelog
414 that shows files and branches.  You can use this listing to determine
415 if there are any changes in the mainline that you need to merge into
416 your own branch.  A typical merging session looks like this:
417
418     % cd ~/p4view/perlio
419     % p4 integrate -b perlio     # to bring parent changes into perlio
420     % p4 resolve -am ./...        # auto merge the changes
421     % p4 resolve ./...           # manual merge conflicting changes
422     % p4 submit ./...            # check in
423
424 If the owner of the mainline wants to bring the changes in perlio
425 back into the mainline, they do:
426
427     % p4 integrate -r -b perlio
428     ...
429
430 Generating a patch for change#42 is done as follows:
431
432     % p4genpatch 42 > change-42.patch
433
434 F<p4genpatch> is to be found in //depot/perl/Porting/.
435
436 The usual routine to apply a patch is
437
438     % p4 edit file.c file.h
439     % patch < patch.txt
440
441 (any necessary, re-Configure, make regen_headers, make clean, etc, here)
442
443     % make all test
444
445 (preferably make all test in several platforms and under several
446 different Configurations)
447
448     % while unhappy
449     do
450       $EDITOR
451       make all test
452     done
453     % p4 submit
454
455 Other useful Perforce commands
456
457     % p4 describe -du 12345 # show change 12345
458
459 Note: the output of "p4 describe" is not in proper diff format, use
460 the F<Porting/p4genpatch> to get a diff-compatible format.
461 (Note that it may be easier to get one already prepared: grep
462 L<perlhack> for APC, and append eg "/diffs/12345.gz" to one of the
463 URLs to get a usable patch.)
464
465     % p4 diff -se ./...     # have I modified something but forgotten
466                             # to "p4 edit", easy faux pas with autogenerated
467                             # files like proto.h, or if one forgets to
468                             # look carefully which files a patch modifies
469     % p4 sync file.h        # if someone else has modified file.h
470     % p4 opened             # which files are opened (p4 edit) by me
471     % p4 opened -a          # which files are opened by anybody
472     % p4 diff -du file.c    # what changes have I done
473     % p4 revert file.h      # never mind my changes
474     % p4 sync -f argh.c     # forcibly synchronize your file
475                             # from the repository
476     % p4 diff -sr | p4 -x - revert
477                             # throw away (opened but) unchanged files
478                             # (in Perforce it's a little bit too easy
479                             # to checkin unchanged files)
480
481 Integrate patch 12345 from the mainline to the maint-5.6 branch:
482 (you have to in the directory that has both the mainline and
483 the maint-5.6/perl as subdirectories)
484
485     % p4 integrate -d perl/...@12345,12345 maint-5.6/perl/...
486
487 Integrate patches 12347-12350 from the perlio branch to the mainline:
488
489     % p4 integrate -d perlio/...@12347,12350 perl/...
490
491 =head1 Contact Information
492
493 The mail alias E<lt>perl-repository-keepers@perl.orgE<gt> can be used to reach
494 all current users of the repository.
495
496 The repository keeper is currently Philippe M. Chiasson
497 E<lt>gozer@ActiveState.comE<gt>.
498
499 =head1 AUTHORS
500
501 Malcolm Beattie, E<lt>mbeattie@sable.ox.ac.ukE<gt>, 24 June 1997.
502
503 Gurusamy Sarathy, E<lt>gsar@activestate.comE<gt>, 8 May 1999.
504
505 Slightly updated by Simon Cozens, E<lt>simon@brecon.co.ukE<gt>, 3 July 2000.
506
507 More updates by Jarkko Hietaniemi, E<lt>jhi@iki.fiE<gt>, 28 June 2001.
508
509 Perforce clarifications by Randall Gellens, E<lt>rcg@users.sourceforge.netE<gt>, 12 July 2001.
510
511 Windows-related updates by Steve Hay E<lt>shay@cpan.orgE<gt>, 23 July 2004
512 and 08 Aug 2005.
513
514 =cut