hgbook

view en/ch06-collab.xml @ 643:61ac4138e086

Update Chinese translation
author Dongsheng Song <dongsheng.song@gmail.com>
date Tue Mar 17 16:25:30 2009 +0800 (2009-03-17)
parents cfdb601a3c8b
children d0160b0b1a9e
line source
1 <!-- vim: set filetype=docbkxml shiftwidth=2 autoindent expandtab tw=77 : -->
3 <chapter id="cha.collab">
4 <?dbhtml filename="collaborating-with-other-people.html"?>
5 <title>Collaborating with other people</title>
7 <para>As a completely decentralised tool, Mercurial doesn't impose
8 any policy on how people ought to work with each other. However,
9 if you're new to distributed revision control, it helps to have
10 some tools and examples in mind when you're thinking about
11 possible workflow models.</para>
13 <sect1>
14 <title>Mercurial's web interface</title>
16 <para>Mercurial has a powerful web interface that provides several
17 useful capabilities.</para>
19 <para>For interactive use, the web interface lets you browse a
20 single repository or a collection of repositories. You can view
21 the history of a repository, examine each change (comments and
22 diffs), and view the contents of each directory and file.</para>
24 <para>Also for human consumption, the web interface provides an
25 RSS feed of the changes in a repository. This lets you
26 <quote>subscribe</quote> to a repository using your favourite
27 feed reader, and be automatically notified of activity in that
28 repository as soon as it happens. I find this capability much
29 more convenient than the model of subscribing to a mailing list
30 to which notifications are sent, as it requires no additional
31 configuration on the part of whoever is serving the
32 repository.</para>
34 <para>The web interface also lets remote users clone a repository,
35 pull changes from it, and (when the server is configured to
36 permit it) push changes back to it. Mercurial's HTTP tunneling
37 protocol aggressively compresses data, so that it works
38 efficiently even over low-bandwidth network connections.</para>
40 <para>The easiest way to get started with the web interface is to
41 use your web browser to visit an existing repository, such as
42 the master Mercurial repository at <ulink
43 url="http://www.selenic.com/repo/hg?style=gitweb">http://www.selenic.com/repo/hg?style=gitweb</ulink>.</para>
45 <para>If you're interested in providing a web interface to your
46 own repositories, Mercurial provides two ways to do this. The
47 first is using the <command role="hg-cmd">hg serve</command>
48 command, which is best suited to short-term
49 <quote>lightweight</quote> serving. See section <xref
50 linkend="sec.collab.serve"/> below for details of how to use
51 this command. If you have a long-lived repository that you'd
52 like to make permanently available, Mercurial has built-in
53 support for the CGI (Common Gateway Interface) standard, which
54 all common web servers support. See section <xref
55 linkend="sec.collab.cgi"/> for details of CGI
56 configuration.</para>
58 </sect1>
59 <sect1>
60 <title>Collaboration models</title>
62 <para>With a suitably flexible tool, making decisions about
63 workflow is much more of a social engineering challenge than a
64 technical one. Mercurial imposes few limitations on how you can
65 structure the flow of work in a project, so it's up to you and
66 your group to set up and live with a model that matches your own
67 particular needs.</para>
69 <sect2>
70 <title>Factors to keep in mind</title>
72 <para>The most important aspect of any model that you must keep
73 in mind is how well it matches the needs and capabilities of
74 the people who will be using it. This might seem
75 self-evident; even so, you still can't afford to forget it for
76 a moment.</para>
78 <para>I once put together a workflow model that seemed to make
79 perfect sense to me, but that caused a considerable amount of
80 consternation and strife within my development team. In spite
81 of my attempts to explain why we needed a complex set of
82 branches, and how changes ought to flow between them, a few
83 team members revolted. Even though they were smart people,
84 they didn't want to pay attention to the constraints we were
85 operating under, or face the consequences of those constraints
86 in the details of the model that I was advocating.</para>
88 <para>Don't sweep foreseeable social or technical problems under
89 the rug. Whatever scheme you put into effect, you should plan
90 for mistakes and problem scenarios. Consider adding automated
91 machinery to prevent, or quickly recover from, trouble that
92 you can anticipate. As an example, if you intend to have a
93 branch with not-for-release changes in it, you'd do well to
94 think early about the possibility that someone might
95 accidentally merge those changes into a release branch. You
96 could avoid this particular problem by writing a hook that
97 prevents changes from being merged from an inappropriate
98 branch.</para>
100 </sect2>
101 <sect2>
102 <title>Informal anarchy</title>
104 <para>I wouldn't suggest an <quote>anything goes</quote>
105 approach as something sustainable, but it's a model that's
106 easy to grasp, and it works perfectly well in a few unusual
107 situations.</para>
109 <para>As one example, many projects have a loose-knit group of
110 collaborators who rarely physically meet each other. Some
111 groups like to overcome the isolation of working at a distance
112 by organising occasional <quote>sprints</quote>. In a sprint,
113 a number of people get together in a single location (a
114 company's conference room, a hotel meeting room, that kind of
115 place) and spend several days more or less locked in there,
116 hacking intensely on a handful of projects.</para>
118 <para>A sprint is the perfect place to use the <command
119 role="hg-cmd">hg serve</command> command, since <command
120 role="hg-cmd">hg serve</command> does not require any fancy
121 server infrastructure. You can get started with <command
122 role="hg-cmd">hg serve</command> in moments, by reading
123 section <xref linkend="sec.collab.serve"/> below. Then simply
124 tell
125 the person next to you that you're running a server, send the
126 URL to them in an instant message, and you immediately have a
127 quick-turnaround way to work together. They can type your URL
128 into their web browser and quickly review your changes; or
129 they can pull a bugfix from you and verify it; or they can
130 clone a branch containing a new feature and try it out.</para>
132 <para>The charm, and the problem, with doing things in an ad hoc
133 fashion like this is that only people who know about your
134 changes, and where they are, can see them. Such an informal
135 approach simply doesn't scale beyond a handful people, because
136 each individual needs to know about $n$ different repositories
137 to pull from.</para>
139 </sect2>
140 <sect2>
141 <title>A single central repository</title>
143 <para>For smaller projects migrating from a centralised revision
144 control tool, perhaps the easiest way to get started is to
145 have changes flow through a single shared central repository.
146 This is also the most common <quote>building block</quote> for
147 more ambitious workflow schemes.</para>
149 <para>Contributors start by cloning a copy of this repository.
150 They can pull changes from it whenever they need to, and some
151 (perhaps all) developers have permission to push a change back
152 when they're ready for other people to see it.</para>
154 <para>Under this model, it can still often make sense for people
155 to pull changes directly from each other, without going
156 through the central repository. Consider a case in which I
157 have a tentative bug fix, but I am worried that if I were to
158 publish it to the central repository, it might subsequently
159 break everyone else's trees as they pull it. To reduce the
160 potential for damage, I can ask you to clone my repository
161 into a temporary repository of your own and test it. This
162 lets us put off publishing the potentially unsafe change until
163 it has had a little testing.</para>
165 <para>In this kind of scenario, people usually use the
166 <command>ssh</command> protocol to securely push changes to
167 the central repository, as documented in section <xref
168 linkend="sec.collab.ssh"/>. It's also
169 usual to publish a read-only copy of the repository over HTTP
170 using CGI, as in section <xref linkend="sec.collab.cgi"/>.
171 Publishing over HTTP
172 satisfies the needs of people who don't have push access, and
173 those who want to use web browsers to browse the repository's
174 history.</para>
176 </sect2>
177 <sect2>
178 <title>Working with multiple branches</title>
180 <para>Projects of any significant size naturally tend to make
181 progress on several fronts simultaneously. In the case of
182 software, it's common for a project to go through periodic
183 official releases. A release might then go into
184 <quote>maintenance mode</quote> for a while after its first
185 publication; maintenance releases tend to contain only bug
186 fixes, not new features. In parallel with these maintenance
187 releases, one or more future releases may be under
188 development. People normally use the word
189 <quote>branch</quote> to refer to one of these many slightly
190 different directions in which development is
191 proceeding.</para>
193 <para>Mercurial is particularly well suited to managing a number
194 of simultaneous, but not identical, branches. Each
195 <quote>development direction</quote> can live in its own
196 central repository, and you can merge changes from one to
197 another as the need arises. Because repositories are
198 independent of each other, unstable changes in a development
199 branch will never affect a stable branch unless someone
200 explicitly merges those changes in.</para>
202 <para>Here's an example of how this can work in practice. Let's
203 say you have one <quote>main branch</quote> on a central
204 server.</para>
206 &interaction.branching.init;
208 <para>People clone it, make changes locally, test them, and push
209 them back.</para>
211 <para>Once the main branch reaches a release milestone, you can
212 use the <command role="hg-cmd">hg tag</command> command to
213 give a permanent name to the milestone revision.</para>
215 &interaction.branching.tag;
217 <para>Let's say some ongoing
218 development occurs on the main branch.</para>
220 &interaction.branching.main;
222 <para>Using the tag that was recorded at the milestone, people
223 who clone that repository at any time in the future can use
224 <command role="hg-cmd">hg update</command> to get a copy of
225 the working directory exactly as it was when that tagged
226 revision was committed.</para>
228 &interaction.branching.update;
230 <para>In addition, immediately after the main branch is tagged,
231 someone can then clone the main branch on the server to a new
232 <quote>stable</quote> branch, also on the server.</para>
234 &interaction.branching.clone;
236 <para>Someone who needs to make a change to the stable branch
237 can then clone <emphasis>that</emphasis> repository, make
238 their changes, commit, and push their changes back there.</para>
240 &interaction.branching.stable;
242 <para>Because Mercurial repositories are independent, and
243 Mercurial doesn't move changes around automatically, the
244 stable and main branches are <emphasis>isolated</emphasis>
245 from each other. The changes that you made on the main branch
246 don't <quote>leak</quote> to the stable branch, and vice
247 versa.</para>
249 <para>You'll often want all of your bugfixes on the stable
250 branch to show up on the main branch, too. Rather than
251 rewrite a bugfix on the main branch, you can simply pull and
252 merge changes from the stable to the main branch, and
253 Mercurial will bring those bugfixes in for you.</para>
255 &interaction.branching.merge;
257 <para>The main branch will still contain changes that are not on
258 the stable branch, but it will also contain all of the
259 bugfixes from the stable branch. The stable branch remains
260 unaffected by these changes.</para>
262 </sect2>
263 <sect2>
264 <title>Feature branches</title>
266 <para>For larger projects, an effective way to manage change is
267 to break up a team into smaller groups. Each group has a
268 shared branch of its own, cloned from a single
269 <quote>master</quote> branch used by the entire project.
270 People working on an individual branch are typically quite
271 isolated from developments on other branches.</para>
273 <informalfigure id="fig.collab.feature-branches">
274 <mediaobject>
275 <imageobject><imagedata fileref="images/feature-branches.png"/>
276 </imageobject>
277 <textobject><phrase>XXX add text</phrase></textobject>
278 <caption><para id="fig.collab.feature-branches.caption">Feature
279 branches</para></caption>
280 </mediaobject>
281 </informalfigure>
283 <para>When a particular feature is deemed to be in suitable
284 shape, someone on that feature team pulls and merges from the
285 master branch into the feature branch, then pushes back up to
286 the master branch.</para>
288 </sect2>
289 <sect2>
290 <title>The release train</title>
292 <para>Some projects are organised on a <quote>train</quote>
293 basis: a release is scheduled to happen every few months, and
294 whatever features are ready when the <quote>train</quote> is
295 ready to leave are allowed in.</para>
297 <para>This model resembles working with feature branches. The
298 difference is that when a feature branch misses a train,
299 someone on the feature team pulls and merges the changes that
300 went out on that train release into the feature branch, and
301 the team continues its work on top of that release so that
302 their feature can make the next release.</para>
304 </sect2>
305 <sect2>
306 <title>The Linux kernel model</title>
308 <para>The development of the Linux kernel has a shallow
309 hierarchical structure, surrounded by a cloud of apparent
310 chaos. Because most Linux developers use
311 <command>git</command>, a distributed revision control tool
312 with capabilities similar to Mercurial, it's useful to
313 describe the way work flows in that environment; if you like
314 the ideas, the approach translates well across tools.</para>
316 <para>At the center of the community sits Linus Torvalds, the
317 creator of Linux. He publishes a single source repository
318 that is considered the <quote>authoritative</quote> current
319 tree by the entire developer community. Anyone can clone
320 Linus's tree, but he is very choosy about whose trees he pulls
321 from.</para>
323 <para>Linus has a number of <quote>trusted lieutenants</quote>.
324 As a general rule, he pulls whatever changes they publish, in
325 most cases without even reviewing those changes. Some of
326 those lieutenants are generally agreed to be
327 <quote>maintainers</quote>, responsible for specific
328 subsystems within the kernel. If a random kernel hacker wants
329 to make a change to a subsystem that they want to end up in
330 Linus's tree, they must find out who the subsystem's
331 maintainer is, and ask that maintainer to take their change.
332 If the maintainer reviews their changes and agrees to take
333 them, they'll pass them along to Linus in due course.</para>
335 <para>Individual lieutenants have their own approaches to
336 reviewing, accepting, and publishing changes; and for deciding
337 when to feed them to Linus. In addition, there are several
338 well known branches that people use for different purposes.
339 For example, a few people maintain <quote>stable</quote>
340 repositories of older versions of the kernel, to which they
341 apply critical fixes as needed. Some maintainers publish
342 multiple trees: one for experimental changes; one for changes
343 that they are about to feed upstream; and so on. Others just
344 publish a single tree.</para>
346 <para>This model has two notable features. The first is that
347 it's <quote>pull only</quote>. You have to ask, convince, or
348 beg another developer to take a change from you, because there
349 are almost no trees to which more than one person can push,
350 and there's no way to push changes into a tree that someone
351 else controls.</para>
353 <para>The second is that it's based on reputation and acclaim.
354 If you're an unknown, Linus will probably ignore changes from
355 you without even responding. But a subsystem maintainer will
356 probably review them, and will likely take them if they pass
357 their criteria for suitability. The more <quote>good</quote>
358 changes you contribute to a maintainer, the more likely they
359 are to trust your judgment and accept your changes. If you're
360 well-known and maintain a long-lived branch for something
361 Linus hasn't yet accepted, people with similar interests may
362 pull your changes regularly to keep up with your work.</para>
364 <para>Reputation and acclaim don't necessarily cross subsystem
365 or <quote>people</quote> boundaries. If you're a respected
366 but specialised storage hacker, and you try to fix a
367 networking bug, that change will receive a level of scrutiny
368 from a network maintainer comparable to a change from a
369 complete stranger.</para>
371 <para>To people who come from more orderly project backgrounds,
372 the comparatively chaotic Linux kernel development process
373 often seems completely insane. It's subject to the whims of
374 individuals; people make sweeping changes whenever they deem
375 it appropriate; and the pace of development is astounding.
376 And yet Linux is a highly successful, well-regarded piece of
377 software.</para>
379 </sect2>
380 <sect2>
381 <title>Pull-only versus shared-push collaboration</title>
383 <para>A perpetual source of heat in the open source community is
384 whether a development model in which people only ever pull
385 changes from others is <quote>better than</quote> one in which
386 multiple people can push changes to a shared
387 repository.</para>
389 <para>Typically, the backers of the shared-push model use tools
390 that actively enforce this approach. If you're using a
391 centralised revision control tool such as Subversion, there's
392 no way to make a choice over which model you'll use: the tool
393 gives you shared-push, and if you want to do anything else,
394 you'll have to roll your own approach on top (such as applying
395 a patch by hand).</para>
397 <para>A good distributed revision control tool, such as
398 Mercurial, will support both models. You and your
399 collaborators can then structure how you work together based
400 on your own needs and preferences, not on what contortions
401 your tools force you into.</para>
403 </sect2>
404 <sect2>
405 <title>Where collaboration meets branch management</title>
407 <para>Once you and your team set up some shared repositories and
408 start propagating changes back and forth between local and
409 shared repos, you begin to face a related, but slightly
410 different challenge: that of managing the multiple directions
411 in which your team may be moving at once. Even though this
412 subject is intimately related to how your team collaborates,
413 it's dense enough to merit treatment of its own, in chapter
414 <xref linkend="chap.branch"/>.</para>
416 </sect2>
417 </sect1>
418 <sect1>
419 <title>The technical side of sharing</title>
421 <para>The remainder of this chapter is devoted to the question of
422 serving data to your collaborators.</para>
424 </sect1>
425 <sect1 id="sec.collab.serve">
426 <title>Informal sharing with <command role="hg-cmd">hg
427 serve</command></title>
429 <para>Mercurial's <command role="hg-cmd">hg serve</command>
430 command is wonderfully suited to small, tight-knit, and
431 fast-paced group environments. It also provides a great way to
432 get a feel for using Mercurial commands over a network.</para>
434 <para>Run <command role="hg-cmd">hg serve</command> inside a
435 repository, and in under a second it will bring up a specialised
436 HTTP server; this will accept connections from any client, and
437 serve up data for that repository until you terminate it.
438 Anyone who knows the URL of the server you just started, and can
439 talk to your computer over the network, can then use a web
440 browser or Mercurial to read data from that repository. A URL
441 for a <command role="hg-cmd">hg serve</command> instance running
442 on a laptop is likely to look something like
443 <literal>http://my-laptop.local:8000/</literal>.</para>
445 <para>The <command role="hg-cmd">hg serve</command> command is
446 <emphasis>not</emphasis> a general-purpose web server. It can do
447 only two things:</para>
448 <itemizedlist>
449 <listitem><para>Allow people to browse the history of the
450 repository it's serving, from their normal web
451 browsers.</para>
452 </listitem>
453 <listitem><para>Speak Mercurial's wire protocol, so that people
454 can <command role="hg-cmd">hg clone</command> or <command
455 role="hg-cmd">hg pull</command> changes from that
456 repository.</para>
457 </listitem></itemizedlist>
458 <para>In particular, <command role="hg-cmd">hg serve</command>
459 won't allow remote users to <emphasis>modify</emphasis> your
460 repository. It's intended for read-only use.</para>
462 <para>If you're getting started with Mercurial, there's nothing to
463 prevent you from using <command role="hg-cmd">hg serve</command>
464 to serve up a repository on your own computer, then use commands
465 like <command role="hg-cmd">hg clone</command>, <command
466 role="hg-cmd">hg incoming</command>, and so on to talk to that
467 server as if the repository was hosted remotely. This can help
468 you to quickly get acquainted with using commands on
469 network-hosted repositories.</para>
471 <sect2>
472 <title>A few things to keep in mind</title>
474 <para>Because it provides unauthenticated read access to all
475 clients, you should only use <command role="hg-cmd">hg
476 serve</command> in an environment where you either don't
477 care, or have complete control over, who can access your
478 network and pull data from your repository.</para>
480 <para>The <command role="hg-cmd">hg serve</command> command
481 knows nothing about any firewall software you might have
482 installed on your system or network. It cannot detect or
483 control your firewall software. If other people are unable to
484 talk to a running <command role="hg-cmd">hg serve</command>
485 instance, the second thing you should do
486 (<emphasis>after</emphasis> you make sure that they're using
487 the correct URL) is check your firewall configuration.</para>
489 <para>By default, <command role="hg-cmd">hg serve</command>
490 listens for incoming connections on port 8000. If another
491 process is already listening on the port you want to use, you
492 can specify a different port to listen on using the <option
493 role="hg-opt-serve">-p</option> option.</para>
495 <para>Normally, when <command role="hg-cmd">hg serve</command>
496 starts, it prints no output, which can be a bit unnerving. If
497 you'd like to confirm that it is indeed running correctly, and
498 find out what URL you should send to your collaborators, start
499 it with the <option role="hg-opt-global">-v</option>
500 option.</para>
502 </sect2>
503 </sect1>
504 <sect1 id="sec.collab.ssh">
505 <title>Using the Secure Shell (ssh) protocol</title>
507 <para>You can pull and push changes securely over a network
508 connection using the Secure Shell (<literal>ssh</literal>)
509 protocol. To use this successfully, you may have to do a little
510 bit of configuration on the client or server sides.</para>
512 <para>If you're not familiar with ssh, it's a network protocol
513 that lets you securely communicate with another computer. To
514 use it with Mercurial, you'll be setting up one or more user
515 accounts on a server so that remote users can log in and execute
516 commands.</para>
518 <para>(If you <emphasis>are</emphasis> familiar with ssh, you'll
519 probably find some of the material that follows to be elementary
520 in nature.)</para>
522 <sect2>
523 <title>How to read and write ssh URLs</title>
525 <para>An ssh URL tends to look like this:</para>
526 <programlisting>ssh://bos@hg.serpentine.com:22/hg/hgbook</programlisting>
527 <orderedlist>
528 <listitem><para>The <quote><literal>ssh://</literal></quote>
529 part tells Mercurial to use the ssh protocol.</para>
530 </listitem>
531 <listitem><para>The <quote><literal>bos@</literal></quote>
532 component indicates what username to log into the server
533 as. You can leave this out if the remote username is the
534 same as your local username.</para>
535 </listitem>
536 <listitem><para>The
537 <quote><literal>hg.serpentine.com</literal></quote> gives
538 the hostname of the server to log into.</para>
539 </listitem>
540 <listitem><para>The <quote>:22</quote> identifies the port
541 number to connect to the server on. The default port is
542 22, so you only need to specify this part if you're
543 <emphasis>not</emphasis> using port 22.</para>
544 </listitem>
545 <listitem><para>The remainder of the URL is the local path to
546 the repository on the server.</para>
547 </listitem></orderedlist>
549 <para>There's plenty of scope for confusion with the path
550 component of ssh URLs, as there is no standard way for tools
551 to interpret it. Some programs behave differently than others
552 when dealing with these paths. This isn't an ideal situation,
553 but it's unlikely to change. Please read the following
554 paragraphs carefully.</para>
556 <para>Mercurial treats the path to a repository on the server as
557 relative to the remote user's home directory. For example, if
558 user <literal>foo</literal> on the server has a home directory
559 of <filename class="directory">/home/foo</filename>, then an
560 ssh URL that contains a path component of <filename
561 class="directory">bar</filename> <emphasis>really</emphasis>
562 refers to the directory <filename
563 class="directory">/home/foo/bar</filename>.</para>
565 <para>If you want to specify a path relative to another user's
566 home directory, you can use a path that starts with a tilde
567 character followed by the user's name (let's call them
568 <literal>otheruser</literal>), like this.</para>
569 <programlisting>ssh://server/~otheruser/hg/repo</programlisting>
571 <para>And if you really want to specify an
572 <emphasis>absolute</emphasis> path on the server, begin the
573 path component with two slashes, as in this example.</para>
574 <programlisting>ssh://server//absolute/path</programlisting>
576 </sect2>
577 <sect2>
578 <title>Finding an ssh client for your system</title>
580 <para>Almost every Unix-like system comes with OpenSSH
581 preinstalled. If you're using such a system, run
582 <literal>which ssh</literal> to find out if the
583 <command>ssh</command> command is installed (it's usually in
584 <filename class="directory">/usr/bin</filename>). In the
585 unlikely event that it isn't present, take a look at your
586 system documentation to figure out how to install it.</para>
588 <para>On Windows, you'll first need to download a suitable ssh
589 client. There are two alternatives.</para>
590 <itemizedlist>
591 <listitem><para>Simon Tatham's excellent PuTTY package
592 <citation>web:putty</citation> provides a complete suite
593 of ssh client commands.</para>
594 </listitem>
595 <listitem><para>If you have a high tolerance for pain, you can
596 use the Cygwin port of OpenSSH.</para>
597 </listitem></itemizedlist>
598 <para>In either case, you'll need to edit your \hgini\ file to
599 tell Mercurial where to find the actual client command. For
600 example, if you're using PuTTY, you'll need to use the
601 <command>plink</command> command as a command-line ssh
602 client.</para>
603 <programlisting>[ui] ssh = C:/path/to/plink.exe -ssh -i
604 "C:/path/to/my/private/key"</programlisting>
606 <note>
607 <para> The path to <command>plink</command> shouldn't contain
608 any whitespace characters, or Mercurial may not be able to
609 run it correctly (so putting it in <filename
610 class="directory">C:\\Program Files</filename> is probably
611 not a good idea).</para>
612 </note>
614 </sect2>
615 <sect2>
616 <title>Generating a key pair</title>
618 <para>To avoid the need to repetitively type a password every
619 time you need to use your ssh client, I recommend generating a
620 key pair. On a Unix-like system, the
621 <command>ssh-keygen</command> command will do the trick. On
622 Windows, if you're using PuTTY, the
623 <command>puttygen</command> command is what you'll
624 need.</para>
626 <para>When you generate a key pair, it's usually
627 <emphasis>highly</emphasis> advisable to protect it with a
628 passphrase. (The only time that you might not want to do this
629 is when you're using the ssh protocol for automated tasks on a
630 secure network.)</para>
632 <para>Simply generating a key pair isn't enough, however.
633 You'll need to add the public key to the set of authorised
634 keys for whatever user you're logging in remotely as. For
635 servers using OpenSSH (the vast majority), this will mean
636 adding the public key to a list in a file called <filename
637 role="special">authorized_keys</filename> in their <filename
638 role="special" class="directory">.ssh</filename>
639 directory.</para>
641 <para>On a Unix-like system, your public key will have a
642 <filename>.pub</filename> extension. If you're using
643 <command>puttygen</command> on Windows, you can save the
644 public key to a file of your choosing, or paste it from the
645 window it's displayed in straight into the <filename
646 role="special">authorized_keys</filename> file.</para>
648 </sect2>
649 <sect2>
650 <title>Using an authentication agent</title>
652 <para>An authentication agent is a daemon that stores
653 passphrases in memory (so it will forget passphrases if you
654 log out and log back in again). An ssh client will notice if
655 it's running, and query it for a passphrase. If there's no
656 authentication agent running, or the agent doesn't store the
657 necessary passphrase, you'll have to type your passphrase
658 every time Mercurial tries to communicate with a server on
659 your behalf (e.g. whenever you pull or push changes).</para>
661 <para>The downside of storing passphrases in an agent is that
662 it's possible for a well-prepared attacker to recover the
663 plain text of your passphrases, in some cases even if your
664 system has been power-cycled. You should make your own
665 judgment as to whether this is an acceptable risk. It
666 certainly saves a lot of repeated typing.</para>
668 <para>On Unix-like systems, the agent is called
669 <command>ssh-agent</command>, and it's often run automatically
670 for you when you log in. You'll need to use the
671 <command>ssh-add</command> command to add passphrases to the
672 agent's store. On Windows, if you're using PuTTY, the
673 <command>pageant</command> command acts as the agent. It adds
674 an icon to your system tray that will let you manage stored
675 passphrases.</para>
677 </sect2>
678 <sect2>
679 <title>Configuring the server side properly</title>
681 <para>Because ssh can be fiddly to set up if you're new to it,
682 there's a variety of things that can go wrong. Add Mercurial
683 on top, and there's plenty more scope for head-scratching.
684 Most of these potential problems occur on the server side, not
685 the client side. The good news is that once you've gotten a
686 configuration working, it will usually continue to work
687 indefinitely.</para>
689 <para>Before you try using Mercurial to talk to an ssh server,
690 it's best to make sure that you can use the normal
691 <command>ssh</command> or <command>putty</command> command to
692 talk to the server first. If you run into problems with using
693 these commands directly, Mercurial surely won't work. Worse,
694 it will obscure the underlying problem. Any time you want to
695 debug ssh-related Mercurial problems, you should drop back to
696 making sure that plain ssh client commands work first,
697 <emphasis>before</emphasis> you worry about whether there's a
698 problem with Mercurial.</para>
700 <para>The first thing to be sure of on the server side is that
701 you can actually log in from another machine at all. If you
702 can't use <command>ssh</command> or <command>putty</command>
703 to log in, the error message you get may give you a few hints
704 as to what's wrong. The most common problems are as
705 follows.</para>
706 <itemizedlist>
707 <listitem><para>If you get a <quote>connection refused</quote>
708 error, either there isn't an SSH daemon running on the
709 server at all, or it's inaccessible due to firewall
710 configuration.</para>
711 </listitem>
712 <listitem><para>If you get a <quote>no route to host</quote>
713 error, you either have an incorrect address for the server
714 or a seriously locked down firewall that won't admit its
715 existence at all.</para>
716 </listitem>
717 <listitem><para>If you get a <quote>permission denied</quote>
718 error, you may have mistyped the username on the server,
719 or you could have mistyped your key's passphrase or the
720 remote user's password.</para>
721 </listitem></itemizedlist>
722 <para>In summary, if you're having trouble talking to the
723 server's ssh daemon, first make sure that one is running at
724 all. On many systems it will be installed, but disabled, by
725 default. Once you're done with this step, you should then
726 check that the server's firewall is configured to allow
727 incoming connections on the port the ssh daemon is listening
728 on (usually 22). Don't worry about more exotic possibilities
729 for misconfiguration until you've checked these two
730 first.</para>
732 <para>If you're using an authentication agent on the client side
733 to store passphrases for your keys, you ought to be able to
734 log into the server without being prompted for a passphrase or
735 a password. If you're prompted for a passphrase, there are a
736 few possible culprits.</para>
737 <itemizedlist>
738 <listitem><para>You might have forgotten to use
739 <command>ssh-add</command> or <command>pageant</command>
740 to store the passphrase.</para>
741 </listitem>
742 <listitem><para>You might have stored the passphrase for the
743 wrong key.</para>
744 </listitem></itemizedlist>
745 <para>If you're being prompted for the remote user's password,
746 there are another few possible problems to check.</para>
747 <itemizedlist>
748 <listitem><para>Either the user's home directory or their
749 <filename role="special" class="directory">.ssh</filename>
750 directory might have excessively liberal permissions. As
751 a result, the ssh daemon will not trust or read their
752 <filename role="special">authorized_keys</filename> file.
753 For example, a group-writable home or <filename
754 role="special" class="directory">.ssh</filename>
755 directory will often cause this symptom.</para>
756 </listitem>
757 <listitem><para>The user's <filename
758 role="special">authorized_keys</filename> file may have
759 a problem. If anyone other than the user owns or can write
760 to that file, the ssh daemon will not trust or read
761 it.</para>
762 </listitem></itemizedlist>
764 <para>In the ideal world, you should be able to run the
765 following command successfully, and it should print exactly
766 one line of output, the current date and time.</para>
767 <programlisting>ssh myserver date</programlisting>
769 <para>If, on your server, you have login scripts that print
770 banners or other junk even when running non-interactive
771 commands like this, you should fix them before you continue,
772 so that they only print output if they're run interactively.
773 Otherwise these banners will at least clutter up Mercurial's
774 output. Worse, they could potentially cause problems with
775 running Mercurial commands remotely. Mercurial makes tries to
776 detect and ignore banners in non-interactive
777 <command>ssh</command> sessions, but it is not foolproof. (If
778 you're editing your login scripts on your server, the usual
779 way to see if a login script is running in an interactive
780 shell is to check the return code from the command
781 <literal>tty -s</literal>.)</para>
783 <para>Once you've verified that plain old ssh is working with
784 your server, the next step is to ensure that Mercurial runs on
785 the server. The following command should run
786 successfully:</para>
787 <programlisting>ssh myserver hg version</programlisting>
788 <para>If you see an error message instead of normal <command
789 role="hg-cmd">hg version</command> output, this is usually
790 because you haven't installed Mercurial to <filename
791 class="directory">/usr/bin</filename>. Don't worry if this
792 is the case; you don't need to do that. But you should check
793 for a few possible problems.</para>
794 <itemizedlist>
795 <listitem><para>Is Mercurial really installed on the server at
796 all? I know this sounds trivial, but it's worth
797 checking!</para>
798 </listitem>
799 <listitem><para>Maybe your shell's search path (usually set
800 via the <envar>PATH</envar> environment variable) is
801 simply misconfigured.</para>
802 </listitem>
803 <listitem><para>Perhaps your <envar>PATH</envar> environment
804 variable is only being set to point to the location of the
805 <command>hg</command> executable if the login session is
806 interactive. This can happen if you're setting the path
807 in the wrong shell login script. See your shell's
808 documentation for details.</para>
809 </listitem>
810 <listitem><para>The <envar>PYTHONPATH</envar> environment
811 variable may need to contain the path to the Mercurial
812 Python modules. It might not be set at all; it could be
813 incorrect; or it may be set only if the login is
814 interactive.</para>
815 </listitem></itemizedlist>
817 <para>If you can run <command role="hg-cmd">hg version</command>
818 over an ssh connection, well done! You've got the server and
819 client sorted out. You should now be able to use Mercurial to
820 access repositories hosted by that username on that server.
821 If you run into problems with Mercurial and ssh at this point,
822 try using the <option role="hg-opt-global">--debug</option>
823 option to get a clearer picture of what's going on.</para>
825 </sect2>
826 <sect2>
827 <title>Using compression with ssh</title>
829 <para>Mercurial does not compress data when it uses the ssh
830 protocol, because the ssh protocol can transparently compress
831 data. However, the default behaviour of ssh clients is
832 <emphasis>not</emphasis> to request compression.</para>
834 <para>Over any network other than a fast LAN (even a wireless
835 network), using compression is likely to significantly speed
836 up Mercurial's network operations. For example, over a WAN,
837 someone measured compression as reducing the amount of time
838 required to clone a particularly large repository from 51
839 minutes to 17 minutes.</para>
841 <para>Both <command>ssh</command> and <command>plink</command>
842 accept a <option role="cmd-opt-ssh">-C</option> option which
843 turns on compression. You can easily edit your <filename
844 role="special"> /.hgrc</filename>\ to enable compression for
845 all of Mercurial's uses of the ssh protocol.</para>
846 <programlisting>[ui] ssh = ssh -C</programlisting>
848 <para>If you use <command>ssh</command>, you can configure it to
849 always use compression when talking to your server. To do
850 this, edit your <filename
851 role="special">.ssh/config</filename> file (which may not
852 yet exist), as follows.</para>
853 <programlisting>Host hg Compression yes HostName
854 hg.example.com</programlisting>
855 <para>This defines an alias, <literal>hg</literal>. When you
856 use it on the <command>ssh</command> command line or in a
857 Mercurial <literal>ssh</literal>-protocol URL, it will cause
858 <command>ssh</command> to connect to
859 <literal>hg.example.com</literal> and use compression. This
860 gives you both a shorter name to type and compression, each of
861 which is a good thing in its own right.</para>
863 </sect2>
864 </sect1>
865 <sect1 id="sec.collab.cgi">
866 <title>Serving over HTTP using CGI</title>
868 <para>Depending on how ambitious you are, configuring Mercurial's
869 CGI interface can take anything from a few moments to several
870 hours.</para>
872 <para>We'll begin with the simplest of examples, and work our way
873 towards a more complex configuration. Even for the most basic
874 case, you're almost certainly going to need to read and modify
875 your web server's configuration.</para>
877 <note>
878 <para> Configuring a web server is a complex, fiddly, and
879 highly system-dependent activity. I can't possibly give you
880 instructions that will cover anything like all of the cases
881 you will encounter. Please use your discretion and judgment in
882 following the sections below. Be prepared to make plenty of
883 mistakes, and to spend a lot of time reading your server's
884 error logs.</para>
885 </note>
887 <sect2>
888 <title>Web server configuration checklist</title>
890 <para>Before you continue, do take a few moments to check a few
891 aspects of your system's setup.</para>
893 <orderedlist>
894 <listitem><para>Do you have a web server installed at all?
895 Mac OS X ships with Apache, but many other systems may not
896 have a web server installed.</para>
897 </listitem>
898 <listitem><para>If you have a web server installed, is it
899 actually running? On most systems, even if one is
900 present, it will be disabled by default.</para>
901 </listitem>
902 <listitem><para>Is your server configured to allow you to run
903 CGI programs in the directory where you plan to do so?
904 Most servers default to explicitly disabling the ability
905 to run CGI programs.</para>
906 </listitem></orderedlist>
908 <para>If you don't have a web server installed, and don't have
909 substantial experience configuring Apache, you should consider
910 using the <literal>lighttpd</literal> web server instead of
911 Apache. Apache has a well-deserved reputation for baroque and
912 confusing configuration. While <literal>lighttpd</literal> is
913 less capable in some ways than Apache, most of these
914 capabilities are not relevant to serving Mercurial
915 repositories. And <literal>lighttpd</literal> is undeniably
916 <emphasis>much</emphasis> easier to get started with than
917 Apache.</para>
919 </sect2>
920 <sect2>
921 <title>Basic CGI configuration</title>
923 <para>On Unix-like systems, it's common for users to have a
924 subdirectory named something like <filename
925 class="directory">public_html</filename> in their home
926 directory, from which they can serve up web pages. A file
927 named <filename>foo</filename> in this directory will be
928 accessible at a URL of the form
929 <literal>http://www.example.com/\
930 {</literal>username/foo}.</para>
932 <para>To get started, find the <filename
933 role="special">hgweb.cgi</filename> script that should be
934 present in your Mercurial installation. If you can't quickly
935 find a local copy on your system, simply download one from the
936 master Mercurial repository at <ulink
937 url="http://www.selenic.com/repo/hg/raw-file/tip/hgweb.cgi">http://www.selenic.com/repo/hg/raw-file/tip/hgweb.cgi</ulink>.</para>
939 <para>You'll need to copy this script into your <filename
940 class="directory">public_html</filename> directory, and
941 ensure that it's executable.</para>
942 <programlisting>cp .../hgweb.cgi ~/public_html chmod 755
943 ~/public_html/hgweb.cgi</programlisting>
944 <para>The <literal>755</literal> argument to
945 <command>chmod</command> is a little more general than just
946 making the script executable: it ensures that the script is
947 executable by anyone, and that <quote>group</quote> and
948 <quote>other</quote> write permissions are
949 <emphasis>not</emphasis> set. If you were to leave those
950 write permissions enabled, Apache's <literal>suexec</literal>
951 subsystem would likely refuse to execute the script. In fact,
952 <literal>suexec</literal> also insists that the
953 <emphasis>directory</emphasis> in which the script resides
954 must not be writable by others.</para>
955 <programlisting>chmod 755 ~/public_html</programlisting>
957 <sect3 id="sec.collab.wtf">
958 <title>What could <emphasis>possibly</emphasis> go
959 wrong?</title>
961 <para>Once you've copied the CGI script into place, go into a
962 web browser, and try to open the URL <ulink
963 url="http://myhostname/
964 myuser/hgweb.cgi">http://myhostname/
965 myuser/hgweb.cgi</ulink>, <emphasis>but</emphasis> brace
966 yourself for instant failure. There's a high probability
967 that trying to visit this URL will fail, and there are many
968 possible reasons for this. In fact, you're likely to
969 stumble over almost every one of the possible errors below,
970 so please read carefully. The following are all of the
971 problems I ran into on a system running Fedora 7, with a
972 fresh installation of Apache, and a user account that I
973 created specially to perform this exercise.</para>
975 <para>Your web server may have per-user directories disabled.
976 If you're using Apache, search your config file for a
977 <literal>UserDir</literal> directive. If there's none
978 present, per-user directories will be disabled. If one
979 exists, but its value is <literal>disabled</literal>, then
980 per-user directories will be disabled. Otherwise, the
981 string after <literal>UserDir</literal> gives the name of
982 the subdirectory that Apache will look in under your home
983 directory, for example <filename
984 class="directory">public_html</filename>.</para>
986 <para>Your file access permissions may be too restrictive.
987 The web server must be able to traverse your home directory
988 and directories under your <filename
989 class="directory">public_html</filename> directory, and
990 read files under the latter too. Here's a quick recipe to
991 help you to make your permissions more appropriate.</para>
992 <programlisting>chmod 755 ~ find ~/public_html -type d -print0
993 | xargs -0r chmod 755 find ~/public_html -type f -print0 |
994 xargs -0r chmod 644</programlisting>
996 <para>The other possibility with permissions is that you might
997 get a completely empty window when you try to load the
998 script. In this case, it's likely that your access
999 permissions are <emphasis>too permissive</emphasis>. Apache's
1000 <literal>suexec</literal> subsystem won't execute a script
1001 that's group- or world-writable, for example.</para>
1003 <para>Your web server may be configured to disallow execution
1004 of CGI programs in your per-user web directory. Here's
1005 Apache's default per-user configuration from my Fedora
1006 system.</para>
1007 <programlisting>&lt;Directory /home/*/public_html&gt;
1008 AllowOverride FileInfo AuthConfig Limit Options MultiViews
1009 Indexes SymLinksIfOwnerMatch IncludesNoExec &lt;Limit GET
1010 POST OPTIONS&gt; Order allow,deny Allow from all
1011 &lt;/Limit&gt; &lt;LimitExcept GET POST OPTIONS&gt; Order
1012 deny,allow Deny from all &lt;/LimitExcept&gt;
1013 &lt;/Directory&gt;</programlisting>
1014 <para>If you find a similar-looking
1015 <literal>Directory</literal> group in your Apache
1016 configuration, the directive to look at inside it is
1017 <literal>Options</literal>. Add <literal>ExecCGI</literal>
1018 to the end of this list if it's missing, and restart the web
1019 server.</para>
1021 <para>If you find that Apache serves you the text of the CGI
1022 script instead of executing it, you may need to either
1023 uncomment (if already present) or add a directive like
1024 this.</para>
1025 <programlisting>AddHandler cgi-script .cgi</programlisting>
1027 <para>The next possibility is that you might be served with a
1028 colourful Python backtrace claiming that it can't import a
1029 <literal>mercurial</literal>-related module. This is
1030 actually progress! The server is now capable of executing
1031 your CGI script. This error is only likely to occur if
1032 you're running a private installation of Mercurial, instead
1033 of a system-wide version. Remember that the web server runs
1034 the CGI program without any of the environment variables
1035 that you take for granted in an interactive session. If
1036 this error happens to you, edit your copy of <filename
1037 role="special">hgweb.cgi</filename> and follow the
1038 directions inside it to correctly set your
1039 <envar>PYTHONPATH</envar> environment variable.</para>
1041 <para>Finally, you are <emphasis>certain</emphasis> to by
1042 served with another colourful Python backtrace: this one
1043 will complain that it can't find <filename
1044 class="directory">/path/to/repository</filename>. Edit
1045 your <filename role="special">hgweb.cgi</filename> script
1046 and replace the <filename
1047 class="directory">/path/to/repository</filename> string
1048 with the complete path to the repository you want to serve
1049 up.</para>
1051 <para>At this point, when you try to reload the page, you
1052 should be presented with a nice HTML view of your
1053 repository's history. Whew!</para>
1055 </sect3>
1056 <sect3>
1057 <title>Configuring lighttpd</title>
1059 <para>To be exhaustive in my experiments, I tried configuring
1060 the increasingly popular <literal>lighttpd</literal> web
1061 server to serve the same repository as I described with
1062 Apache above. I had already overcome all of the problems I
1063 outlined with Apache, many of which are not server-specific.
1064 As a result, I was fairly sure that my file and directory
1065 permissions were good, and that my <filename
1066 role="special">hgweb.cgi</filename> script was properly
1067 edited.</para>
1069 <para>Once I had Apache running, getting
1070 <literal>lighttpd</literal> to serve the repository was a
1071 snap (in other words, even if you're trying to use
1072 <literal>lighttpd</literal>, you should read the Apache
1073 section). I first had to edit the
1074 <literal>mod_access</literal> section of its config file to
1075 enable <literal>mod_cgi</literal> and
1076 <literal>mod_userdir</literal>, both of which were disabled
1077 by default on my system. I then added a few lines to the
1078 end of the config file, to configure these modules.</para>
1079 <programlisting>userdir.path = "public_html" cgi.assign = (
1080 ".cgi" =&gt; "" )</programlisting>
1081 <para>With this done, <literal>lighttpd</literal> ran
1082 immediately for me. If I had configured
1083 <literal>lighttpd</literal> before Apache, I'd almost
1084 certainly have run into many of the same system-level
1085 configuration problems as I did with Apache. However, I
1086 found <literal>lighttpd</literal> to be noticeably easier to
1087 configure than Apache, even though I've used Apache for over
1088 a decade, and this was my first exposure to
1089 <literal>lighttpd</literal>.</para>
1091 </sect3>
1092 </sect2>
1093 <sect2>
1094 <title>Sharing multiple repositories with one CGI script</title>
1096 <para>The <filename role="special">hgweb.cgi</filename> script
1097 only lets you publish a single repository, which is an
1098 annoying restriction. If you want to publish more than one
1099 without wracking yourself with multiple copies of the same
1100 script, each with different names, a better choice is to use
1101 the <filename role="special">hgwebdir.cgi</filename>
1102 script.</para>
1104 <para>The procedure to configure <filename
1105 role="special">hgwebdir.cgi</filename> is only a little more
1106 involved than for <filename
1107 role="special">hgweb.cgi</filename>. First, you must obtain
1108 a copy of the script. If you don't have one handy, you can
1109 download a copy from the master Mercurial repository at <ulink
1110 url="http://www.selenic.com/repo/hg/raw-file/tip/hgwebdir.cgi">http://www.selenic.com/repo/hg/raw-file/tip/hgwebdir.cgi</ulink>.</para>
1112 <para>You'll need to copy this script into your <filename
1113 class="directory">public_html</filename> directory, and
1114 ensure that it's executable.</para>
1115 <programlisting>cp .../hgwebdir.cgi ~/public_html chmod 755
1116 ~/public_html ~/public_html/hgwebdir.cgi</programlisting>
1117 <para>With basic configuration out of the way, try to visit
1118 <ulink url="http://myhostname/
1119 myuser/hgwebdir.cgi">http://myhostname/
1120 myuser/hgwebdir.cgi</ulink> in your browser. It should
1121 display an empty list of repositories. If you get a blank
1122 window or error message, try walking through the list of
1123 potential problems in section <xref
1124 linkend="sec.collab.wtf"/>.</para>
1126 <para>The <filename role="special">hgwebdir.cgi</filename>
1127 script relies on an external configuration file. By default,
1128 it searches for a file named <filename
1129 role="special">hgweb.config</filename> in the same directory
1130 as itself. You'll need to create this file, and make it
1131 world-readable. The format of the file is similar to a
1132 Windows <quote>ini</quote> file, as understood by Python's
1133 <literal>ConfigParser</literal>
1134 <citation>web:configparser</citation> module.</para>
1136 <para>The easiest way to configure <filename
1137 role="special">hgwebdir.cgi</filename> is with a section
1138 named <literal>collections</literal>. This will automatically
1139 publish <emphasis>every</emphasis> repository under the
1140 directories you name. The section should look like
1141 this:</para>
1142 <programlisting>[collections] /my/root =
1143 /my/root</programlisting>
1144 <para>Mercurial interprets this by looking at the directory name
1145 on the <emphasis>right</emphasis> hand side of the
1146 <quote><literal>=</literal></quote> sign; finding repositories
1147 in that directory hierarchy; and using the text on the
1148 <emphasis>left</emphasis> to strip off matching text from the
1149 names it will actually list in the web interface. The
1150 remaining component of a path after this stripping has
1151 occurred is called a <quote>virtual path</quote>.</para>
1153 <para>Given the example above, if we have a repository whose
1154 local path is <filename
1155 class="directory">/my/root/this/repo</filename>, the CGI
1156 script will strip the leading <filename
1157 class="directory">/my/root</filename> from the name, and
1158 publish the repository with a virtual path of <filename
1159 class="directory">this/repo</filename>. If the base URL for
1160 our CGI script is <ulink url="http://myhostname/
1161 myuser/hgwebdir.cgi">http://myhostname/
1162 myuser/hgwebdir.cgi</ulink>, the complete URL for that
1163 repository will be <ulink url="http://myhostname/
1164 myuser/hgwebdir.cgi/this/repo">http://myhostname/
1165 myuser/hgwebdir.cgi/this/repo</ulink>.</para>
1167 <para>If we replace <filename
1168 class="directory">/my/root</filename> on the left hand side
1169 of this example with <filename
1170 class="directory">/my</filename>, then <filename
1171 role="special">hgwebdir.cgi</filename> will only strip off
1172 <filename class="directory">/my</filename> from the repository
1173 name, and will give us a virtual path of <filename
1174 class="directory">root/this/repo</filename> instead of
1175 <filename class="directory">this/repo</filename>.</para>
1177 <para>The <filename role="special">hgwebdir.cgi</filename>
1178 script will recursively search each directory listed in the
1179 <literal>collections</literal> section of its configuration
1180 file, but it will <literal>not</literal> recurse into the
1181 repositories it finds.</para>
1183 <para>The <literal>collections</literal> mechanism makes it easy
1184 to publish many repositories in a <quote>fire and
1185 forget</quote> manner. You only need to set up the CGI
1186 script and configuration file one time. Afterwards, you can
1187 publish or unpublish a repository at any time by simply moving
1188 it into, or out of, the directory hierarchy in which you've
1189 configured <filename role="special">hgwebdir.cgi</filename> to
1190 look.</para>
1192 <sect3>
1193 <title>Explicitly specifying which repositories to
1194 publish</title>
1196 <para>In addition to the <literal>collections</literal>
1197 mechanism, the <filename
1198 role="special">hgwebdir.cgi</filename> script allows you
1199 to publish a specific list of repositories. To do so,
1200 create a <literal>paths</literal> section, with contents of
1201 the following form.</para>
1202 <programlisting>[paths] repo1 = /my/path/to/some/repo repo2 =
1203 /some/path/to/another</programlisting>
1204 <para>In this case, the virtual path (the component that will
1205 appear in a URL) is on the left hand side of each
1206 definition, while the path to the repository is on the
1207 right. Notice that there does not need to be any
1208 relationship between the virtual path you choose and the
1209 location of a repository in your filesystem.</para>
1211 <para>If you wish, you can use both the
1212 <literal>collections</literal> and <literal>paths</literal>
1213 mechanisms simultaneously in a single configuration
1214 file.</para>
1216 <note>
1217 <para> If multiple repositories have the same virtual path,
1218 <filename role="special">hgwebdir.cgi</filename> will not
1219 report an error. Instead, it will behave
1220 unpredictably.</para>
1221 </note>
1223 </sect3>
1224 </sect2>
1225 <sect2>
1226 <title>Downloading source archives</title>
1228 <para>Mercurial's web interface lets users download an archive
1229 of any revision. This archive will contain a snapshot of the
1230 working directory as of that revision, but it will not contain
1231 a copy of the repository data.</para>
1233 <para>By default, this feature is not enabled. To enable it,
1234 you'll need to add an <envar
1235 role="rc-item-web">allow_archive</envar> item to the
1236 <literal role="rc-web">web</literal> section of your <filename
1237 role="special"> /.hgrc</filename>.</para>
1239 </sect2>
1240 <sect2>
1241 <title>Web configuration options</title>
1243 <para>Mercurial's web interfaces (the <command role="hg-cmd">hg
1244 serve</command> command, and the <filename
1245 role="special">hgweb.cgi</filename> and <filename
1246 role="special">hgwebdir.cgi</filename> scripts) have a
1247 number of configuration options that you can set. These
1248 belong in a section named <literal
1249 role="rc-web">web</literal>.</para>
1250 <itemizedlist>
1251 <listitem><para><envar
1252 role="rc-item-web">allow_archive</envar>: Determines
1253 which (if any) archive download mechanisms Mercurial
1254 supports. If you enable this feature, users of the web
1255 interface will be able to download an archive of whatever
1256 revision of a repository they are viewing. To enable the
1257 archive feature, this item must take the form of a
1258 sequence of words drawn from the list below.</para>
1259 <itemizedlist>
1260 <listitem><para><literal>bz2</literal>: A
1261 <command>tar</command> archive, compressed using
1262 <literal>bzip2</literal> compression. This has the
1263 best compression ratio, but uses the most CPU time on
1264 the server.</para>
1265 </listitem>
1266 <listitem><para><literal>gz</literal>: A
1267 <command>tar</command> archive, compressed using
1268 <literal>gzip</literal> compression.</para>
1269 </listitem>
1270 <listitem><para><literal>zip</literal>: A
1271 <command>zip</command> archive, compressed using LZW
1272 compression. This format has the worst compression
1273 ratio, but is widely used in the Windows world.</para>
1274 </listitem>
1275 </itemizedlist>
1276 <para> If you provide an empty list, or don't have an
1277 <envar role="rc-item-web">allow_archive</envar> entry at
1278 all, this feature will be disabled. Here is an example of
1279 how to enable all three supported formats.</para>
1280 <programlisting>[web] allow_archive = bz2 gz
1281 zip</programlisting>
1282 </listitem>
1283 <listitem><para><envar role="rc-item-web">allowpull</envar>:
1284 Boolean. Determines whether the web interface allows
1285 remote users to <command role="hg-cmd">hg pull</command>
1286 and <command role="hg-cmd">hg clone</command> this
1287 repository over HTTP. If set to <literal>no</literal> or
1288 <literal>false</literal>, only the
1289 <quote>human-oriented</quote> portion of the web interface
1290 is available.</para>
1291 </listitem>
1292 <listitem><para><envar role="rc-item-web">contact</envar>:
1293 String. A free-form (but preferably brief) string
1294 identifying the person or group in charge of the
1295 repository. This often contains the name and email
1296 address of a person or mailing list. It often makes sense
1297 to place this entry in a repository's own <filename
1298 role="special">.hg/hgrc</filename> file, but it can make
1299 sense to use in a global <filename role="special">
1300 /.hgrc</filename>\ if every repository has a single
1301 maintainer.</para>
1302 </listitem>
1303 <listitem><para><envar role="rc-item-web">maxchanges</envar>:
1304 Integer. The default maximum number of changesets to
1305 display in a single page of output.</para>
1306 </listitem>
1307 <listitem><para><envar role="rc-item-web">maxfiles</envar>:
1308 Integer. The default maximum number of modified files to
1309 display in a single page of output.</para>
1310 </listitem>
1311 <listitem><para><envar role="rc-item-web">stripes</envar>:
1312 Integer. If the web interface displays alternating
1313 <quote>stripes</quote> to make it easier to visually align
1314 rows when you are looking at a table, this number controls
1315 the number of rows in each stripe.</para>
1316 </listitem>
1317 <listitem><para><envar role="rc-item-web">style</envar>:
1318 Controls the template Mercurial uses to display the web
1319 interface. Mercurial ships with two web templates, named
1320 <literal>default</literal> and <literal>gitweb</literal>
1321 (the latter is much more visually attractive). You can
1322 also specify a custom template of your own; see chapter
1323 <xref linkend="chap.template"/> for details.
1324 Here, you can see how to enable the
1325 <literal>gitweb</literal> style.</para>
1326 <programlisting>[web] style = gitweb</programlisting>
1327 </listitem>
1328 <listitem><para><envar role="rc-item-web">templates</envar>:
1329 Path. The directory in which to search for template
1330 files. By default, Mercurial searches in the directory in
1331 which it was installed.</para>
1332 </listitem></itemizedlist>
1333 <para>If you are using <filename
1334 role="special">hgwebdir.cgi</filename>, you can place a few
1335 configuration items in a <literal role="rc-web">web</literal>
1336 section of the <filename
1337 role="special">hgweb.config</filename> file instead of a
1338 <filename role="special"> /.hgrc</filename>\ file, for
1339 convenience. These items are <envar
1340 role="rc-item-web">motd</envar> and <envar
1341 role="rc-item-web">style</envar>.</para>
1343 <sect3>
1344 <title>Options specific to an individual repository</title>
1346 <para>A few <literal role="rc-web">web</literal> configuration
1347 items ought to be placed in a repository's local <filename
1348 role="special">.hg/hgrc</filename>, rather than a user's
1349 or global <filename role="special">
1350 /.hgrc</filename>.</para>
1351 <itemizedlist>
1352 <listitem><para><envar
1353 role="rc-item-web">description</envar>: String. A
1354 free-form (but preferably brief) string that describes
1355 the contents or purpose of the repository.</para>
1356 </listitem>
1357 <listitem><para><envar role="rc-item-web">name</envar>:
1358 String. The name to use for the repository in the web
1359 interface. This overrides the default name, which is
1360 the last component of the repository's path.</para>
1361 </listitem></itemizedlist>
1363 </sect3>
1364 <sect3>
1365 <title>Options specific to the <command role="hg-cmd">hg
1366 serve</command> command</title>
1368 <para>Some of the items in the <literal
1369 role="rc-web">web</literal> section of a <filename
1370 role="special"> /.hgrc</filename>\ file are only for use
1371 with the <command role="hg-cmd">hg serve</command>
1372 command.</para>
1373 <itemizedlist>
1374 <listitem><para><envar role="rc-item-web">accesslog</envar>:
1375 Path. The name of a file into which to write an access
1376 log. By default, the <command role="hg-cmd">hg
1377 serve</command> command writes this information to
1378 standard output, not to a file. Log entries are written
1379 in the standard <quote>combined</quote> file format used
1380 by almost all web servers.</para>
1381 </listitem>
1382 <listitem><para><envar role="rc-item-web">address</envar>:
1383 String. The local address on which the server should
1384 listen for incoming connections. By default, the server
1385 listens on all addresses.</para>
1386 </listitem>
1387 <listitem><para><envar role="rc-item-web">errorlog</envar>:
1388 Path. The name of a file into which to write an error
1389 log. By default, the <command role="hg-cmd">hg
1390 serve</command> command writes this information to
1391 standard error, not to a file.</para>
1392 </listitem>
1393 <listitem><para><envar role="rc-item-web">ipv6</envar>:
1394 Boolean. Whether to use the IPv6 protocol. By default,
1395 IPv6 is not used.</para>
1396 </listitem>
1397 <listitem><para><envar role="rc-item-web">port</envar>:
1398 Integer. The TCP port number on which the server should
1399 listen. The default port number used is 8000.</para>
1400 </listitem></itemizedlist>
1402 </sect3>
1403 <sect3>
1404 <title>Choosing the right <filename role="special">
1405 /.hgrc</filename>\ file to add <literal
1406 role="rc-web">web</literal> items to</title>
1408 <para>It is important to remember that a web server like
1409 Apache or <literal>lighttpd</literal> will run under a user
1410 ID that is different to yours. CGI scripts run by your
1411 server, such as <filename
1412 role="special">hgweb.cgi</filename>, will usually also run
1413 under that user ID.</para>
1415 <para>If you add <literal role="rc-web">web</literal> items to
1416 your own personal <filename role="special">
1417 /.hgrc</filename>\ file, CGI scripts won't read that
1418 <filename role="special"> /.hgrc</filename>\ file. Those
1419 settings will thus only affect the behaviour of the <command
1420 role="hg-cmd">hg serve</command> command when you run it.
1421 To cause CGI scripts to see your settings, either create a
1422 <filename role="special"> /.hgrc</filename>\ file in the
1423 home directory of the user ID that runs your web server, or
1424 add those settings to a system-wide <filename
1425 role="special"> /.hgrc</filename>\ file.</para>
1428 </sect3>
1429 </sect2>
1430 </sect1>
1431 </chapter>
1433 <!--
1434 local variables:
1435 sgml-parent-document: ("00book.xml" "book" "chapter")
1436 end:
1437 -->