hgbook

view fr/ch10-hook.xml @ 979:64475a75365b

Merged from rpelisse
author Jean-Marie Clément <JeanMarieClement@web.de>
date Fri Sep 04 18:24:06 2009 +0200 (2009-09-04)
parents
children 6f8c48362758
line source
1 <!-- vim: set filetype=docbkxml shiftwidth=2 autoindent expandtab tw=77 : -->
3 <chapter>
4 <title>Handling repository events with hooks</title>
5 <para>\label{chap:hook}</para>
7 <para>Mercurial offers a powerful mechanism to let you perform automated
8 actions in response to events that occur in a repository. In some
9 cases, you can even control Mercurial's response to those events.</para>
11 <para>The name Mercurial uses for one of these actions is a <emphasis>hook</emphasis>.
12 Hooks are called <quote>triggers</quote> in some revision control systems, but
13 the two names refer to the same idea.</para>
15 <sect1>
16 <title>An overview of hooks in Mercurial</title>
18 <para>Here is a brief list of the hooks that Mercurial supports. We will
19 revisit each of these hooks in more detail later, in
20 section <xref linkend="sec:hook:ref"/>.</para>
22 <itemizedlist>
23 <listitem><para><literal role="hook">changegroup</literal>: This is run after a group of
24 changesets has been brought into the repository from elsewhere.</para>
25 </listitem>
26 <listitem><para><literal role="hook">commit</literal>: This is run after a new changeset has been
27 created in the local repository.</para>
28 </listitem>
29 <listitem><para><literal role="hook">incoming</literal>: This is run once for each new changeset
30 that is brought into the repository from elsewhere. Notice the
31 difference from <literal role="hook">changegroup</literal>, which is run once per
32 <emphasis>group</emphasis> of changesets brought in.</para>
33 </listitem>
34 <listitem><para><literal role="hook">outgoing</literal>: This is run after a group of changesets
35 has been transmitted from this repository.</para>
36 </listitem>
37 <listitem><para><literal role="hook">prechangegroup</literal>: This is run before starting to
38 bring a group of changesets into the repository.
39 </para>
40 </listitem>
41 <listitem><para><literal role="hook">precommit</literal>: Controlling. This is run before starting
42 a commit.
43 </para>
44 </listitem>
45 <listitem><para><literal role="hook">preoutgoing</literal>: Controlling. This is run before
46 starting to transmit a group of changesets from this repository.
47 </para>
48 </listitem>
49 <listitem><para><literal role="hook">pretag</literal>: Controlling. This is run before creating a tag.
50 </para>
51 </listitem>
52 <listitem><para><literal role="hook">pretxnchangegroup</literal>: Controlling. This is run after a
53 group of changesets has been brought into the local repository from
54 another, but before the transaction completes that will make the
55 changes permanent in the repository.
56 </para>
57 </listitem>
58 <listitem><para><literal role="hook">pretxncommit</literal>: Controlling. This is run after a new
59 changeset has been created in the local repository, but before the
60 transaction completes that will make it permanent.
61 </para>
62 </listitem>
63 <listitem><para><literal role="hook">preupdate</literal>: Controlling. This is run before starting
64 an update or merge of the working directory.
65 </para>
66 </listitem>
67 <listitem><para><literal role="hook">tag</literal>: This is run after a tag is created.
68 </para>
69 </listitem>
70 <listitem><para><literal role="hook">update</literal>: This is run after an update or merge of the
71 working directory has finished.
72 </para>
73 </listitem></itemizedlist>
74 <para>Each of the hooks whose description begins with the word
75 <quote>Controlling</quote> has the ability to determine whether an activity can
76 proceed. If the hook succeeds, the activity may proceed; if it fails,
77 the activity is either not permitted or undone, depending on the hook.
78 </para>
80 </sect1>
81 <sect1>
82 <title>Hooks and security</title>
84 <sect2>
85 <title>Hooks are run with your privileges</title>
87 <para>When you run a Mercurial command in a repository, and the command
88 causes a hook to run, that hook runs on <emphasis>your</emphasis> system, under
89 <emphasis>your</emphasis> user account, with <emphasis>your</emphasis> privilege level. Since
90 hooks are arbitrary pieces of executable code, you should treat them
91 with an appropriate level of suspicion. Do not install a hook unless
92 you are confident that you know who created it and what it does.
93 </para>
95 <para>In some cases, you may be exposed to hooks that you did not install
96 yourself. If you work with Mercurial on an unfamiliar system,
97 Mercurial will run hooks defined in that system's global <filename role="special"> /.hgrc</filename>\ file.
98 </para>
100 <para>If you are working with a repository owned by another user, Mercurial
101 can run hooks defined in that user's repository, but it will still run
102 them as <quote>you</quote>. For example, if you <command role="hg-cmd">hg pull</command> from that
103 repository, and its <filename role="special">.hg/hgrc</filename> defines a local
104 <literal role="hook">outgoing</literal> hook, that hook will run under your user account, even
105 though you don't own that repository.
106 </para>
108 <note>
109 <para> This only applies if you are pulling from a repository on a local or
110 network filesystem. If you're pulling over http or ssh, any
111 <literal role="hook">outgoing</literal> hook will run under whatever account is executing
112 the server process, on the server.
113 </para>
114 </note>
116 <para>XXX To see what hooks are defined in a repository, use the
117 <command role="hg-cmd">hg config hooks</command> command. If you are working in one
118 repository, but talking to another that you do not own (e.g. using
119 <command role="hg-cmd">hg pull</command> or <command role="hg-cmd">hg incoming</command>), remember that it is the other
120 repository's hooks you should be checking, not your own.
121 </para>
123 </sect2>
124 <sect2>
125 <title>Hooks do not propagate</title>
127 <para>In Mercurial, hooks are not revision controlled, and do not propagate
128 when you clone, or pull from, a repository. The reason for this is
129 simple: a hook is a completely arbitrary piece of executable code. It
130 runs under your user identity, with your privilege level, on your
131 machine.
132 </para>
134 <para>It would be extremely reckless for any distributed revision control
135 system to implement revision-controlled hooks, as this would offer an
136 easily exploitable way to subvert the accounts of users of the
137 revision control system.
138 </para>
140 <para>Since Mercurial does not propagate hooks, if you are collaborating
141 with other people on a common project, you should not assume that they
142 are using the same Mercurial hooks as you are, or that theirs are
143 correctly configured. You should document the hooks you expect people
144 to use.
145 </para>
147 <para>In a corporate intranet, this is somewhat easier to control, as you
148 can for example provide a <quote>standard</quote> installation of Mercurial on an
149 NFS filesystem, and use a site-wide <filename role="special"> /.hgrc</filename>\ file to define hooks that
150 all users will see. However, this too has its limits; see below.
151 </para>
153 </sect2>
154 <sect2>
155 <title>Hooks can be overridden</title>
157 <para>Mercurial allows you to override a hook definition by redefining the
158 hook. You can disable it by setting its value to the empty string, or
159 change its behaviour as you wish.
160 </para>
162 <para>If you deploy a system- or site-wide <filename role="special"> /.hgrc</filename>\ file that defines some
163 hooks, you should thus understand that your users can disable or
164 override those hooks.
165 </para>
167 </sect2>
168 <sect2>
169 <title>Ensuring that critical hooks are run</title>
171 <para>Sometimes you may want to enforce a policy that you do not want others
172 to be able to work around. For example, you may have a requirement
173 that every changeset must pass a rigorous set of tests. Defining this
174 requirement via a hook in a site-wide <filename role="special"> /.hgrc</filename>\ won't work for remote
175 users on laptops, and of course local users can subvert it at will by
176 overriding the hook.
177 </para>
179 <para>Instead, you can set up your policies for use of Mercurial so that
180 people are expected to propagate changes through a well-known
181 <quote>canonical</quote> server that you have locked down and configured
182 appropriately.
183 </para>
185 <para>One way to do this is via a combination of social engineering and
186 technology. Set up a restricted-access account; users can push
187 changes over the network to repositories managed by this account, but
188 they cannot log into the account and run normal shell commands. In
189 this scenario, a user can commit a changeset that contains any old
190 garbage they want.
191 </para>
193 <para>When someone pushes a changeset to the server that everyone pulls
194 from, the server will test the changeset before it accepts it as
195 permanent, and reject it if it fails to pass the test suite. If
196 people only pull changes from this filtering server, it will serve to
197 ensure that all changes that people pull have been automatically
198 vetted.
199 </para>
201 </sect2>
202 </sect1>
203 <sect1>
204 <title>Care with <literal>pretxn</literal> hooks in a shared-access repository</title>
206 <para>If you want to use hooks to do some automated work in a repository
207 that a number of people have shared access to, you need to be careful
208 in how you do this.
209 </para>
211 <para>Mercurial only locks a repository when it is writing to the
212 repository, and only the parts of Mercurial that write to the
213 repository pay attention to locks. Write locks are necessary to
214 prevent multiple simultaneous writers from scribbling on each other's
215 work, corrupting the repository.
216 </para>
218 <para>Because Mercurial is careful with the order in which it reads and
219 writes data, it does not need to acquire a lock when it wants to read
220 data from the repository. The parts of Mercurial that read from the
221 repository never pay attention to locks. This lockless reading scheme
222 greatly increases performance and concurrency.
223 </para>
225 <para>With great performance comes a trade-off, though, one which has the
226 potential to cause you trouble unless you're aware of it. To describe
227 this requires a little detail about how Mercurial adds changesets to a
228 repository and reads those changes.
229 </para>
231 <para>When Mercurial <emphasis>writes</emphasis> metadata, it writes it straight into the
232 destination file. It writes file data first, then manifest data
233 (which contains pointers to the new file data), then changelog data
234 (which contains pointers to the new manifest data). Before the first
235 write to each file, it stores a record of where the end of the file
236 was in its transaction log. If the transaction must be rolled back,
237 Mercurial simply truncates each file back to the size it was before the
238 transaction began.
239 </para>
241 <para>When Mercurial <emphasis>reads</emphasis> metadata, it reads the changelog first,
242 then everything else. Since a reader will only access parts of the
243 manifest or file metadata that it can see in the changelog, it can
244 never see partially written data.
245 </para>
247 <para>Some controlling hooks (<literal role="hook">pretxncommit</literal> and
248 <literal role="hook">pretxnchangegroup</literal>) run when a transaction is almost complete.
249 All of the metadata has been written, but Mercurial can still roll the
250 transaction back and cause the newly-written data to disappear.
251 </para>
253 <para>If one of these hooks runs for long, it opens a window of time during
254 which a reader can see the metadata for changesets that are not yet
255 permanent, and should not be thought of as <quote>really there</quote>. The
256 longer the hook runs, the longer that window is open.
257 </para>
259 <sect2>
260 <title>The problem illustrated</title>
262 <para>In principle, a good use for the <literal role="hook">pretxnchangegroup</literal> hook would
263 be to automatically build and test incoming changes before they are
264 accepted into a central repository. This could let you guarantee that
265 nobody can push changes to this repository that <quote>break the build</quote>.
266 But if a client can pull changes while they're being tested, the
267 usefulness of the test is zero; an unsuspecting someone can pull
268 untested changes, potentially breaking their build.
269 </para>
271 <para>The safest technological answer to this challenge is to set up such a
272 <quote>gatekeeper</quote> repository as <emphasis>unidirectional</emphasis>. Let it take
273 changes pushed in from the outside, but do not allow anyone to pull
274 changes from it (use the <literal role="hook">preoutgoing</literal> hook to lock it down).
275 Configure a <literal role="hook">changegroup</literal> hook so that if a build or test
276 succeeds, the hook will push the new changes out to another repository
277 that people <emphasis>can</emphasis> pull from.
278 </para>
280 <para>In practice, putting a centralised bottleneck like this in place is
281 not often a good idea, and transaction visibility has nothing to do
282 with the problem. As the size of a project&emdash;and the time it takes to
283 build and test&emdash;grows, you rapidly run into a wall with this <quote>try
284 before you buy</quote> approach, where you have more changesets to test than
285 time in which to deal with them. The inevitable result is frustration
286 on the part of all involved.
287 </para>
289 <para>An approach that scales better is to get people to build and test
290 before they push, then run automated builds and tests centrally
291 <emphasis>after</emphasis> a push, to be sure all is well. The advantage of this
292 approach is that it does not impose a limit on the rate at which the
293 repository can accept changes.
294 </para>
296 </sect2>
297 </sect1>
298 <sect1>
299 <title>A short tutorial on using hooks</title>
300 <para>\label{sec:hook:simple}
301 </para>
303 <para>It is easy to write a Mercurial hook. Let's start with a hook that
304 runs when you finish a <command role="hg-cmd">hg commit</command>, and simply prints the hash of
305 the changeset you just created. The hook is called <literal role="hook">commit</literal>.
306 </para>
308 <informalfigure>
309 <para> <!-- &interaction.hook.simple.init; -->
310 <caption><para>A simple hook that runs when a changeset is committed</para></caption>
311 \label{ex:hook:init}
312 </para>
313 </informalfigure>
315 <para>All hooks follow the pattern in example <xref linkend="ex:hook:init"/>. You add
316 an entry to the <literal role="rc-hooks">hooks</literal> section of your <filename role="special"> /.hgrc</filename>. On the left
317 is the name of the event to trigger on; on the right is the action to
318 take. As you can see, you can run an arbitrary shell command in a
319 hook. Mercurial passes extra information to the hook using
320 environment variables (look for <envar>HG_NODE</envar> in the example).
321 </para>
323 <sect2>
324 <title>Performing multiple actions per event</title>
326 <para>Quite often, you will want to define more than one hook for a
327 particular kind of event, as shown in example <xref linkend="ex:hook:ext"/>.
328 Mercurial lets you do this by adding an <emphasis>extension</emphasis> to the end of
329 a hook's name. You extend a hook's name by giving the name of the
330 hook, followed by a full stop (the <quote><literal>.</literal></quote> character), followed
331 by some more text of your choosing. For example, Mercurial will run
332 both <literal>commit.foo</literal> and <literal>commit.bar</literal> when the
333 <literal>commit</literal> event occurs.
334 </para>
336 <informalfigure>
337 <para> <!-- &interaction.hook.simple.ext; -->
338 <caption><para>Defining a second <literal role="hook">commit</para></caption> hook</literal>
339 \label{ex:hook:ext}
340 </para>
341 </informalfigure>
343 <para>To give a well-defined order of execution when there are multiple
344 hooks defined for an event, Mercurial sorts hooks by extension, and
345 executes the hook commands in this sorted order. In the above
346 example, it will execute <literal>commit.bar</literal> before
347 <literal>commit.foo</literal>, and <literal>commit</literal> before both.
348 </para>
350 <para>It is a good idea to use a somewhat descriptive extension when you
351 define a new hook. This will help you to remember what the hook was
352 for. If the hook fails, you'll get an error message that contains the
353 hook name and extension, so using a descriptive extension could give
354 you an immediate hint as to why the hook failed (see
355 section <xref linkend="sec:hook:perm"/> for an example).
356 </para>
358 </sect2>
359 <sect2>
360 <title>Controlling whether an activity can proceed</title>
361 <para>\label{sec:hook:perm}
362 </para>
364 <para>In our earlier examples, we used the <literal role="hook">commit</literal> hook, which is
365 run after a commit has completed. This is one of several Mercurial
366 hooks that run after an activity finishes. Such hooks have no way of
367 influencing the activity itself.
368 </para>
370 <para>Mercurial defines a number of events that occur before an activity
371 starts; or after it starts, but before it finishes. Hooks that
372 trigger on these events have the added ability to choose whether the
373 activity can continue, or will abort.
374 </para>
376 <para>The <literal role="hook">pretxncommit</literal> hook runs after a commit has all but
377 completed. In other words, the metadata representing the changeset
378 has been written out to disk, but the transaction has not yet been
379 allowed to complete. The <literal role="hook">pretxncommit</literal> hook has the ability to
380 decide whether the transaction can complete, or must be rolled back.
381 </para>
383 <para>If the <literal role="hook">pretxncommit</literal> hook exits with a status code of zero, the
384 transaction is allowed to complete; the commit finishes; and the
385 <literal role="hook">commit</literal> hook is run. If the <literal role="hook">pretxncommit</literal> hook exits with
386 a non-zero status code, the transaction is rolled back; the metadata
387 representing the changeset is erased; and the <literal role="hook">commit</literal> hook is
388 not run.
389 </para>
391 <informalfigure>
392 <para> <!-- &interaction.hook.simple.pretxncommit; -->
393 <caption><para>Using the <literal role="hook">pretxncommit</para></caption> hook to control commits</literal>
394 \label{ex:hook:pretxncommit}
395 </para>
396 </informalfigure>
398 <para>The hook in example <xref linkend="ex:hook:pretxncommit"/> checks that a commit
399 comment contains a bug ID. If it does, the commit can complete. If
400 not, the commit is rolled back.
401 </para>
403 </sect2>
404 </sect1>
405 <sect1>
406 <title>Writing your own hooks</title>
408 <para>When you are writing a hook, you might find it useful to run Mercurial
409 either with the <option role="hg-opt-global">-v</option> option, or the <envar role="rc-item-ui">verbose</envar> config
410 item set to <quote>true</quote>. When you do so, Mercurial will print a message
411 before it calls each hook.
412 </para>
414 <sect2>
415 <title>Choosing how your hook should run</title>
416 <para>\label{sec:hook:lang}
417 </para>
419 <para>You can write a hook either as a normal program&emdash;typically a shell
420 script&emdash;or as a Python function that is executed within the Mercurial
421 process.
422 </para>
424 <para>Writing a hook as an external program has the advantage that it
425 requires no knowledge of Mercurial's internals. You can call normal
426 Mercurial commands to get any added information you need. The
427 trade-off is that external hooks are slower than in-process hooks.
428 </para>
430 <para>An in-process Python hook has complete access to the Mercurial API,
431 and does not <quote>shell out</quote> to another process, so it is inherently
432 faster than an external hook. It is also easier to obtain much of the
433 information that a hook requires by using the Mercurial API than by
434 running Mercurial commands.
435 </para>
437 <para>If you are comfortable with Python, or require high performance,
438 writing your hooks in Python may be a good choice. However, when you
439 have a straightforward hook to write and you don't need to care about
440 performance (probably the majority of hooks), a shell script is
441 perfectly fine.
442 </para>
444 </sect2>
445 <sect2>
446 <title>Hook parameters</title>
447 <para>\label{sec:hook:param}
448 </para>
450 <para>Mercurial calls each hook with a set of well-defined parameters. In
451 Python, a parameter is passed as a keyword argument to your hook
452 function. For an external program, a parameter is passed as an
453 environment variable.
454 </para>
456 <para>Whether your hook is written in Python or as a shell script, the
457 hook-specific parameter names and values will be the same. A boolean
458 parameter will be represented as a boolean value in Python, but as the
459 number 1 (for <quote>true</quote>) or 0 (for <quote>false</quote>) as an environment
460 variable for an external hook. If a hook parameter is named
461 <literal>foo</literal>, the keyword argument for a Python hook will also be
462 named <literal>foo</literal>, while the environment variable for an external
463 hook will be named <literal>HG_FOO</literal>.
464 </para>
466 </sect2>
467 <sect2>
468 <title>Hook return values and activity control</title>
470 <para>A hook that executes successfully must exit with a status of zero if
471 external, or return boolean <quote>false</quote> if in-process. Failure is
472 indicated with a non-zero exit status from an external hook, or an
473 in-process hook returning boolean <quote>true</quote>. If an in-process hook
474 raises an exception, the hook is considered to have failed.
475 </para>
477 <para>For a hook that controls whether an activity can proceed, zero/false
478 means <quote>allow</quote>, while non-zero/true/exception means <quote>deny</quote>.
479 </para>
481 </sect2>
482 <sect2>
483 <title>Writing an external hook</title>
485 <para>When you define an external hook in your <filename role="special"> /.hgrc</filename>\ and the hook is run,
486 its value is passed to your shell, which interprets it. This means
487 that you can use normal shell constructs in the body of the hook.
488 </para>
490 <para>An executable hook is always run with its current directory set to a
491 repository's root directory.
492 </para>
494 <para>Each hook parameter is passed in as an environment variable; the name
495 is upper-cased, and prefixed with the string <quote><literal>HG_</literal></quote>.
496 </para>
498 <para>With the exception of hook parameters, Mercurial does not set or
499 modify any environment variables when running a hook. This is useful
500 to remember if you are writing a site-wide hook that may be run by a
501 number of different users with differing environment variables set.
502 In multi-user situations, you should not rely on environment variables
503 being set to the values you have in your environment when testing the
504 hook.
505 </para>
507 </sect2>
508 <sect2>
509 <title>Telling Mercurial to use an in-process hook</title>
511 <para>The <filename role="special"> /.hgrc</filename>\ syntax for defining an in-process hook is slightly
512 different than for an executable hook. The value of the hook must
513 start with the text <quote><literal>python:</literal></quote>, and continue with the
514 fully-qualified name of a callable object to use as the hook's value.
515 </para>
517 <para>The module in which a hook lives is automatically imported when a hook
518 is run. So long as you have the module name and <envar>PYTHONPATH</envar>
519 right, it should <quote>just work</quote>.
520 </para>
522 <para>The following <filename role="special"> /.hgrc</filename>\ example snippet illustrates the syntax and
523 meaning of the notions we just described.
524 </para>
525 <programlisting>
526 <para> [hooks]
527 commit.example = python:mymodule.submodule.myhook
528 </para>
529 </programlisting>
530 <para>When Mercurial runs the <literal>commit.example</literal> hook, it imports
531 <literal>mymodule.submodule</literal>, looks for the callable object named
532 <literal>myhook</literal>, and calls it.
533 </para>
535 </sect2>
536 <sect2>
537 <title>Writing an in-process hook</title>
539 <para>The simplest in-process hook does nothing, but illustrates the basic
540 shape of the hook API:
541 </para>
542 <programlisting>
543 <para> def myhook(ui, repo, **kwargs):
544 pass
545 </para>
546 </programlisting>
547 <para>The first argument to a Python hook is always a
548 <literal role="py-mod-mercurial.ui">ui</literal> object. The second is a repository object;
549 at the moment, it is always an instance of
550 <literal role="py-mod-mercurial.localrepo">localrepository</literal>. Following these two
551 arguments are other keyword arguments. Which ones are passed in
552 depends on the hook being called, but a hook can ignore arguments it
553 doesn't care about by dropping them into a keyword argument dict, as
554 with <literal>**kwargs</literal> above.
555 </para>
557 </sect2>
558 </sect1>
559 <sect1>
560 <title>Some hook examples</title>
562 <sect2>
563 <title>Writing meaningful commit messages</title>
565 <para>It's hard to imagine a useful commit message being very short. The
566 simple <literal role="hook">pretxncommit</literal> hook of figure <xref linkend="ex:hook:msglen.go"/>
567 will prevent you from committing a changeset with a message that is
568 less than ten bytes long.
569 </para>
571 <informalfigure>
572 <para> <!-- &interaction.hook.msglen.go; -->
573 <caption><para>A hook that forbids overly short commit messages</para></caption>
574 \label{ex:hook:msglen.go}
575 </para>
576 </informalfigure>
578 </sect2>
579 <sect2>
580 <title>Checking for trailing whitespace</title>
582 <para>An interesting use of a commit-related hook is to help you to write
583 cleaner code. A simple example of <quote>cleaner code</quote> is the dictum that
584 a change should not add any new lines of text that contain <quote>trailing
585 whitespace</quote>. Trailing whitespace is a series of space and tab
586 characters at the end of a line of text. In most cases, trailing
587 whitespace is unnecessary, invisible noise, but it is occasionally
588 problematic, and people often prefer to get rid of it.
589 </para>
591 <para>You can use either the <literal role="hook">precommit</literal> or <literal role="hook">pretxncommit</literal> hook to
592 tell whether you have a trailing whitespace problem. If you use the
593 <literal role="hook">precommit</literal> hook, the hook will not know which files you are
594 committing, so it will have to check every modified file in the
595 repository for trailing white space. If you want to commit a change
596 to just the file <filename>foo</filename>, but the file <filename>bar</filename> contains
597 trailing whitespace, doing a check in the <literal role="hook">precommit</literal> hook will
598 prevent you from committing <filename>foo</filename> due to the problem with
599 <filename>bar</filename>. This doesn't seem right.
600 </para>
602 <para>Should you choose the <literal role="hook">pretxncommit</literal> hook, the check won't occur
603 until just before the transaction for the commit completes. This will
604 allow you to check for problems only the exact files that are being
605 committed. However, if you entered the commit message interactively
606 and the hook fails, the transaction will roll back; you'll have to
607 re-enter the commit message after you fix the trailing whitespace and
608 run <command role="hg-cmd">hg commit</command> again.
609 </para>
611 <informalfigure>
612 <para> <!-- &interaction.hook.ws.simple; -->
613 <caption><para>A simple hook that checks for trailing whitespace</para></caption>
614 \label{ex:hook:ws.simple}
615 </para>
616 </informalfigure>
618 <para>Figure <xref linkend="ex:hook:ws.simple"/> introduces a simple <literal role="hook">pretxncommit</literal>
619 hook that checks for trailing whitespace. This hook is short, but not
620 very helpful. It exits with an error status if a change adds a line
621 with trailing whitespace to any file, but does not print any
622 information that might help us to identify the offending file or
623 line. It also has the nice property of not paying attention to
624 unmodified lines; only lines that introduce new trailing whitespace
625 cause problems.
626 </para>
628 <informalfigure>
629 <para> <!-- &interaction.hook.ws.better; -->
630 <caption><para>A better trailing whitespace hook</para></caption>
631 \label{ex:hook:ws.better}
632 </para>
633 </informalfigure>
635 <para>The example of figure <xref linkend="ex:hook:ws.better"/> is much more complex,
636 but also more useful. It parses a unified diff to see if any lines
637 add trailing whitespace, and prints the name of the file and the line
638 number of each such occurrence. Even better, if the change adds
639 trailing whitespace, this hook saves the commit comment and prints the
640 name of the save file before exiting and telling Mercurial to roll the
641 transaction back, so you can use
642 <command role="hg-cmd">hg commit <option role="hg-opt-commit">-l</option> <emphasis>filename</emphasis></command> to reuse the
643 saved commit message once you've corrected the problem.
644 </para>
646 <para>As a final aside, note in figure <xref linkend="ex:hook:ws.better"/> the use of
647 <command>perl</command>'s in-place editing feature to get rid of trailing
648 whitespace from a file. This is concise and useful enough that I will
649 reproduce it here.
650 </para>
651 <programlisting>
652 <para> perl -pi -e 's,\textbackslash{}s+$,,' filename
653 </para>
654 </programlisting>
656 </sect2>
657 </sect1>
658 <sect1>
659 <title>Bundled hooks</title>
661 <para>Mercurial ships with several bundled hooks. You can find them in the
662 <filename class="directory">hgext</filename> directory of a Mercurial source tree. If you are
663 using a Mercurial binary package, the hooks will be located in the
664 <filename class="directory">hgext</filename> directory of wherever your package installer put
665 Mercurial.
666 </para>
668 <sect2>
669 <title><literal role="hg-ext">acl</literal>&emdash;access control for parts of a repository</title>
671 <para>The <literal role="hg-ext">acl</literal> extension lets you control which remote users are
672 allowed to push changesets to a networked server. You can protect any
673 portion of a repository (including the entire repo), so that a
674 specific remote user can push changes that do not affect the protected
675 portion.
676 </para>
678 <para>This extension implements access control based on the identity of the
679 user performing a push, <emphasis>not</emphasis> on who committed the changesets
680 they're pushing. It makes sense to use this hook only if you have a
681 locked-down server environment that authenticates remote users, and
682 you want to be sure that only specific users are allowed to push
683 changes to that server.
684 </para>
686 <sect3>
687 <title>Configuring the <literal role="hook">acl</literal> hook</title>
689 <para>In order to manage incoming changesets, the <literal role="hg-ext">acl</literal> hook must be
690 used as a <literal role="hook">pretxnchangegroup</literal> hook. This lets it see which files
691 are modified by each incoming changeset, and roll back a group of
692 changesets if they modify <quote>forbidden</quote> files. Example:
693 </para>
694 <programlisting>
695 <para> [hooks]
696 pretxnchangegroup.acl = python:hgext.acl.hook
697 </para>
698 </programlisting>
700 <para>The <literal role="hg-ext">acl</literal> extension is configured using three sections.
701 </para>
703 <para>The <literal role="rc-acl">acl</literal> section has only one entry, <envar role="rc-item-acl">sources</envar>,
704 which lists the sources of incoming changesets that the hook should
705 pay attention to. You don't normally need to configure this section.
706 </para>
707 <itemizedlist>
708 <listitem><para><envar role="rc-item-acl">serve</envar>: Control incoming changesets that are arriving
709 from a remote repository over http or ssh. This is the default
710 value of <envar role="rc-item-acl">sources</envar>, and usually the only setting you'll
711 need for this configuration item.
712 </para>
713 </listitem>
714 <listitem><para><envar role="rc-item-acl">pull</envar>: Control incoming changesets that are
715 arriving via a pull from a local repository.
716 </para>
717 </listitem>
718 <listitem><para><envar role="rc-item-acl">push</envar>: Control incoming changesets that are
719 arriving via a push from a local repository.
720 </para>
721 </listitem>
722 <listitem><para><envar role="rc-item-acl">bundle</envar>: Control incoming changesets that are
723 arriving from another repository via a bundle.
724 </para>
725 </listitem></itemizedlist>
727 <para>The <literal role="rc-acl.allow">acl.allow</literal> section controls the users that are allowed to
728 add changesets to the repository. If this section is not present, all
729 users that are not explicitly denied are allowed. If this section is
730 present, all users that are not explicitly allowed are denied (so an
731 empty section means that all users are denied).
732 </para>
734 <para>The <literal role="rc-acl.deny">acl.deny</literal> section determines which users are denied
735 from adding changesets to the repository. If this section is not
736 present or is empty, no users are denied.
737 </para>
739 <para>The syntaxes for the <literal role="rc-acl.allow">acl.allow</literal> and <literal role="rc-acl.deny">acl.deny</literal>
740 sections are identical. On the left of each entry is a glob pattern
741 that matches files or directories, relative to the root of the
742 repository; on the right, a user name.
743 </para>
745 <para>In the following example, the user <literal>docwriter</literal> can only push
746 changes to the <filename class="directory">docs</filename> subtree of the repository, while
747 <literal>intern</literal> can push changes to any file or directory except
748 <filename class="directory">source/sensitive</filename>.
749 </para>
750 <programlisting>
751 <para> [acl.allow]
752 docs/** = docwriter
753 </para>
755 <para> [acl.deny]
756 source/sensitive/** = intern
757 </para>
758 </programlisting>
760 </sect3>
761 <sect3>
762 <title>Testing and troubleshooting</title>
764 <para>If you want to test the <literal role="hg-ext">acl</literal> hook, run it with Mercurial's
765 debugging output enabled. Since you'll probably be running it on a
766 server where it's not convenient (or sometimes possible) to pass in
767 the <option role="hg-opt-global">--debug</option> option, don't forget that you can enable
768 debugging output in your <filename role="special"> /.hgrc</filename>:
769 </para>
770 <programlisting>
771 <para> [ui]
772 debug = true
773 </para>
774 </programlisting>
775 <para>With this enabled, the <literal role="hg-ext">acl</literal> hook will print enough information
776 to let you figure out why it is allowing or forbidding pushes from
777 specific users.
778 </para>
780 </sect3>
781 </sect2>
782 <sect2>
783 <title><literal role="hg-ext">bugzilla</literal>&emdash;integration with Bugzilla</title>
785 <para>The <literal role="hg-ext">bugzilla</literal> extension adds a comment to a Bugzilla bug
786 whenever it finds a reference to that bug ID in a commit comment. You
787 can install this hook on a shared server, so that any time a remote
788 user pushes changes to this server, the hook gets run.
789 </para>
791 <para>It adds a comment to the bug that looks like this (you can configure
792 the contents of the comment&emdash;see below):
793 </para>
794 <programlisting>
795 <para> Changeset aad8b264143a, made by Joe User &lt;joe.user@domain.com&gt; in
796 the frobnitz repository, refers to this bug.
797 </para>
799 <para> For complete details, see
800 http://hg.domain.com/frobnitz?cmd=changeset;node=aad8b264143a
801 </para>
803 <para> Changeset description:
804 Fix bug 10483 by guarding against some NULL pointers
805 </para>
806 </programlisting>
807 <para>The value of this hook is that it automates the process of updating a
808 bug any time a changeset refers to it. If you configure the hook
809 properly, it makes it easy for people to browse straight from a
810 Bugzilla bug to a changeset that refers to that bug.
811 </para>
813 <para>You can use the code in this hook as a starting point for some more
814 exotic Bugzilla integration recipes. Here are a few possibilities:
815 </para>
816 <itemizedlist>
817 <listitem><para>Require that every changeset pushed to the server have a valid
818 bug ID in its commit comment. In this case, you'd want to configure
819 the hook as a <literal role="hook">pretxncommit</literal> hook. This would allow the hook
820 to reject changes that didn't contain bug IDs.
821 </para>
822 </listitem>
823 <listitem><para>Allow incoming changesets to automatically modify the
824 <emphasis>state</emphasis> of a bug, as well as simply adding a comment. For
825 example, the hook could recognise the string <quote>fixed bug 31337</quote> as
826 indicating that it should update the state of bug 31337 to
827 <quote>requires testing</quote>.
828 </para>
829 </listitem></itemizedlist>
831 <sect3>
832 <title>Configuring the <literal role="hook">bugzilla</literal> hook</title>
833 <para>\label{sec:hook:bugzilla:config}
834 </para>
836 <para>You should configure this hook in your server's <filename role="special"> /.hgrc</filename>\ as an
837 <literal role="hook">incoming</literal> hook, for example as follows:
838 </para>
839 <programlisting>
840 <para> [hooks]
841 incoming.bugzilla = python:hgext.bugzilla.hook
842 </para>
843 </programlisting>
845 <para>Because of the specialised nature of this hook, and because Bugzilla
846 was not written with this kind of integration in mind, configuring
847 this hook is a somewhat involved process.
848 </para>
850 <para>Before you begin, you must install the MySQL bindings for Python on
851 the host(s) where you'll be running the hook. If this is not
852 available as a binary package for your system, you can download it
853 from <citation>web:mysql-python</citation>.
854 </para>
856 <para>Configuration information for this hook lives in the
857 <literal role="rc-bugzilla">bugzilla</literal> section of your <filename role="special"> /.hgrc</filename>.
858 </para>
859 <itemizedlist>
860 <listitem><para><envar role="rc-item-bugzilla">version</envar>: The version of Bugzilla installed on
861 the server. The database schema that Bugzilla uses changes
862 occasionally, so this hook has to know exactly which schema to use.
863 At the moment, the only version supported is <literal>2.16</literal>.
864 </para>
865 </listitem>
866 <listitem><para><envar role="rc-item-bugzilla">host</envar>: The hostname of the MySQL server that
867 stores your Bugzilla data. The database must be configured to allow
868 connections from whatever host you are running the <literal role="hook">bugzilla</literal>
869 hook on.
870 </para>
871 </listitem>
872 <listitem><para><envar role="rc-item-bugzilla">user</envar>: The username with which to connect to
873 the MySQL server. The database must be configured to allow this
874 user to connect from whatever host you are running the
875 <literal role="hook">bugzilla</literal> hook on. This user must be able to access and
876 modify Bugzilla tables. The default value of this item is
877 <literal>bugs</literal>, which is the standard name of the Bugzilla user in a
878 MySQL database.
879 </para>
880 </listitem>
881 <listitem><para><envar role="rc-item-bugzilla">password</envar>: The MySQL password for the user you
882 configured above. This is stored as plain text, so you should make
883 sure that unauthorised users cannot read the <filename role="special"> /.hgrc</filename>\ file where you
884 store this information.
885 </para>
886 </listitem>
887 <listitem><para><envar role="rc-item-bugzilla">db</envar>: The name of the Bugzilla database on the
888 MySQL server. The default value of this item is <literal>bugs</literal>,
889 which is the standard name of the MySQL database where Bugzilla
890 stores its data.
891 </para>
892 </listitem>
893 <listitem><para><envar role="rc-item-bugzilla">notify</envar>: If you want Bugzilla to send out a
894 notification email to subscribers after this hook has added a
895 comment to a bug, you will need this hook to run a command whenever
896 it updates the database. The command to run depends on where you
897 have installed Bugzilla, but it will typically look something like
898 this, if you have Bugzilla installed in
899 <filename class="directory">/var/www/html/bugzilla</filename>:
900 </para>
901 </listitem><programlisting>
902 <listitem><para> cd /var/www/html/bugzilla &amp;&amp; ./processmail %s nobody@nowhere.com
903 </para>
904 </listitem></programlisting>
905 <listitem><para> The Bugzilla <literal>processmail</literal> program expects to be given a
906 bug ID (the hook replaces <quote><literal>%s</literal></quote> with the bug ID) and an
907 email address. It also expects to be able to write to some files in
908 the directory that it runs in. If Bugzilla and this hook are not
909 installed on the same machine, you will need to find a way to run
910 <literal>processmail</literal> on the server where Bugzilla is installed.
911 </para>
912 </listitem></itemizedlist>
914 </sect3>
915 <sect3>
916 <title>Mapping committer names to Bugzilla user names</title>
918 <para>By default, the <literal role="hg-ext">bugzilla</literal> hook tries to use the email address
919 of a changeset's committer as the Bugzilla user name with which to
920 update a bug. If this does not suit your needs, you can map committer
921 email addresses to Bugzilla user names using a <literal role="rc-usermap">usermap</literal>
922 section.
923 </para>
925 <para>Each item in the <literal role="rc-usermap">usermap</literal> section contains an email address
926 on the left, and a Bugzilla user name on the right.
927 </para>
928 <programlisting>
929 <para> [usermap]
930 jane.user@example.com = jane
931 </para>
932 </programlisting>
933 <para>You can either keep the <literal role="rc-usermap">usermap</literal> data in a normal <filename role="special"> /.hgrc</filename>, or
934 tell the <literal role="hg-ext">bugzilla</literal> hook to read the information from an
935 external <filename>usermap</filename> file. In the latter case, you can store
936 <filename>usermap</filename> data by itself in (for example) a user-modifiable
937 repository. This makes it possible to let your users maintain their
938 own <envar role="rc-item-bugzilla">usermap</envar> entries. The main <filename role="special"> /.hgrc</filename>\ file might
939 look like this:
940 </para>
941 <programlisting>
942 <para> # regular hgrc file refers to external usermap file
943 [bugzilla]
944 usermap = /home/hg/repos/userdata/bugzilla-usermap.conf
945 </para>
946 </programlisting>
947 <para>While the <filename>usermap</filename> file that it refers to might look like
948 this:
949 </para>
950 <programlisting>
951 <para> # bugzilla-usermap.conf - inside a hg repository
952 [usermap]
953 stephanie@example.com = steph
954 </para>
955 </programlisting>
957 </sect3>
958 <sect3>
959 <title>Configuring the text that gets added to a bug</title>
961 <para>You can configure the text that this hook adds as a comment; you
962 specify it in the form of a Mercurial template. Several <filename role="special"> /.hgrc</filename>\
963 entries (still in the <literal role="rc-bugzilla">bugzilla</literal> section) control this
964 behaviour.
965 </para>
966 <itemizedlist>
967 <listitem><para><literal>strip</literal>: The number of leading path elements to strip
968 from a repository's path name to construct a partial path for a URL.
969 For example, if the repositories on your server live under
970 <filename class="directory">/home/hg/repos</filename>, and you have a repository whose path is
971 <filename class="directory">/home/hg/repos/app/tests</filename>, then setting <literal>strip</literal> to
972 <literal>4</literal> will give a partial path of <filename class="directory">app/tests</filename>. The
973 hook will make this partial path available when expanding a
974 template, as <literal>webroot</literal>.
975 </para>
976 </listitem>
977 <listitem><para><literal>template</literal>: The text of the template to use. In addition
978 to the usual changeset-related variables, this template can use
979 <literal>hgweb</literal> (the value of the <literal>hgweb</literal> configuration item
980 above) and <literal>webroot</literal> (the path constructed using
981 <literal>strip</literal> above).
982 </para>
983 </listitem></itemizedlist>
985 <para>In addition, you can add a <envar role="rc-item-web">baseurl</envar> item to the
986 <literal role="rc-web">web</literal> section of your <filename role="special"> /.hgrc</filename>. The <literal role="hg-ext">bugzilla</literal> hook will
987 make this available when expanding a template, as the base string to
988 use when constructing a URL that will let users browse from a Bugzilla
989 comment to view a changeset. Example:
990 </para>
991 <programlisting>
992 <para> [web]
993 baseurl = http://hg.domain.com/
994 </para>
995 </programlisting>
997 <para>Here is an example set of <literal role="hg-ext">bugzilla</literal> hook config information.
998 </para>
999 <programlisting>
1000 <para> [bugzilla]
1001 host = bugzilla.example.com
1002 password = mypassword
1003 version = 2.16
1004 # server-side repos live in /home/hg/repos, so strip 4 leading
1005 # separators
1006 strip = 4
1007 hgweb = http://hg.example.com/
1008 usermap = /home/hg/repos/notify/bugzilla.conf
1009 template = Changeset {node|short}, made by {author} in the {webroot}
1010 repo, refers to this bug.\\nFor complete details, see
1011 {hgweb}{webroot}?cmd=changeset;node={node|short}\\nChangeset
1012 description:\\n\\t{desc|tabindent}
1013 </para>
1014 </programlisting>
1016 </sect3>
1017 <sect3>
1018 <title>Testing and troubleshooting</title>
1020 <para>The most common problems with configuring the <literal role="hg-ext">bugzilla</literal> hook
1021 relate to running Bugzilla's <filename>processmail</filename> script and mapping
1022 committer names to user names.
1023 </para>
1025 <para>Recall from section <xref linkend="sec:hook:bugzilla:config"/> above that the user
1026 that runs the Mercurial process on the server is also the one that
1027 will run the <filename>processmail</filename> script. The
1028 <filename>processmail</filename> script sometimes causes Bugzilla to write to
1029 files in its configuration directory, and Bugzilla's configuration
1030 files are usually owned by the user that your web server runs under.
1031 </para>
1033 <para>You can cause <filename>processmail</filename> to be run with the suitable
1034 user's identity using the <command>sudo</command> command. Here is an example
1035 entry for a <filename>sudoers</filename> file.
1036 </para>
1037 <programlisting>
1038 <para> hg_user = (httpd_user) NOPASSWD: /var/www/html/bugzilla/processmail-wrapper %s
1039 </para>
1040 </programlisting>
1041 <para>This allows the <literal>hg_user</literal> user to run a
1042 <filename>processmail-wrapper</filename> program under the identity of
1043 <literal>httpd_user</literal>.
1044 </para>
1046 <para>This indirection through a wrapper script is necessary, because
1047 <filename>processmail</filename> expects to be run with its current directory
1048 set to wherever you installed Bugzilla; you can't specify that kind of
1049 constraint in a <filename>sudoers</filename> file. The contents of the wrapper
1050 script are simple:
1051 </para>
1052 <programlisting>
1053 <para> #!/bin/sh
1054 cd `dirname $0` &amp;&amp; ./processmail "$1" nobody@example.com
1055 </para>
1056 </programlisting>
1057 <para>It doesn't seem to matter what email address you pass to
1058 <filename>processmail</filename>.
1059 </para>
1061 <para>If your <literal role="rc-usermap">usermap</literal> is not set up correctly, users will see an
1062 error message from the <literal role="hg-ext">bugzilla</literal> hook when they push changes
1063 to the server. The error message will look like this:
1064 </para>
1065 <programlisting>
1066 <para> cannot find bugzilla user id for john.q.public@example.com
1067 </para>
1068 </programlisting>
1069 <para>What this means is that the committer's address,
1070 <literal>john.q.public@example.com</literal>, is not a valid Bugzilla user name,
1071 nor does it have an entry in your <literal role="rc-usermap">usermap</literal> that maps it to
1072 a valid Bugzilla user name.
1073 </para>
1075 </sect3>
1076 </sect2>
1077 <sect2>
1078 <title><literal role="hg-ext">notify</literal>&emdash;send email notifications</title>
1080 <para>Although Mercurial's built-in web server provides RSS feeds of changes
1081 in every repository, many people prefer to receive change
1082 notifications via email. The <literal role="hg-ext">notify</literal> hook lets you send out
1083 notifications to a set of email addresses whenever changesets arrive
1084 that those subscribers are interested in.
1085 </para>
1087 <para>As with the <literal role="hg-ext">bugzilla</literal> hook, the <literal role="hg-ext">notify</literal> hook is
1088 template-driven, so you can customise the contents of the notification
1089 messages that it sends.
1090 </para>
1092 <para>By default, the <literal role="hg-ext">notify</literal> hook includes a diff of every changeset
1093 that it sends out; you can limit the size of the diff, or turn this
1094 feature off entirely. It is useful for letting subscribers review
1095 changes immediately, rather than clicking to follow a URL.
1096 </para>
1098 <sect3>
1099 <title>Configuring the <literal role="hg-ext">notify</literal> hook</title>
1101 <para>You can set up the <literal role="hg-ext">notify</literal> hook to send one email message per
1102 incoming changeset, or one per incoming group of changesets (all those
1103 that arrived in a single pull or push).
1104 </para>
1105 <programlisting>
1106 <para> [hooks]
1107 # send one email per group of changes
1108 changegroup.notify = python:hgext.notify.hook
1109 # send one email per change
1110 incoming.notify = python:hgext.notify.hook
1111 </para>
1112 </programlisting>
1114 <para>Configuration information for this hook lives in the
1115 <literal role="rc-notify">notify</literal> section of a <filename role="special"> /.hgrc</filename>\ file.
1116 </para>
1117 <itemizedlist>
1118 <listitem><para><envar role="rc-item-notify">test</envar>: By default, this hook does not send out
1119 email at all; instead, it prints the message that it <emphasis>would</emphasis>
1120 send. Set this item to <literal>false</literal> to allow email to be sent.
1121 The reason that sending of email is turned off by default is that it
1122 takes several tries to configure this extension exactly as you would
1123 like, and it would be bad form to spam subscribers with a number of
1124 <quote>broken</quote> notifications while you debug your configuration.
1125 </para>
1126 </listitem>
1127 <listitem><para><envar role="rc-item-notify">config</envar>: The path to a configuration file that
1128 contains subscription information. This is kept separate from the
1129 main <filename role="special"> /.hgrc</filename>\ so that you can maintain it in a repository of its own.
1130 People can then clone that repository, update their subscriptions,
1131 and push the changes back to your server.
1132 </para>
1133 </listitem>
1134 <listitem><para><envar role="rc-item-notify">strip</envar>: The number of leading path separator
1135 characters to strip from a repository's path, when deciding whether
1136 a repository has subscribers. For example, if the repositories on
1137 your server live in <filename class="directory">/home/hg/repos</filename>, and <literal role="hg-ext">notify</literal> is
1138 considering a repository named <filename class="directory">/home/hg/repos/shared/test</filename>,
1139 setting <envar role="rc-item-notify">strip</envar> to <literal>4</literal> will cause
1140 <literal role="hg-ext">notify</literal> to trim the path it considers down to
1141 <filename class="directory">shared/test</filename>, and it will match subscribers against that.
1142 </para>
1143 </listitem>
1144 <listitem><para><envar role="rc-item-notify">template</envar>: The template text to use when sending
1145 messages. This specifies both the contents of the message header
1146 and its body.
1147 </para>
1148 </listitem>
1149 <listitem><para><envar role="rc-item-notify">maxdiff</envar>: The maximum number of lines of diff
1150 data to append to the end of a message. If a diff is longer than
1151 this, it is truncated. By default, this is set to 300. Set this to
1152 <literal>0</literal> to omit diffs from notification emails.
1153 </para>
1154 </listitem>
1155 <listitem><para><envar role="rc-item-notify">sources</envar>: A list of sources of changesets to
1156 consider. This lets you limit <literal role="hg-ext">notify</literal> to only sending out
1157 email about changes that remote users pushed into this repository
1158 via a server, for example. See section <xref linkend="sec:hook:sources"/> for
1159 the sources you can specify here.
1160 </para>
1161 </listitem></itemizedlist>
1163 <para>If you set the <envar role="rc-item-web">baseurl</envar> item in the <literal role="rc-web">web</literal>
1164 section, you can use it in a template; it will be available as
1165 <literal>webroot</literal>.
1166 </para>
1168 <para>Here is an example set of <literal role="hg-ext">notify</literal> configuration information.
1169 </para>
1170 <programlisting>
1171 <para> [notify]
1172 # really send email
1173 test = false
1174 # subscriber data lives in the notify repo
1175 config = /home/hg/repos/notify/notify.conf
1176 # repos live in /home/hg/repos on server, so strip 4 "/" chars
1177 strip = 4
1178 template = X-Hg-Repo: {webroot}
1179 Subject: {webroot}: {desc|firstline|strip}
1180 From: {author}
1181 </para>
1183 <para> changeset {node|short} in {root}
1184 details: {baseurl}{webroot}?cmd=changeset;node={node|short}
1185 description:
1186 {desc|tabindent|strip}
1187 </para>
1189 <para> [web]
1190 baseurl = http://hg.example.com/
1191 </para>
1192 </programlisting>
1194 <para>This will produce a message that looks like the following:
1195 </para>
1196 <programlisting>
1197 <para> X-Hg-Repo: tests/slave
1198 Subject: tests/slave: Handle error case when slave has no buffers
1199 Date: Wed, 2 Aug 2006 15:25:46 -0700 (PDT)
1200 </para>
1202 <para> changeset 3cba9bfe74b5 in /home/hg/repos/tests/slave
1203 details: http://hg.example.com/tests/slave?cmd=changeset;node=3cba9bfe74b5
1204 description:
1205 Handle error case when slave has no buffers
1206 diffs (54 lines):
1207 </para>
1209 <para> diff -r 9d95df7cf2ad -r 3cba9bfe74b5 include/tests.h
1210 &emdash; a/include/tests.h Wed Aug 02 15:19:52 2006 -0700
1211 +++ b/include/tests.h Wed Aug 02 15:25:26 2006 -0700
1212 @@ -212,6 +212,15 @@ static __inline__ void test_headers(void *h)
1213 [...snip...]
1214 </para>
1215 </programlisting>
1217 </sect3>
1218 <sect3>
1219 <title>Testing and troubleshooting</title>
1221 <para>Do not forget that by default, the <literal role="hg-ext">notify</literal> extension \emph{will
1222 not send any mail} until you explicitly configure it to do so, by
1223 setting <envar role="rc-item-notify">test</envar> to <literal>false</literal>. Until you do that,
1224 it simply prints the message it <emphasis>would</emphasis> send.
1225 </para>
1227 </sect3>
1228 </sect2>
1229 </sect1>
1230 <sect1>
1231 <title>Information for writers of hooks</title>
1232 <para>\label{sec:hook:ref}
1233 </para>
1235 <sect2>
1236 <title>In-process hook execution</title>
1238 <para>An in-process hook is called with arguments of the following form:
1239 </para>
1240 <programlisting>
1241 <para> def myhook(ui, repo, **kwargs):
1242 pass
1243 </para>
1244 </programlisting>
1245 <para>The <literal>ui</literal> parameter is a <literal role="py-mod-mercurial.ui">ui</literal> object.
1246 The <literal>repo</literal> parameter is a
1247 <literal role="py-mod-mercurial.localrepo">localrepository</literal> object. The
1248 names and values of the <literal>**kwargs</literal> parameters depend on the
1249 hook being invoked, with the following common features:
1250 </para>
1251 <itemizedlist>
1252 <listitem><para>If a parameter is named <literal>node</literal> or
1253 <literal>parent<emphasis>N</emphasis></literal>, it will contain a hexadecimal changeset ID.
1254 The empty string is used to represent <quote>null changeset ID</quote> instead
1255 of a string of zeroes.
1256 </para>
1257 </listitem>
1258 <listitem><para>If a parameter is named <literal>url</literal>, it will contain the URL of
1259 a remote repository, if that can be determined.
1260 </para>
1261 </listitem>
1262 <listitem><para>Boolean-valued parameters are represented as Python
1263 <literal>bool</literal> objects.
1264 </para>
1265 </listitem></itemizedlist>
1267 <para>An in-process hook is called without a change to the process's working
1268 directory (unlike external hooks, which are run in the root of the
1269 repository). It must not change the process's working directory, or
1270 it will cause any calls it makes into the Mercurial API to fail.
1271 </para>
1273 <para>If a hook returns a boolean <quote>false</quote> value, it is considered to have
1274 succeeded. If it returns a boolean <quote>true</quote> value or raises an
1275 exception, it is considered to have failed. A useful way to think of
1276 the calling convention is <quote>tell me if you fail</quote>.
1277 </para>
1279 <para>Note that changeset IDs are passed into Python hooks as hexadecimal
1280 strings, not the binary hashes that Mercurial's APIs normally use. To
1281 convert a hash from hex to binary, use the
1282 \pymodfunc{mercurial.node}{bin} function.
1283 </para>
1285 </sect2>
1286 <sect2>
1287 <title>External hook execution</title>
1289 <para>An external hook is passed to the shell of the user running Mercurial.
1290 Features of that shell, such as variable substitution and command
1291 redirection, are available. The hook is run in the root directory of
1292 the repository (unlike in-process hooks, which are run in the same
1293 directory that Mercurial was run in).
1294 </para>
1296 <para>Hook parameters are passed to the hook as environment variables. Each
1297 environment variable's name is converted in upper case and prefixed
1298 with the string <quote><literal>HG_</literal></quote>. For example, if the name of a
1299 parameter is <quote><literal>node</literal></quote>, the name of the environment variable
1300 representing that parameter will be <quote><literal>HG_NODE</literal></quote>.
1301 </para>
1303 <para>A boolean parameter is represented as the string <quote><literal>1</literal></quote> for
1304 <quote>true</quote>, <quote><literal>0</literal></quote> for <quote>false</quote>. If an environment variable is
1305 named <envar>HG_NODE</envar>, <envar>HG_PARENT1</envar> or <envar>HG_PARENT2</envar>, it
1306 contains a changeset ID represented as a hexadecimal string. The
1307 empty string is used to represent <quote>null changeset ID</quote> instead of a
1308 string of zeroes. If an environment variable is named
1309 <envar>HG_URL</envar>, it will contain the URL of a remote repository, if
1310 that can be determined.
1311 </para>
1313 <para>If a hook exits with a status of zero, it is considered to have
1314 succeeded. If it exits with a non-zero status, it is considered to
1315 have failed.
1316 </para>
1318 </sect2>
1319 <sect2>
1320 <title>Finding out where changesets come from</title>
1322 <para>A hook that involves the transfer of changesets between a local
1323 repository and another may be able to find out information about the
1324 <quote>far side</quote>. Mercurial knows <emphasis>how</emphasis> changes are being
1325 transferred, and in many cases <emphasis>where</emphasis> they are being transferred
1326 to or from.
1327 </para>
1329 <sect3>
1330 <title>Sources of changesets</title>
1331 <para>\label{sec:hook:sources}
1332 </para>
1334 <para>Mercurial will tell a hook what means are, or were, used to transfer
1335 changesets between repositories. This is provided by Mercurial in a
1336 Python parameter named <literal>source</literal>, or an environment variable named
1337 <envar>HG_SOURCE</envar>.
1338 </para>
1340 <itemizedlist>
1341 <listitem><para><literal>serve</literal>: Changesets are transferred to or from a remote
1342 repository over http or ssh.
1343 </para>
1344 </listitem>
1345 <listitem><para><literal>pull</literal>: Changesets are being transferred via a pull from
1346 one repository into another.
1347 </para>
1348 </listitem>
1349 <listitem><para><literal>push</literal>: Changesets are being transferred via a push from
1350 one repository into another.
1351 </para>
1352 </listitem>
1353 <listitem><para><literal>bundle</literal>: Changesets are being transferred to or from a
1354 bundle.
1355 </para>
1356 </listitem></itemizedlist>
1358 </sect3>
1359 <sect3>
1360 <title>Where changes are going&emdash;remote repository URLs</title>
1361 <para>\label{sec:hook:url}
1362 </para>
1364 <para>When possible, Mercurial will tell a hook the location of the <quote>far
1365 side</quote> of an activity that transfers changeset data between
1366 repositories. This is provided by Mercurial in a Python parameter
1367 named <literal>url</literal>, or an environment variable named <envar>HG_URL</envar>.
1368 </para>
1370 <para>This information is not always known. If a hook is invoked in a
1371 repository that is being served via http or ssh, Mercurial cannot tell
1372 where the remote repository is, but it may know where the client is
1373 connecting from. In such cases, the URL will take one of the
1374 following forms:
1375 </para>
1376 <itemizedlist>
1377 <listitem><para><literal>remote:ssh:<emphasis>ip-address</emphasis></literal>&emdash;remote ssh client, at
1378 the given IP address.
1379 </para>
1380 </listitem>
1381 <listitem><para><literal>remote:http:<emphasis>ip-address</emphasis></literal>&emdash;remote http client, at
1382 the given IP address. If the client is using SSL, this will be of
1383 the form <literal>remote:https:<emphasis>ip-address</emphasis></literal>.
1384 </para>
1385 </listitem>
1386 <listitem><para>Empty&emdash;no information could be discovered about the remote
1387 client.
1388 </para>
1389 </listitem></itemizedlist>
1391 </sect3>
1392 </sect2>
1393 </sect1>
1394 <sect1>
1395 <title>Hook reference</title>
1397 <sect2>
1398 <title><literal role="hook">changegroup</literal>&emdash;after remote changesets added</title>
1399 <para>\label{sec:hook:changegroup}
1400 </para>
1402 <para>This hook is run after a group of pre-existing changesets has been
1403 added to the repository, for example via a <command role="hg-cmd">hg pull</command> or
1404 <command role="hg-cmd">hg unbundle</command>. This hook is run once per operation that added one
1405 or more changesets. This is in contrast to the <literal role="hook">incoming</literal> hook,
1406 which is run once per changeset, regardless of whether the changesets
1407 arrive in a group.
1408 </para>
1410 <para>Some possible uses for this hook include kicking off an automated
1411 build or test of the added changesets, updating a bug database, or
1412 notifying subscribers that a repository contains new changes.
1413 </para>
1415 <para>Parameters to this hook:
1416 </para>
1417 <itemizedlist>
1418 <listitem><para><literal>node</literal>: A changeset ID. The changeset ID of the first
1419 changeset in the group that was added. All changesets between this
1420 and \index{tags!<literal>tip</literal>}<literal>tip</literal>, inclusive, were added by
1421 a single <command role="hg-cmd">hg pull</command>, <command role="hg-cmd">hg push</command> or <command role="hg-cmd">hg unbundle</command>.
1422 </para>
1423 </listitem>
1424 <listitem><para><literal>source</literal>: A string. The source of these changes. See
1425 section <xref linkend="sec:hook:sources"/> for details.
1426 </para>
1427 </listitem>
1428 <listitem><para><literal>url</literal>: A URL. The location of the remote repository, if
1429 known. See section <xref linkend="sec:hook:url"/> for more information.
1430 </para>
1431 </listitem></itemizedlist>
1433 <para>See also: <literal role="hook">incoming</literal> (section <xref linkend="sec:hook:incoming"/>),
1434 <literal role="hook">prechangegroup</literal> (section <xref linkend="sec:hook:prechangegroup"/>),
1435 <literal role="hook">pretxnchangegroup</literal> (section <xref linkend="sec:hook:pretxnchangegroup"/>)
1436 </para>
1438 </sect2>
1439 <sect2>
1440 <title><literal role="hook">commit</literal>&emdash;after a new changeset is created</title>
1441 <para>\label{sec:hook:commit}
1442 </para>
1444 <para>This hook is run after a new changeset has been created.
1445 </para>
1447 <para>Parameters to this hook:
1448 </para>
1449 <itemizedlist>
1450 <listitem><para><literal>node</literal>: A changeset ID. The changeset ID of the newly
1451 committed changeset.
1452 </para>
1453 </listitem>
1454 <listitem><para><literal>parent1</literal>: A changeset ID. The changeset ID of the first
1455 parent of the newly committed changeset.
1456 </para>
1457 </listitem>
1458 <listitem><para><literal>parent2</literal>: A changeset ID. The changeset ID of the second
1459 parent of the newly committed changeset.
1460 </para>
1461 </listitem></itemizedlist>
1463 <para>See also: <literal role="hook">precommit</literal> (section <xref linkend="sec:hook:precommit"/>),
1464 <literal role="hook">pretxncommit</literal> (section <xref linkend="sec:hook:pretxncommit"/>)
1465 </para>
1467 </sect2>
1468 <sect2>
1469 <title><literal role="hook">incoming</literal>&emdash;after one remote changeset is added</title>
1470 <para>\label{sec:hook:incoming}
1471 </para>
1473 <para>This hook is run after a pre-existing changeset has been added to the
1474 repository, for example via a <command role="hg-cmd">hg push</command>. If a group of changesets
1475 was added in a single operation, this hook is called once for each
1476 added changeset.
1477 </para>
1479 <para>You can use this hook for the same purposes as the <literal role="hook">changegroup</literal>
1480 hook (section <xref linkend="sec:hook:changegroup"/>); it's simply more convenient
1481 sometimes to run a hook once per group of changesets, while other
1482 times it's handier once per changeset.
1483 </para>
1485 <para>Parameters to this hook:
1486 </para>
1487 <itemizedlist>
1488 <listitem><para><literal>node</literal>: A changeset ID. The ID of the newly added
1489 changeset.
1490 </para>
1491 </listitem>
1492 <listitem><para><literal>source</literal>: A string. The source of these changes. See
1493 section <xref linkend="sec:hook:sources"/> for details.
1494 </para>
1495 </listitem>
1496 <listitem><para><literal>url</literal>: A URL. The location of the remote repository, if
1497 known. See section <xref linkend="sec:hook:url"/> for more information.
1498 </para>
1499 </listitem></itemizedlist>
1501 <para>See also: <literal role="hook">changegroup</literal> (section <xref linkend="sec:hook:changegroup"/>) <literal role="hook">prechangegroup</literal> (section <xref linkend="sec:hook:prechangegroup"/>), <literal role="hook">pretxnchangegroup</literal> (section <xref linkend="sec:hook:pretxnchangegroup"/>)
1502 </para>
1504 </sect2>
1505 <sect2>
1506 <title><literal role="hook">outgoing</literal>&emdash;after changesets are propagated</title>
1507 <para>\label{sec:hook:outgoing}
1508 </para>
1510 <para>This hook is run after a group of changesets has been propagated out
1511 of this repository, for example by a <command role="hg-cmd">hg push</command> or <command role="hg-cmd">hg bundle</command>
1512 command.
1513 </para>
1515 <para>One possible use for this hook is to notify administrators that
1516 changes have been pulled.
1517 </para>
1519 <para>Parameters to this hook:
1520 </para>
1521 <itemizedlist>
1522 <listitem><para><literal>node</literal>: A changeset ID. The changeset ID of the first
1523 changeset of the group that was sent.
1524 </para>
1525 </listitem>
1526 <listitem><para><literal>source</literal>: A string. The source of the of the operation
1527 (see section <xref linkend="sec:hook:sources"/>). If a remote client pulled
1528 changes from this repository, <literal>source</literal> will be
1529 <literal>serve</literal>. If the client that obtained changes from this
1530 repository was local, <literal>source</literal> will be <literal>bundle</literal>,
1531 <literal>pull</literal>, or <literal>push</literal>, depending on the operation the
1532 client performed.
1533 </para>
1534 </listitem>
1535 <listitem><para><literal>url</literal>: A URL. The location of the remote repository, if
1536 known. See section <xref linkend="sec:hook:url"/> for more information.
1537 </para>
1538 </listitem></itemizedlist>
1540 <para>See also: <literal role="hook">preoutgoing</literal> (section <xref linkend="sec:hook:preoutgoing"/>)
1541 </para>
1543 </sect2>
1544 <sect2>
1545 <title><literal role="hook">prechangegroup</literal>&emdash;before starting to add remote changesets</title>
1546 <para>\label{sec:hook:prechangegroup}
1547 </para>
1549 <para>This controlling hook is run before Mercurial begins to add a group of
1550 changesets from another repository.
1551 </para>
1553 <para>This hook does not have any information about the changesets to be
1554 added, because it is run before transmission of those changesets is
1555 allowed to begin. If this hook fails, the changesets will not be
1556 transmitted.
1557 </para>
1559 <para>One use for this hook is to prevent external changes from being added
1560 to a repository. For example, you could use this to <quote>freeze</quote> a
1561 server-hosted branch temporarily or permanently so that users cannot
1562 push to it, while still allowing a local administrator to modify the
1563 repository.
1564 </para>
1566 <para>Parameters to this hook:
1567 </para>
1568 <itemizedlist>
1569 <listitem><para><literal>source</literal>: A string. The source of these changes. See
1570 section <xref linkend="sec:hook:sources"/> for details.
1571 </para>
1572 </listitem>
1573 <listitem><para><literal>url</literal>: A URL. The location of the remote repository, if
1574 known. See section <xref linkend="sec:hook:url"/> for more information.
1575 </para>
1576 </listitem></itemizedlist>
1578 <para>See also: <literal role="hook">changegroup</literal> (section <xref linkend="sec:hook:changegroup"/>),
1579 <literal role="hook">incoming</literal> (section <xref linkend="sec:hook:incoming"/>), ,
1580 <literal role="hook">pretxnchangegroup</literal> (section <xref linkend="sec:hook:pretxnchangegroup"/>)
1581 </para>
1583 </sect2>
1584 <sect2>
1585 <title><literal role="hook">precommit</literal>&emdash;before starting to commit a changeset</title>
1586 <para>\label{sec:hook:precommit}
1587 </para>
1589 <para>This hook is run before Mercurial begins to commit a new changeset.
1590 It is run before Mercurial has any of the metadata for the commit,
1591 such as the files to be committed, the commit message, or the commit
1592 date.
1593 </para>
1595 <para>One use for this hook is to disable the ability to commit new
1596 changesets, while still allowing incoming changesets. Another is to
1597 run a build or test, and only allow the commit to begin if the build
1598 or test succeeds.
1599 </para>
1601 <para>Parameters to this hook:
1602 </para>
1603 <itemizedlist>
1604 <listitem><para><literal>parent1</literal>: A changeset ID. The changeset ID of the first
1605 parent of the working directory.
1606 </para>
1607 </listitem>
1608 <listitem><para><literal>parent2</literal>: A changeset ID. The changeset ID of the second
1609 parent of the working directory.
1610 </para>
1611 </listitem></itemizedlist>
1612 <para>If the commit proceeds, the parents of the working directory will
1613 become the parents of the new changeset.
1614 </para>
1616 <para>See also: <literal role="hook">commit</literal> (section <xref linkend="sec:hook:commit"/>),
1617 <literal role="hook">pretxncommit</literal> (section <xref linkend="sec:hook:pretxncommit"/>)
1618 </para>
1620 </sect2>
1621 <sect2>
1622 <title><literal role="hook">preoutgoing</literal>&emdash;before starting to propagate changesets</title>
1623 <para>\label{sec:hook:preoutgoing}
1624 </para>
1626 <para>This hook is invoked before Mercurial knows the identities of the
1627 changesets to be transmitted.
1628 </para>
1630 <para>One use for this hook is to prevent changes from being transmitted to
1631 another repository.
1632 </para>
1634 <para>Parameters to this hook:
1635 </para>
1636 <itemizedlist>
1637 <listitem><para><literal>source</literal>: A string. The source of the operation that is
1638 attempting to obtain changes from this repository (see
1639 section <xref linkend="sec:hook:sources"/>). See the documentation for the
1640 <literal>source</literal> parameter to the <literal role="hook">outgoing</literal> hook, in
1641 section <xref linkend="sec:hook:outgoing"/>, for possible values of this
1642 parameter.
1643 </para>
1644 </listitem>
1645 <listitem><para><literal>url</literal>: A URL. The location of the remote repository, if
1646 known. See section <xref linkend="sec:hook:url"/> for more information.
1647 </para>
1648 </listitem></itemizedlist>
1650 <para>See also: <literal role="hook">outgoing</literal> (section <xref linkend="sec:hook:outgoing"/>)
1651 </para>
1653 </sect2>
1654 <sect2>
1655 <title><literal role="hook">pretag</literal>&emdash;before tagging a changeset</title>
1656 <para>\label{sec:hook:pretag}
1657 </para>
1659 <para>This controlling hook is run before a tag is created. If the hook
1660 succeeds, creation of the tag proceeds. If the hook fails, the tag is
1661 not created.
1662 </para>
1664 <para>Parameters to this hook:
1665 </para>
1666 <itemizedlist>
1667 <listitem><para><literal>local</literal>: A boolean. Whether the tag is local to this
1668 repository instance (i.e. stored in <filename role="special">.hg/localtags</filename>) or
1669 managed by Mercurial (stored in <filename role="special">.hgtags</filename>).
1670 </para>
1671 </listitem>
1672 <listitem><para><literal>node</literal>: A changeset ID. The ID of the changeset to be tagged.
1673 </para>
1674 </listitem>
1675 <listitem><para><literal>tag</literal>: A string. The name of the tag to be created.
1676 </para>
1677 </listitem></itemizedlist>
1679 <para>If the tag to be created is revision-controlled, the <literal role="hook">precommit</literal>
1680 and <literal role="hook">pretxncommit</literal> hooks (sections <xref linkend="sec:hook:commit"/>
1681 and <xref linkend="sec:hook:pretxncommit"/>) will also be run.
1682 </para>
1684 <para>See also: <literal role="hook">tag</literal> (section <xref linkend="sec:hook:tag"/>)
1685 </para>
1687 <para>\subsection{<literal role="hook">pretxnchangegroup</literal>&emdash;before completing addition of
1688 remote changesets}
1689 \label{sec:hook:pretxnchangegroup}
1690 </para>
1692 <para>This controlling hook is run before a transaction&emdash;that manages the
1693 addition of a group of new changesets from outside the
1694 repository&emdash;completes. If the hook succeeds, the transaction
1695 completes, and all of the changesets become permanent within this
1696 repository. If the hook fails, the transaction is rolled back, and
1697 the data for the changesets is erased.
1698 </para>
1700 <para>This hook can access the metadata associated with the almost-added
1701 changesets, but it should not do anything permanent with this data.
1702 It must also not modify the working directory.
1703 </para>
1705 <para>While this hook is running, if other Mercurial processes access this
1706 repository, they will be able to see the almost-added changesets as if
1707 they are permanent. This may lead to race conditions if you do not
1708 take steps to avoid them.
1709 </para>
1711 <para>This hook can be used to automatically vet a group of changesets. If
1712 the hook fails, all of the changesets are <quote>rejected</quote> when the
1713 transaction rolls back.
1714 </para>
1716 <para>Parameters to this hook:
1717 </para>
1718 <itemizedlist>
1719 <listitem><para><literal>node</literal>: A changeset ID. The changeset ID of the first
1720 changeset in the group that was added. All changesets between this
1721 and \index{tags!<literal>tip</literal>}<literal>tip</literal>, inclusive, were added by
1722 a single <command role="hg-cmd">hg pull</command>, <command role="hg-cmd">hg push</command> or <command role="hg-cmd">hg unbundle</command>.
1723 </para>
1724 </listitem>
1725 <listitem><para><literal>source</literal>: A string. The source of these changes. See
1726 section <xref linkend="sec:hook:sources"/> for details.
1727 </para>
1728 </listitem>
1729 <listitem><para><literal>url</literal>: A URL. The location of the remote repository, if
1730 known. See section <xref linkend="sec:hook:url"/> for more information.
1731 </para>
1732 </listitem></itemizedlist>
1734 <para>See also: <literal role="hook">changegroup</literal> (section <xref linkend="sec:hook:changegroup"/>),
1735 <literal role="hook">incoming</literal> (section <xref linkend="sec:hook:incoming"/>),
1736 <literal role="hook">prechangegroup</literal> (section <xref linkend="sec:hook:prechangegroup"/>)
1737 </para>
1739 </sect2>
1740 <sect2>
1741 <title><literal role="hook">pretxncommit</literal>&emdash;before completing commit of new changeset</title>
1742 <para>\label{sec:hook:pretxncommit}
1743 </para>
1745 <para>This controlling hook is run before a transaction&emdash;that manages a new
1746 commit&emdash;completes. If the hook succeeds, the transaction completes
1747 and the changeset becomes permanent within this repository. If the
1748 hook fails, the transaction is rolled back, and the commit data is
1749 erased.
1750 </para>
1752 <para>This hook can access the metadata associated with the almost-new
1753 changeset, but it should not do anything permanent with this data. It
1754 must also not modify the working directory.
1755 </para>
1757 <para>While this hook is running, if other Mercurial processes access this
1758 repository, they will be able to see the almost-new changeset as if it
1759 is permanent. This may lead to race conditions if you do not take
1760 steps to avoid them.
1761 </para>
1763 <para>Parameters to this hook:
1764 </para>
1765 <itemizedlist>
1766 <listitem><para><literal>node</literal>: A changeset ID. The changeset ID of the newly
1767 committed changeset.
1768 </para>
1769 </listitem>
1770 <listitem><para><literal>parent1</literal>: A changeset ID. The changeset ID of the first
1771 parent of the newly committed changeset.
1772 </para>
1773 </listitem>
1774 <listitem><para><literal>parent2</literal>: A changeset ID. The changeset ID of the second
1775 parent of the newly committed changeset.
1776 </para>
1777 </listitem></itemizedlist>
1779 <para>See also: <literal role="hook">precommit</literal> (section <xref linkend="sec:hook:precommit"/>)
1780 </para>
1782 </sect2>
1783 <sect2>
1784 <title><literal role="hook">preupdate</literal>&emdash;before updating or merging working directory</title>
1785 <para>\label{sec:hook:preupdate}
1786 </para>
1788 <para>This controlling hook is run before an update or merge of the working
1789 directory begins. It is run only if Mercurial's normal pre-update
1790 checks determine that the update or merge can proceed. If the hook
1791 succeeds, the update or merge may proceed; if it fails, the update or
1792 merge does not start.
1793 </para>
1795 <para>Parameters to this hook:
1796 </para>
1797 <itemizedlist>
1798 <listitem><para><literal>parent1</literal>: A changeset ID. The ID of the parent that the
1799 working directory is to be updated to. If the working directory is
1800 being merged, it will not change this parent.
1801 </para>
1802 </listitem>
1803 <listitem><para><literal>parent2</literal>: A changeset ID. Only set if the working
1804 directory is being merged. The ID of the revision that the working
1805 directory is being merged with.
1806 </para>
1807 </listitem></itemizedlist>
1809 <para>See also: <literal role="hook">update</literal> (section <xref linkend="sec:hook:update"/>)
1810 </para>
1812 </sect2>
1813 <sect2>
1814 <title><literal role="hook">tag</literal>&emdash;after tagging a changeset</title>
1815 <para>\label{sec:hook:tag}
1816 </para>
1818 <para>This hook is run after a tag has been created.
1819 </para>
1821 <para>Parameters to this hook:
1822 </para>
1823 <itemizedlist>
1824 <listitem><para><literal>local</literal>: A boolean. Whether the new tag is local to this
1825 repository instance (i.e. stored in <filename role="special">.hg/localtags</filename>) or
1826 managed by Mercurial (stored in <filename role="special">.hgtags</filename>).
1827 </para>
1828 </listitem>
1829 <listitem><para><literal>node</literal>: A changeset ID. The ID of the changeset that was
1830 tagged.
1831 </para>
1832 </listitem>
1833 <listitem><para><literal>tag</literal>: A string. The name of the tag that was created.
1834 </para>
1835 </listitem></itemizedlist>
1837 <para>If the created tag is revision-controlled, the <literal role="hook">commit</literal> hook
1838 (section <xref linkend="sec:hook:commit"/>) is run before this hook.
1839 </para>
1841 <para>See also: <literal role="hook">pretag</literal> (section <xref linkend="sec:hook:pretag"/>)
1842 </para>
1844 </sect2>
1845 <sect2>
1846 <title><literal role="hook">update</literal>&emdash;after updating or merging working directory</title>
1847 <para>\label{sec:hook:update}
1848 </para>
1850 <para>This hook is run after an update or merge of the working directory
1851 completes. Since a merge can fail (if the external <command>hgmerge</command>
1852 command fails to resolve conflicts in a file), this hook communicates
1853 whether the update or merge completed cleanly.
1854 </para>
1856 <itemizedlist>
1857 <listitem><para><literal>error</literal>: A boolean. Indicates whether the update or
1858 merge completed successfully.
1859 </para>
1860 </listitem>
1861 <listitem><para><literal>parent1</literal>: A changeset ID. The ID of the parent that the
1862 working directory was updated to. If the working directory was
1863 merged, it will not have changed this parent.
1864 </para>
1865 </listitem>
1866 <listitem><para><literal>parent2</literal>: A changeset ID. Only set if the working
1867 directory was merged. The ID of the revision that the working
1868 directory was merged with.
1869 </para>
1870 </listitem></itemizedlist>
1872 <para>See also: <literal role="hook">preupdate</literal> (section <xref linkend="sec:hook:preupdate"/>)
1873 </para>
1875 </sect2>
1876 </sect1>
1877 </chapter>
1879 <!--
1880 local variables:
1881 sgml-parent-document: ("00book.xml" "book" "chapter")
1882 end:
1883 -->