hgbook

changeset 62:8806b2875f10

Finish off a big whack of content for the hook chapter.
author Bryan O'Sullivan <bos@serpentine.com>
date Fri Aug 04 13:29:38 2006 -0700 (2006-08-04)
parents 39ea14398861
children a00b562b4598
files en/99defs.tex en/hook.tex
line diff
     1.1 --- a/en/99defs.tex	Fri Aug 04 05:28:08 2006 -0700
     1.2 +++ b/en/99defs.tex	Fri Aug 04 13:29:38 2006 -0700
     1.3 @@ -55,7 +55,7 @@
     1.4  
     1.5  % Named item in a hgrc file section.
     1.6  \newcommand{\rcitem}[2]{\index{\texttt{hgrc} file!\texttt{#1}
     1.7 -    section!\texttt{#2} entry}\texttt{#1.#2}}
     1.8 +    section!\texttt{#2} entry}\texttt{#2}}
     1.9  
    1.10  % hgrc file.
    1.11  \newcommand{\hgrc}{\index{\texttt{hgrc} file}\texttt{hgrc}}
    1.12 @@ -74,6 +74,10 @@
    1.13  \newcommand{\pymodclass}[2]{\index{\texttt{#1} module!\texttt{#2}
    1.14      class}\texttt{#1.#2}}
    1.15  
    1.16 +% Python function in a module.
    1.17 +\newcommand{\pymodfunc}[2]{\index{\texttt{#1} module!\texttt{#2}
    1.18 +    function}\texttt{#1.#2}}
    1.19 +
    1.20  % Note: blah blah.
    1.21  \newsavebox{\notebox}
    1.22  \newenvironment{note}%
     2.1 --- a/en/hook.tex	Fri Aug 04 05:28:08 2006 -0700
     2.2 +++ b/en/hook.tex	Fri Aug 04 13:29:38 2006 -0700
     2.3 @@ -513,11 +513,423 @@
     2.4  
     2.5  This extension implements access control based on the identity of the
     2.6  user performing a push, \emph{not} on who committed the changesets
     2.7 -they're pushing.  (If access control based on committer was to work
     2.8 -properly, it would require commits to be cryptographically signed,
     2.9 -which is an onerous and hence unusual policy to enforce.)
    2.10 -
    2.11 -XXX More help.
    2.12 +they're pushing.  It makes sense to use this hook only if you have a
    2.13 +locked-down server environment that authenticates remote users, and
    2.14 +you want to be sure that only specific users are allowed to push
    2.15 +changes to that server.
    2.16 +
    2.17 +\subsubsection{Configuring the \hook{acl} hook}
    2.18 +
    2.19 +In order to manage incoming changesets, the \hgext{acl} hook must be
    2.20 +used as a \hook{pretxnchangegroup} hook.  This lets it see which files
    2.21 +are modified by each incoming changeset, and roll back a group of
    2.22 +changesets if they modify ``forbidden'' files.  Example:
    2.23 +\begin{codesample2}
    2.24 +  [hooks]
    2.25 +  pretxnchangegroup.acl = python:hgext.acl.hook
    2.26 +\end{codesample2}
    2.27 +
    2.28 +The \hgext{acl} extension is configured using three sections.  
    2.29 +
    2.30 +The \rcsection{acl} section has only one entry, \rcitem{acl}{sources},
    2.31 +which lists the sources of incoming changesets that the hook should
    2.32 +pay attention to.  You don't normally need to configure this section.
    2.33 +\begin{itemize}
    2.34 +\item[\texttt{serve}] Control incoming changesets that are arriving
    2.35 +  from a remote repository over http or ssh.  This is the default
    2.36 +  value of \rcitem{acl}{sources}, and usually the only setting you'll
    2.37 +  need for this configuration item.
    2.38 +\item[\texttt{pull}] Control incoming changesets that are arriving via
    2.39 +  a pull from a local repository.
    2.40 +\item[\texttt{push}] Control incoming changesets that are arriving via
    2.41 +  a push from a local repository.
    2.42 +\item[\texttt{bundle}] Control incoming changesets that are arriving
    2.43 +  from another repository via a bundle.
    2.44 +\end{itemize}
    2.45 +
    2.46 +The \rcsection{acl.allow} section controls the users that are allowed to
    2.47 +add changesets to the repository.  If this section is not present, all
    2.48 +users that are not explicitly denied are allowed.  If this section is
    2.49 +present, all users that are not explicitly allowed are denied (so an
    2.50 +empty section means that all users are denied).
    2.51 +
    2.52 +The \rcsection{acl.deny} section determines which users are denied
    2.53 +from adding changesets to the repository.  If this section is not
    2.54 +present or is empty, no users are denied.
    2.55 +
    2.56 +The syntaxes for the \rcsection{acl.allow} and \rcsection{acl.deny}
    2.57 +sections are identical.  On the left of each entry is a glob pattern
    2.58 +that matches files or directories, relative to the root of the
    2.59 +repository; on the right, a user name.
    2.60 +
    2.61 +In the following example, the user \texttt{docwriter} can only push
    2.62 +changes to the \dirname{docs} subtree of the repository, while
    2.63 +\texttt{intern} can push changes to any file or directory except
    2.64 +\dirname{source/sensitive}.
    2.65 +\begin{codesample2}
    2.66 +  [acl.allow]
    2.67 +  docs/** = docwriter
    2.68 +
    2.69 +  [acl.deny]
    2.70 +  source/sensitive/** = intern
    2.71 +\end{codesample2}
    2.72 +
    2.73 +\subsubsection{Testing and troubleshooting}
    2.74 +
    2.75 +If you want to test the \hgext{acl} hook, run it with Mercurial's
    2.76 +debugging output enabled.  Since you'll probably be running it on a
    2.77 +server where it's not convenient (or sometimes possible) to pass in
    2.78 +the \hggopt{--debug} option, don't forget that you can enable
    2.79 +debugging output in your \hgrc:
    2.80 +\begin{codesample2}
    2.81 +  [ui]
    2.82 +  debug = true
    2.83 +\end{codesample2}
    2.84 +With this enabled, the \hgext{acl} hook will print enough information
    2.85 +to let you figure out why it is allowing or forbidding pushes from
    2.86 +specific users.
    2.87 +
    2.88 +\subsection{\hgext{bugzilla}---integration with Bugzilla}
    2.89 +
    2.90 +The \hgext{bugzilla} extension adds a comment to a Bugzilla bug
    2.91 +whenever it finds a reference to that bug ID in a commit comment.  You
    2.92 +can install this hook on a shared server, so that any time a remote
    2.93 +user pushes changes to this server, the hook gets run.  
    2.94 +
    2.95 +It adds a comment to the bug that looks like this (you can configure
    2.96 +the contents of the comment---see below):
    2.97 +\begin{codesample2}
    2.98 +  Changeset aad8b264143a, made by Joe User <joe.user@domain.com> in
    2.99 +  the frobnitz repository, refers to this bug.
   2.100 +
   2.101 +  For complete details, see
   2.102 +  http://hg.domain.com/frobnitz?cmd=changeset;node=aad8b264143a
   2.103 +
   2.104 +  Changeset description:
   2.105 +        Fix bug 10483 by guarding against some NULL pointers
   2.106 +\end{codesample2}
   2.107 +The value of this hook is that it automates the process of updating a
   2.108 +bug any time a changeset refers to it.  If you configure the hook
   2.109 +properly, it makes it easy for people to browse straight from a
   2.110 +Bugzilla bug to a changeset that refers to that bug.
   2.111 +
   2.112 +You can use the code in this hook as a starting point for some more
   2.113 +exotic Bugzilla integration recipes.  Here are a few possibilities:
   2.114 +\begin{itemize}
   2.115 +\item Require that every changeset pushed to the server have a valid
   2.116 +  bug~ID in its commit comment.  In this case, you'd want to configure
   2.117 +  the hook as a \hook{pretxncommit} hook.  This would allow the hook
   2.118 +  to reject changes that didn't contain bug IDs.
   2.119 +\item Allow incoming changesets to automatically modify the
   2.120 +  \emph{state} of a bug, as well as simply adding a comment.  For
   2.121 +  example, the hook could recognise the string ``fixed bug 31337'' as
   2.122 +  indicating that it should update the state of bug 31337 to
   2.123 +  ``requires testing''.
   2.124 +\end{itemize}
   2.125 +
   2.126 +\subsubsection{Configuring the \hook{bugzilla} hook}
   2.127 +\label{sec:hook:bugzilla:config}
   2.128 +
   2.129 +You should configure this hook in your server's \hgrc\ as an
   2.130 +\hook{incoming} hook, for example as follows:
   2.131 +\begin{codesample2}
   2.132 +  [hooks]
   2.133 +  incoming.bugzilla = python:hgext.bugzilla.hook
   2.134 +\end{codesample2}
   2.135 +
   2.136 +Because of the specialised nature of this hook, and because Bugzilla
   2.137 +was not written with this kind of integration in mind, configuring
   2.138 +this hook is a somewhat involved process.
   2.139 +
   2.140 +Before you begin, you must install the MySQL bindings for Python on
   2.141 +the host(s) where you'll be running the hook.  If this is not
   2.142 +available as a binary package for your system, you can download it
   2.143 +from~\cite{web:mysql-python}.
   2.144 +
   2.145 +Configuration information for this hook lives in the
   2.146 +\rcsection{bugzilla} section of your \hgrc.
   2.147 +\begin{itemize}
   2.148 +\item[\texttt{version}] The version of Bugzilla installed on the
   2.149 +  server.  The database schema that Bugzilla uses changes
   2.150 +  occasionally, so this hook has to know exactly which schema to use.
   2.151 +  At the moment, the only version supported is \texttt{2.16}.
   2.152 +\item[\texttt{host}] The hostname of the MySQL server that stores your
   2.153 +  Bugzilla data.  The database must be configured to allow connections
   2.154 +  from whatever host you are running the \hook{bugzilla} hook on.
   2.155 +\item[\texttt{user}] The username with which to connect to the MySQL
   2.156 +  server.  The database must be configured to allow this user to
   2.157 +  connect from whatever host you are running the \hook{bugzilla} hook
   2.158 +  on.  This user must be able to access and modify Bugzilla tables.
   2.159 +  The default value of this item is \texttt{bugs}, which is the
   2.160 +  standard name of the Bugzilla user in a MySQL database.
   2.161 +\item[\texttt{password}] The MySQL password for the user you
   2.162 +  configured above.  This is stored as plain text, so you should make
   2.163 +  sure that unauthorised users cannot read the \hgrc\ file where you
   2.164 +  store this information.
   2.165 +\item[\texttt{db}] The name of the Bugzilla database on the MySQL
   2.166 +  server.  The default value of this item is \texttt{bugs}, which is
   2.167 +  the standard name of the MySQL database where Bugzilla stores its
   2.168 +  data.
   2.169 +\item[\texttt{notify}] If you want Bugzilla to send out a notification
   2.170 +  email to subscribers after this hook has added a comment to a bug,
   2.171 +  you will need this hook to run a command whenever it updates the
   2.172 +  database.  The command to run depends on where you have installed
   2.173 +  Bugzilla, but it will typically look something like this, if you
   2.174 +  have Bugzilla installed in \dirname{/var/www/html/bugzilla}:
   2.175 +  \begin{codesample4}
   2.176 +    cd /var/www/html/bugzilla && ./processmail %s nobody@nowhere.com
   2.177 +  \end{codesample4}
   2.178 +  The Bugzilla \texttt{processmail} program expects to be given a
   2.179 +  bug~ID (the hook replaces ``\texttt{\%s}'' with the bug~ID) and an
   2.180 +  email address.  It also expects to be able to write to some files in
   2.181 +  the directory that it runs in.  If Bugzilla and this hook are not
   2.182 +  installed on the same machine, you will need to find a way to run
   2.183 +  \texttt{processmail} on the server where Bugzilla is installed.
   2.184 +\end{itemize}
   2.185 +
   2.186 +\subsubsection{Mapping committer names to Bugzilla user names}
   2.187 +
   2.188 +By default, the \hgext{bugzilla} hook tries to use the email address
   2.189 +of a changeset's committer as the Bugzilla user name with which to
   2.190 +update a bug.  If this does not suit your needs, you can map committer
   2.191 +email addresses to Bugzilla user names using a \rcsection{usermap}
   2.192 +section.
   2.193 +
   2.194 +Each item in the \rcsection{usermap} section contains an email address
   2.195 +on the left, and a Bugzilla user name on the right.
   2.196 +\begin{codesample2}
   2.197 +  [usermap]
   2.198 +  jane.user@example.com = jane
   2.199 +\end{codesample2}
   2.200 +You can either keep the \rcsection{usermap} data in a normal \hgrc, or
   2.201 +tell the \hgext{bugzilla} hook to read the information from an
   2.202 +external \filename{usermap} file.  In the latter case, you can store
   2.203 +\filename{usermap} data by itself in (for example) a user-modifiable
   2.204 +repository.  This makes it possible to let your users maintain their
   2.205 +own \texttt{usermap} entries.  The main \hgrc\ file might look like
   2.206 +this:
   2.207 +\begin{codesample2}
   2.208 +  # regular hgrc file refers to external usermap file
   2.209 +  [bugzilla]
   2.210 +  usermap = /home/hg/repos/userdata/bugzilla-usermap.conf
   2.211 +\end{codesample2}
   2.212 +While the \filename{usermap} file that it refers to might look like
   2.213 +this:
   2.214 +\begin{codesample2}
   2.215 +  # bugzilla-usermap.conf - inside a hg repository
   2.216 +  [usermap]
   2.217 +  stephanie@example.com = steph
   2.218 +\end{codesample2}
   2.219 +
   2.220 +\subsubsection{Configuring the text that gets added to a bug}
   2.221 +
   2.222 +You can configure the text that this hook adds as a comment; you
   2.223 +specify it in the form of a Mercurial template.  Several \hgrc\
   2.224 +entries (still in the \rcsection{bugzilla} section) control this
   2.225 +behaviour.
   2.226 +\begin{itemize}
   2.227 +\item[\texttt{hgweb}] The base string to use when constructing a URL
   2.228 +  that will let users browse from a Bugzilla comment to view a
   2.229 +  changeset.  Example:
   2.230 +  \begin{codesample4}
   2.231 +    hgweb = http://hg.domain.com/
   2.232 +  \end{codesample4}
   2.233 +\item[\texttt{strip}] The number of leading path elements to strip
   2.234 +  from a repository's path name to construct a partial path for a URL.
   2.235 +  For example, if the repositories on your server live under
   2.236 +  \dirname{/home/hg/repos}, and you have a repository whose path is
   2.237 +  \dirname{/home/hg/repos/app/tests}, then setting \texttt{strip} to
   2.238 +  \texttt{4} will give a partial path of \dirname{app/tests}.  The
   2.239 +  hook will make this partial path available when expanding a
   2.240 +  template, as \texttt{webroot}.
   2.241 +\item[\texttt{template}] The text of the template to use.  In addition
   2.242 +  to the usual changeset-related variables, this template can use
   2.243 +  \texttt{hgweb} (the value of the \texttt{hgweb} configuration item
   2.244 +  above) and \texttt{webroot} (the path constructed using
   2.245 +  \texttt{strip} above).
   2.246 +\end{itemize}
   2.247 +
   2.248 +Here is an example set of \hgext{bugzilla} hook config information.
   2.249 +\begin{codesample2}
   2.250 +  [bugzilla]
   2.251 +  host = bugzilla.example.com
   2.252 +  password = mypassword
   2.253 +  version = 2.16
   2.254 +  # server-side repos live in /home/hg/repos, so strip 4 leading
   2.255 +  # separators
   2.256 +  strip = 4
   2.257 +  hgweb = http://hg.example.com/
   2.258 +  usermap = /home/hg/repos/notify/bugzilla.conf
   2.259 +  template = Changeset \{node|short\}, made by \{author\} in the \{webroot\}
   2.260 +    repo, refers to this bug.\\nFor complete details, see 
   2.261 +    \{hgweb\}\{webroot\}?cmd=changeset;node=\{node|short\}\\nChangeset
   2.262 +    description:\\n\\t\{desc|tabindent\}
   2.263 +\end{codesample2}
   2.264 +
   2.265 +\subsubsection{Testing and troubleshooting}
   2.266 +
   2.267 +The most common problems with configuring the \hgext{bugzilla} hook
   2.268 +relate to running Bugzilla's \filename{processmail} script and mapping
   2.269 +committer names to user names.
   2.270 +
   2.271 +Recall from section~\ref{sec:hook:bugzilla:config} above that the user
   2.272 +that runs the Mercurial process on the server is also the one that
   2.273 +will run the \filename{processmail} script.  The
   2.274 +\filename{processmail} script sometimes causes Bugzilla to write to
   2.275 +files in its configuration directory, and Bugzilla's configuration
   2.276 +files are usually owned by the user that your web server runs under.
   2.277 +
   2.278 +You can cause \filename{processmail} to be run with the suitable
   2.279 +user's identity using the \command{sudo} command.  Here is an example
   2.280 +entry for a \filename{sudoers} file.
   2.281 +\begin{codesample2}
   2.282 +  hg_user = (httpd_user) NOPASSWD: /var/www/html/bugzilla/processmail-wrapper %s
   2.283 +\end{codesample2}
   2.284 +This allows the \texttt{hg\_user} user to run a
   2.285 +\filename{processmail-wrapper} program under the identity of
   2.286 +\texttt{httpd\_user}.
   2.287 +
   2.288 +This indirection through a wrapper script is necessary, because
   2.289 +\filename{processmail} expects to be run with its current directory
   2.290 +set to wherever you installed Bugzilla; you can't specify that kind of
   2.291 +constraint in a \filename{sudoers} file.  The contents of the wrapper
   2.292 +script are simple:
   2.293 +\begin{codesample2}
   2.294 +  #!/bin/sh
   2.295 +  cd `dirname $0` && ./processmail "$1" nobody@example.com
   2.296 +\end{codesample2}
   2.297 +It doesn't seem to matter what email address you pass to
   2.298 +\filename{processmail}.
   2.299 +
   2.300 +If your \rcsection{usermap} is not set up correctly, users will see an
   2.301 +error message from the \hgext{bugzilla} hook when they push changes
   2.302 +to the server.  The error message will look like this:
   2.303 +\begin{codesample2}
   2.304 +  cannot find bugzilla user id for john.q.public@example.com
   2.305 +\end{codesample2}
   2.306 +What this means is that the committer's address,
   2.307 +\texttt{john.q.public@example.com}, is not a valid Bugzilla user name,
   2.308 +nor does it have an entry in your \rcsection{usermap} that maps it to
   2.309 +a valid Bugzilla user name.
   2.310 +
   2.311 +\subsection{\hgext{notify}---send email notifications}
   2.312 +
   2.313 +Although Mercurial's built-in web server provides RSS feeds of changes
   2.314 +in every repository, many people prefer to receive change
   2.315 +notifications via email.  The \hgext{notify} hook lets you send out
   2.316 +notifications to a set of email addresses whenever changesets arrive
   2.317 +that those subscribers are interested in.
   2.318 +
   2.319 +As with the \hgext{bugzilla} hook, the \hgext{notify} hook is
   2.320 +template-driven, so you can customise the contents of the notification
   2.321 +messages that it sends.
   2.322 +
   2.323 +By default, the \hgext{notify} hook includes a diff of every changeset
   2.324 +that it sends outd; you can limit the size of the diff, or turn this
   2.325 +feature off entirely.  It is useful for letting subscribers review
   2.326 +changes immediately, rather than clicking to follow a URL.
   2.327 +
   2.328 +\subsubsection{Configuring the \hgext{notify} hook}
   2.329 +
   2.330 +You can set up the \hgext{notify} hook to send one email message per
   2.331 +incoming changeset, or one per incoming group of changesets (all those
   2.332 +that arrived in a single pull or push).
   2.333 +\begin{codesample2}
   2.334 +  [hooks]
   2.335 +  # send one email per group of changes
   2.336 +  changegroup.notify = python:hgext.notify.hook
   2.337 +  # send one email per change
   2.338 +  incoming.notify = python:hgext.notify.hook
   2.339 +\end{codesample2}
   2.340 +
   2.341 +Configuration information for this hook lives in the
   2.342 +\rcsection{notify} section of a \hgrc\ file.
   2.343 +\begin{itemize}
   2.344 +\item[\rcitem{notify}{test}] By default, this hook does not send out
   2.345 +  email at all; instead, it prints the message that it \emph{would}
   2.346 +  send.  Set this item to \texttt{false} to allow email to be sent.
   2.347 +  The reason that sending of email is turned off by default is that it
   2.348 +  takes several tries to configure this extension exactly as you would
   2.349 +  like, and it would be bad form to spam subscribers with a number of
   2.350 +  ``broken'' notifications while you debug your configuration.
   2.351 +\item[\rcitem{notify}{config}] The path to a configuration file that
   2.352 +  contains subbscription information.  This is kept separate from the
   2.353 +  main \hgrc\ so that you can maintain it in a repository of its own.
   2.354 +  People can then clone that repository, update their subscriptions,
   2.355 +  and push the changes back to your server.
   2.356 +\item[\rcitem{notify}{strip}] The number of leading path separator
   2.357 +  characters to strip from a repository's path, when deciding whether
   2.358 +  a repository has subscribers.  For example, if the repositories on
   2.359 +  your server live in \dirname{/home/hg/repos}, and \hgext{notify} is
   2.360 +  considering a repository named \dirname{/home/hg/repos/shared/test},
   2.361 +  setting \rcitem{notify}{strip} to \texttt{4} will cause
   2.362 +  \hgext{notify} to trim the path it considers down to
   2.363 +  \dirname{shared/test}, and it will match subscribers against that.
   2.364 +\item[\rcitem{notify}{template}] The template text to use when sending
   2.365 +  messages.  This specifies both the contents of the message header
   2.366 +  and its body.
   2.367 +\item[\rcitem{notify}{maxdiff}] The maximum number of lines of diff
   2.368 +  data to append to the end of a message.  If a diff is longer than
   2.369 +  this, it is truncated.  By default, this is set to 300.  Set this to
   2.370 +  \texttt{0} to omit diffs from notification emails.
   2.371 +\item[\rcitem{notify}{sources}] A list of sources of changesets to
   2.372 +  consider.  This lets you limit \hgext{notify} to only sending out
   2.373 +  email about changes that remote users pushed into this repository
   2.374 +  via a server, for example.  See section~\ref{sec:hook:sources} for
   2.375 +  the sources you can specify here.
   2.376 +\end{itemize}
   2.377 +
   2.378 +If you set the \rcitem{web}{baseurl} item in the \rcsection{web}
   2.379 +section, you can use it in a template; it will be available as
   2.380 +\texttt{webroot}.
   2.381 +
   2.382 +Here is an example set of \hgext{notify} configuration information.
   2.383 +\begin{codesample2}
   2.384 +  [notify]
   2.385 +  # really send email
   2.386 +  test = false
   2.387 +  # subscriber data lives in the notify repo
   2.388 +  config = /home/hg/repos/notify/notify.conf
   2.389 +  # repos live in /home/hg/repos on server, so strip 4 "/" chars
   2.390 +  strip = 4
   2.391 +  template = X-Hg-Repo: \{webroot\}\\n\\\\
   2.392 +    Subject: \{webroot\}: \{desc|firstline|strip\}\\n\\\\
   2.393 +    From: \{author\}\\n\\\\
   2.394 +    \\n\\\\
   2.395 +    changeset \{node|short\} in \{root\}\\n\\\\
   2.396 +    details: \{baseurl\}\{webroot\}?cmd=changeset;node=\{node|short\}\\n\\\\
   2.397 +    description:\\n\\\\
   2.398 +    \\t\{desc|tabindent|strip\}
   2.399 +
   2.400 +  [web]
   2.401 +  baseurl = http://hg.example.com/
   2.402 +\end{codesample2}
   2.403 +
   2.404 +This will produce a message that looks like the following:
   2.405 +\begin{codesample2}
   2.406 +  X-Hg-Repo: tests/slave
   2.407 +  Subject: tests/slave: Handle error case when slave has no buffers
   2.408 +  Date: Wed,  2 Aug 2006 15:25:46 -0700 (PDT)
   2.409 +
   2.410 +  changeset 3cba9bfe74b5 in /home/hg/repos/tests/slave
   2.411 +  details: http://hg.example.com/tests/slave?cmd=changeset;node=3cba9bfe74b5
   2.412 +  description:
   2.413 +          Handle error case when slave has no buffers
   2.414 +  diffs (54 lines):
   2.415 +
   2.416 +  diff -r 9d95df7cf2ad -r 3cba9bfe74b5 include/tests.h
   2.417 +  --- a/include/tests.h      Wed Aug 02 15:19:52 2006 -0700
   2.418 +  +++ b/include/tests.h      Wed Aug 02 15:25:26 2006 -0700
   2.419 +  @@ -212,6 +212,15 @@ static __inline__ void test_headers(void *h)
   2.420 +  [...snip...]
   2.421 +\end{codesample2}
   2.422 +
   2.423 +\subsubsection{Testing and troubleshooting}
   2.424 +
   2.425 +Do not forget that by default, the \hgext{notify} extension \emph{will
   2.426 +  not send any mail} until you explicitly configure it to do so, by
   2.427 +setting \rcitem{notify}{test} to \texttt{false}.  Until you do that,
   2.428 +it simply prints the message it \emph{would} send.
   2.429  
   2.430  \section{Hook reference}
   2.431  \label{sec:hook:ref}
   2.432 @@ -539,26 +951,34 @@
   2.433    \texttt{parent\emph{N}}, it will contain a hexadecimal changeset ID.
   2.434    The empty string is used to represent ``null changeset ID'' instead
   2.435    of a string of zeroes.
   2.436 +\item If a parameter is named \texttt{url}, it will contain the URL of
   2.437 +  a remote repository, if that can be determined.
   2.438  \item Boolean-valued parameters are represented as Python
   2.439    \texttt{bool} objects.
   2.440  \end{itemize}
   2.441  
   2.442  An in-process hook is called without a change to the process's working
   2.443  directory (unlike external hooks, which are run in the root of the
   2.444 -repository).  It must not change the process's working directory.  If
   2.445 -it were to do so, it would probably cause calls to the Mercurial API,
   2.446 -or operations after the hook finishes, to fail.
   2.447 -
   2.448 -If a hook returns a boolean ``false'' value, it is considered to
   2.449 -have succeeded.  If it returns a boolean ``true'' value or raises an
   2.450 -exception, it is considered to have failed.
   2.451 +repository).  It must not change the process's working directory, or
   2.452 +it will cause any calls it makes into the Mercurial API to fail.
   2.453 +
   2.454 +If a hook returns a boolean ``false'' value, it is considered to have
   2.455 +succeeded.  If it returns a boolean ``true'' value or raises an
   2.456 +exception, it is considered to have failed.  A useful way to think of
   2.457 +the calling convention is ``tell me if you fail''.
   2.458 +
   2.459 +Note that changeset IDs are passed into Python hooks as hexadecimal
   2.460 +strings, not the binary hashes that Mercurial's APIs normally use.  To
   2.461 +convert a hash from hex to binary, use the
   2.462 +\pymodfunc{mercurial.node}{bin} function.
   2.463  
   2.464  \subsection{External hook execution}
   2.465  
   2.466 -An external hook is passed to the user's shell for execution, so
   2.467 -features of that shell, such as variable substitution and command
   2.468 +An external hook is passed to the shell of the user running Mercurial.
   2.469 +Features of that shell, such as variable substitution and command
   2.470  redirection, are available.  The hook is run in the root directory of
   2.471 -the repository.
   2.472 +the repository (unlike in-process hooks, which are run in the same
   2.473 +directory that Mercurial was run in).
   2.474  
   2.475  Hook parameters are passed to the hook as environment variables.  Each
   2.476  environment variable's name is converted in upper case and prefixed
   2.477 @@ -571,12 +991,64 @@
   2.478  named \envar{HG\_NODE}, \envar{HG\_PARENT1} or \envar{HG\_PARENT2}, it
   2.479  contains a changeset ID represented as a hexadecimal string.  The
   2.480  empty string is used to represent ``null changeset ID'' instead of a
   2.481 -string of zeroes.
   2.482 +string of zeroes.  If an environment variable is named
   2.483 +\envar{HG\_URL}, it will contain the URL of a remote repository, if
   2.484 +that can be determined.
   2.485  
   2.486  If a hook exits with a status of zero, it is considered to have
   2.487  succeeded.  If it exits with a non-zero status, it is considered to
   2.488  have failed.
   2.489  
   2.490 +\subsection{Finding out where changesets come from}
   2.491 +
   2.492 +A hook that involves the transfer of changesets between a local
   2.493 +repository and another may be able to find out information about the
   2.494 +``far side''.  Mercurial knows \emph{how} changes are being
   2.495 +transferred, and in many cases \emph{where} they are being transferred
   2.496 +to or from.
   2.497 +
   2.498 +\subsubsection{Sources of changesets}
   2.499 +\label{sec:hook:sources}
   2.500 +
   2.501 +Mercurial will tell a hook what means are, or were, used to transfer
   2.502 +changesets between repositories.  This is provided by Mercurial in a
   2.503 +Python parameter named \texttt{source}, or an environment variable named
   2.504 +\envar{HG\_SOURCE}.
   2.505 +
   2.506 +\begin{itemize}
   2.507 +\item[\texttt{serve}] Changesets are transferred to or from a remote
   2.508 +  repository over http or ssh.
   2.509 +\item[\texttt{pull}] Changesets are being transferred via a pull from
   2.510 +  one repository into another.
   2.511 +\item[\texttt{push}] Changesets are being transferred via a push from
   2.512 +  one repository into another.
   2.513 +\item[\texttt{bundle}] Changesets are being transferred to or from a
   2.514 +  bundle.
   2.515 +\end{itemize}
   2.516 +
   2.517 +\subsubsection{Where changes are going---remote repository URLs}
   2.518 +\label{sec:hook:url}
   2.519 +
   2.520 +When possible, Mercurial will tell a hook the location of the ``far
   2.521 +side'' of an activity that transfers changeset data between
   2.522 +repositories.  This is provided by Mercurial in a Python parameter
   2.523 +named \texttt{url}, or an environment variable named \envar{HG\_URL}.
   2.524 +
   2.525 +This information is not always known.  If a hook is invoked in a
   2.526 +repository that is being served via http or ssh, Mercurial cannot tell
   2.527 +where the remote repository is, but it may know where the client is
   2.528 +connecting from.  In such cases, the URL will take one of the
   2.529 +following forms:
   2.530 +\begin{itemize}
   2.531 +\item \texttt{remote:ssh:\emph{ip-address}}---remote ssh client, at
   2.532 +  the given IP address.
   2.533 +\item \texttt{remote:http:\emph{ip-address}}---remote http client, at
   2.534 +  the given IP address.  If the client is using SSL, this will be of
   2.535 +  the form \texttt{remote:https:\emph{ip-address}}.
   2.536 +\item Empty---no information could be discovered about the remote
   2.537 +  client.
   2.538 +\end{itemize}
   2.539 +
   2.540  \subsection{The \hook{changegroup} hook}
   2.541  \label{sec:hook:changegroup}
   2.542  
   2.543 @@ -597,6 +1069,10 @@
   2.544    changeset in the group that was added.  All changesets between this
   2.545    and \index{tags!\texttt{tip}}\texttt{tip}, inclusive, were added by
   2.546    a single \hgcmd{pull}, \hgcmd{push} or \hgcmd{unbundle}.
   2.547 +\item[\texttt{source}] A string.  The source of these changes.  See
   2.548 +  section~\ref{sec:hook:sources} for details.
   2.549 +\item[\texttt{url}] A URL.  The location of the remote repository, if
   2.550 +  known.  See section~\ref{sec:hook:url} for more information.
   2.551  \end{itemize}
   2.552  
   2.553  See also: \hook{incoming} (section~\ref{sec:hook:incoming}),
   2.554 @@ -638,6 +1114,10 @@
   2.555  \begin{itemize}
   2.556  \item[\texttt{node}] A changeset ID.  The ID of the newly added
   2.557    changeset.
   2.558 +\item[\texttt{source}] A string.  The source of these changes.  See
   2.559 +  section~\ref{sec:hook:sources} for details.
   2.560 +\item[\texttt{url}] A URL.  The location of the remote repository, if
   2.561 +  known.  See section~\ref{sec:hook:url} for more information.
   2.562  \end{itemize}
   2.563  
   2.564  See also: \hook{changegroup} (section~\ref{sec:hook:changegroup}) \hook{prechangegroup} (section~\ref{sec:hook:prechangegroup}), \hook{pretxnchangegroup} (section~\ref{sec:hook:pretxnchangegroup})
   2.565 @@ -656,12 +1136,15 @@
   2.566  \begin{itemize}
   2.567  \item[\texttt{node}] A changeset ID.  The changeset ID of the first
   2.568    changeset of the group that was sent.
   2.569 -\item[\texttt{source}] A string.  The source of the of the operation.
   2.570 -  If a remote client pulled changes from this repository,
   2.571 -  \texttt{source} will be \texttt{serve}.  If the client that obtained
   2.572 -  changes from this repository was local, \texttt{source} will be
   2.573 -  \texttt{bundle}, \texttt{pull}, or \texttt{push}, depending on the
   2.574 -  operation the client performed.
   2.575 +\item[\texttt{source}] A string.  The source of the of the operation
   2.576 +  (see section~\ref{sec:hook:sources}).  If a remote client pulled
   2.577 +  changes from this repository, \texttt{source} will be
   2.578 +  \texttt{serve}.  If the client that obtained changes from this
   2.579 +  repository was local, \texttt{source} will be \texttt{bundle},
   2.580 +  \texttt{pull}, or \texttt{push}, depending on the operation the
   2.581 +  client performed.
   2.582 +\item[\texttt{url}] A URL.  The location of the remote repository, if
   2.583 +  known.  See section~\ref{sec:hook:url} for more information.
   2.584  \end{itemize}
   2.585  
   2.586  See also: \hook{preoutgoing} (section~\ref{sec:hook:preoutgoing})
   2.587 @@ -678,10 +1161,18 @@
   2.588  transmitted.
   2.589  
   2.590  One use for this hook is to prevent external changes from being added
   2.591 -to a repository, for example to ``freeze'' a server-hosted branch
   2.592 -temporarily or permanently.
   2.593 -
   2.594 -This hook is not passed any parameters.
   2.595 +to a repository.  For example, you could use this to ``freeze'' a
   2.596 +server-hosted branch temporarily or permanently so that users cannot
   2.597 +push to it, while still allowing a local administrator to modify the
   2.598 +repository.
   2.599 +
   2.600 +Parameters to this hook:
   2.601 +\begin{itemize}
   2.602 +\item[\texttt{source}] A string.  The source of these changes.  See
   2.603 +  section~\ref{sec:hook:sources} for details.
   2.604 +\item[\texttt{url}] A URL.  The location of the remote repository, if
   2.605 +  known.  See section~\ref{sec:hook:url} for more information.
   2.606 +\end{itemize}
   2.607  
   2.608  See also: \hook{changegroup} (section~\ref{sec:hook:changegroup}),
   2.609  \hook{incoming} (section~\ref{sec:hook:incoming}), ,
   2.610 @@ -725,10 +1216,13 @@
   2.611  Parameters to this hook:
   2.612  \begin{itemize}
   2.613  \item[\texttt{source}] A string.  The source of the operation that is
   2.614 -  attempting to obtain changes from this repository.  See the
   2.615 -  documentation for the \texttt{source} parameter to the
   2.616 -  \hook{outgoing} hook, in section~\ref{sec:hook:outgoing}, for
   2.617 -  possible values of this parameter..
   2.618 +  attempting to obtain changes from this repository (see
   2.619 +  section~\ref{sec:hook:sources}).  See the documentation for the
   2.620 +  \texttt{source} parameter to the \hook{outgoing} hook, in
   2.621 +  section~\ref{sec:hook:outgoing}, for possible values of this
   2.622 +  parameter.
   2.623 +\item[\texttt{url}] A URL.  The location of the remote repository, if
   2.624 +  known.  See section~\ref{sec:hook:url} for more information.
   2.625  \end{itemize}
   2.626  
   2.627  See also: \hook{outgoing} (section~\ref{sec:hook:outgoing})
   2.628 @@ -778,8 +1272,17 @@
   2.629  the hook fails, all of the changesets are ``rejected'' when the
   2.630  transaction rolls back.
   2.631  
   2.632 -Parameters to this hook are the same as for the \hook{changegroup}
   2.633 -hook; see section~\ref{sec:hook:changegroup} for details.
   2.634 +Parameters to this hook:
   2.635 +\begin{itemize}
   2.636 +\item[\texttt{node}] A changeset ID.  The changeset ID of the first
   2.637 +  changeset in the group that was added.  All changesets between this
   2.638 +  and \index{tags!\texttt{tip}}\texttt{tip}, inclusive, were added by
   2.639 +  a single \hgcmd{pull}, \hgcmd{push} or \hgcmd{unbundle}.
   2.640 +\item[\texttt{source}] A string.  The source of these changes.  See
   2.641 +  section~\ref{sec:hook:sources} for details.
   2.642 +\item[\texttt{url}] A URL.  The location of the remote repository, if
   2.643 +  known.  See section~\ref{sec:hook:url} for more information.
   2.644 +\end{itemize}
   2.645  
   2.646  See also: \hook{changegroup} (section~\ref{sec:hook:changegroup}),
   2.647  \hook{incoming} (section~\ref{sec:hook:incoming}),
   2.648 @@ -803,8 +1306,15 @@
   2.649  is permanent.  This may lead to race conditions if you do not take
   2.650  steps to avoid them.
   2.651  
   2.652 -Parameters to this hook are the same as for the \hook{commit} hook;
   2.653 -see section~\ref{sec:hook:commit} for details.
   2.654 +Parameters to this hook:
   2.655 +\begin{itemize}
   2.656 +\item[\texttt{node}] A changeset ID.  The changeset ID of the newly
   2.657 +  committed changeset.
   2.658 +\item[\texttt{parent1}] A changeset ID.  The changeset ID of the first
   2.659 +  parent of the newly committed changeset.
   2.660 +\item[\texttt{parent2}] A changeset ID.  The changeset ID of the second
   2.661 +  parent of the newly committed changeset.
   2.662 +\end{itemize}
   2.663  
   2.664  See also: \hook{precommit} (section~\ref{sec:hook:precommit})
   2.665  
   2.666 @@ -834,8 +1344,15 @@
   2.667  
   2.668  This hook is run after a tag has been created.
   2.669  
   2.670 -Parameters to this hook are the same as for the \hook{pretag} hook;
   2.671 -see section~\ref{sec:hook:pretag} for details.
   2.672 +Parameters to this hook:
   2.673 +\begin{itemize}
   2.674 +\item[\texttt{local}] A boolean.  Whether the new tag is local to this
   2.675 +  repository instance (i.e.~stored in \sfilename{.hg/tags}) or managed
   2.676 +  by Mercurial (stored in \sfilename{.hgtags}).
   2.677 +\item[\texttt{node}] A changeset ID.  The ID of the changeset that was
   2.678 +  tagged.
   2.679 +\item[\texttt{tag}] A string.  The name of the tag that was created.
   2.680 +\end{itemize}
   2.681  
   2.682  If the created tag is revision-controlled, the \hook{commit} hook
   2.683  (section~\ref{sec:hook:commit}) is run before this hook.