comparison en/hook.tex @ 39:576fef93bb49

Further content for hook chapter.
author Bryan O'Sullivan <bos@serpentine.com>
date Wed, 19 Jul 2006 16:32:10 -0700
parents b49a7dd4e564
children b2fe9964b21b
comparison
equal deleted inserted replaced
38:b49a7dd4e564 39:576fef93bb49
379 arguments are other keyword arguments. Which ones are passed in 379 arguments are other keyword arguments. Which ones are passed in
380 depends on the hook being called, but a hook can ignore arguments it 380 depends on the hook being called, but a hook can ignore arguments it
381 doesn't care about by dropping them into a keyword argument dict, as 381 doesn't care about by dropping them into a keyword argument dict, as
382 with \texttt{**kwargs} above. 382 with \texttt{**kwargs} above.
383 383
384 \section{Hook reference}
385
386
387 \subsection{In-process hook execution}
388
389 An in-process hook is called with arguments of the following form:
390 \begin{codesample2}
391 def myhook(ui, repo, **kwargs):
392 pass
393 \end{codesample2}
394 The \texttt{ui} parameter is a \pymodclass{mercurial.ui}{ui} object.
395 The \texttt{repo} parameter is a
396 \pymodclass{mercurial.localrepo}{localrepository} object. The
397 names and values of the \texttt{**kwargs} parameters depend on the
398 hook being invoked, with the following common features:
399 \begin{itemize}
400 \item If a parameter is named \texttt{node} or
401 \texttt{parent\emph{N}}, it will contain a hexadecimal changeset ID.
402 The empty string is used to represent ``null changeset ID'' instead
403 of a string of zeroes.
404 \item Boolean-valued parameters are represented as Python
405 \texttt{bool} objects.
406 \end{itemize}
407
408 An in-process hook is called without a change to the process's working
409 directory (unlike external hooks, which are run in the root of the
410 repository). It must not change the process's working directory. If
411 it were to do so, it would probably cause calls to the Mercurial API,
412 or operations after the hook finishes, to fail.
413
414 If a hook returns a boolean ``false'' value, it is considered to
415 have succeeded. If it returns a boolean ``true'' value or raises an
416 exception, it is considered to have failed.
417
418 \subsection{External hook execution}
419
420 An external hook is passed to the user's shell for execution, so
421 features of that shell, such as variable substitution and command
422 redirection, are available. The hook is run in the root directory of
423 the repository.
424
425 Hook parameters are passed to the hook as environment variables. Each
426 environment variable's name is converted in upper case and prefixed
427 with the string ``\texttt{HG\_}''. For example, if the name of a
428 parameter is ``\texttt{node}'', the name of the environment variable
429 representing that parameter will be ``\texttt{HG\_NODE}''.
430
431 A boolean parameter is represented as the string ``\texttt{1}'' for
432 ``true'', ``\texttt{0}'' for ``false''. If an environment variable is
433 named \envar{HG\_NODE}, \envar{HG\_PARENT1} or \envar{HG\_PARENT2}, it
434 contains a changeset ID represented as a hexadecimal string. The
435 empty string is used to represent ``null changeset ID'' instead of a
436 string of zeroes.
437
438 If a hook exits with a status of zero, it is considered to have
439 succeeded. If it exits with a non-zero status, it is considered to
440 have failed.
441
442 \subsection{The \hook{changegroup} hook}
443 \label{sec:hook:changegroup}
444
445 Parameters to this hook:
446 \begin{itemize}
447 \item[\texttt{node}] The changeset ID of the first changeset in the
448 group that was added. All changesets between this and
449 \index{tags!\texttt{tip}}\texttt{tip}, inclusive, were added by a
450 single \hgcmd{pull}, \hgcmd{push} or \hgcmd{unbundle}.
451 \end{itemize}
452
453
454 \subsection{The \hook{commit} hook}
455 \label{sec:hook:commit}
456
457 Parameters to this hook:
458 \begin{itemize}
459 \item[\texttt{node}] The changeset ID of the newly committed
460 changeset.
461 \item[\texttt{parent1}] The changeset ID of the first parent of the
462 newly committed changeset.
463 \item[\texttt{parent2}] The changeset ID of the second parent of the
464 newly committed changeset.
465 \end{itemize}
384 466
385 %%% Local Variables: 467 %%% Local Variables:
386 %%% mode: latex 468 %%% mode: latex
387 %%% TeX-master: "00book" 469 %%% TeX-master: "00book"
388 %%% End: 470 %%% End: