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