Online Book Reader

Home Category

Mercurial_ The Definitive Guide - Bryan O'Sullivan [80]

By Root 904 0
a message. If a diff is longer than this, it is truncated. By default, this is set to 300. Set this to 0 to omit diffs from notification emails.

sources: A list of sources of changesets to consider. This lets you limit notify to only sending out email about changes that remote users pushed into this repository via a server, for example. See Sources of changesets for the sources you can specify here.

If you set the baseurl item in the web section, you can use it in a template; it will be available as webroot.

Here is an example set of notify configuration information:

[notify]

# really send email

test = false

# subscriber data lives in the notify repo

config = /home/hg/repos/notify/notify.conf

# repos live in /home/hg/repos on server, so strip 4 "/" chars

strip = 4

template = X-Hg-Repo: {webroot}\n

Subject: {webroot}: {desc|firstline|strip}\n

From: {author}

\n\n

changeset {node|short} in {root}

\n\ndetails:

{baseurl}{webroot}?cmd=changeset;node={node|short}

description: {desc|tabindent|strip}

[web]

baseurl =

http://hg.example.com/

This will produce a message that looks like the following:

X-Hg-Repo: tests/slave

Subject: tests/slave: Handle error case when slave has no buffers

Date: Wed, 2 Aug 2006 15:25:46 -0700 (PDT)

changeset 3cba9bfe74b5 in /home/hg/repos/tests/slave

details:

http://hg.example.com/tests/slave?cmd=changeset;node=3cba9bfe74b5

description: Handle error case when slave has no buffers

diffs (54 lines):

diff -r 9d95df7cf2ad -r 3cba9bfe74b5 include/tests.h

--- a/include/tests.h Wed Aug 02 15:19:52 2006 -0700

+++ b/include/tests.h Wed Aug 02 15:25:26 2006 -0700

@@ -212,6 +212,15 @@ static __inline__

void test_headers(void *h)

[...snip...]

Testing and troubleshooting

Do not forget that by default, the notify extension will not send any mail until you explicitly configure it to do so, by setting test to false. Until you do that, it simply prints the message it would send.

Information for Writers of Hooks

In-Process Hook Execution

An in-process hook is called with arguments of the following form:

def myhook(ui, repo, **kwargs): pass

The ui parameter is a ui object. The repo parameter is a localrepository object. The names and values of the **kwargs parameters depend on the hook being invoked, with the following common features:

If a parameter is named node or parentN, it will contain a hexadecimal changeset ID. The empty string is used to represent “null changeset ID” instead of a string of zeros.

If a parameter is named url, it will contain the URL of a remote repository, if that can be determined.

Boolean-valued parameters are represented as Python bool objects.

An in-process hook is called without a change to the process’s working directory (unlike external hooks, which are run in the root of the repository). It must not change the process’s working directory, or it will cause any calls it makes into the Mercurial API to fail.

If a hook returns a boolean “false” value, it is considered to have succeeded. If it returns a boolean “true” value or raises an exception, it is considered to have failed. A useful way to think of the calling convention is “tell me if you fail.”

Note that changeset IDs are passed into Python hooks as hexadecimal strings, not the binary hashes that Mercurial’s APIs normally use. To convert a hash from hex to binary, use the bin function.

External Hook Execution

An external hook is passed to the shell of the user running Mercurial. Features of that shell, such as variable substitution and command redirection, are available. The hook is run in the root directory of the repository (unlike in-process hooks, which are run in the same directory that Mercurial was run in).

Hook parameters are passed to the hook as environment variables. Each environment variable’s name is converted to uppercase and prefixed with the string HG_. For example, if the name of a parameter is node, the name of the environment variable representing that parameter will be HG_NODE.

A boolean parameter is represented as

Return Main Page Previous Page Next Page

®Online Book Reader