Graphviz extension

Author: Katsunori FUJIWARA

Overview

This extension generates DOT language (of [http://www.graphviz.org/ Graphviz]) source to visualize changeset tree.

Graphviz allows you to get not only image(e.g. *.jpg) files, but also client side image map. So you can get HTML page which cooperates with hg serve.

This extension which works with Mercurial 0.9.3(and may be later) can be found at http://www.lares.dti.ne.jp/~foozy/fujiguruma/scm/graphviz.py .

Configuration

This extension is enabled by adding the following lines to your configuration file (hgrc), if you place graphviz.py in the directory where your python knows:

[extensions]
graphviz = 

Otherwise:

[extensions]
graphviz = /path/to/graphviz.py

Usage

hg graphviz [OPTIONS] [limit-spec ...]

Without limit-spec, graphviz recognizes all changesets as renderring target.

You can limit target changesets by revision range (see -r option) or datetime range(see -d option).

For revision range, you can use any of 'revision number', 'relative number to tip' 'short changeset ID', 'long changeset ID' or 'tag name'.

For datetime range, you should use XML Schema dateTime format, known as YYYY-MM-DDThh:mm:ss(middle T should be exactly T). But it is not so strongly restricted that you can specify 2007-99-99T99:99:99, for example.

limit-spec should be in one of three format.

  1. 'Start,End' format limits target changesets to ones between 'Start' and 'End'.

  2. 'Start,' format limits target changesets to ones after 'Start'.

  3. ',End' format limits target changesets to ones before 'End'.

ATTENTION: End is treated as inclusive, so you should specify 2007-12-31T24:00:00(or such one) to ignore changesets created after 2007, for example.

graphviz recognizes following options.

-r --revision  use revision to limit targets(default)
-d --datetime  use datetime to limit targets
-u --urlbase   url base for client side image map
-a --aliases   file with user name aliases
-f --format    format of changeset label (default: r)
   --hook      hook module to render node attribute

Label formatting

You can specify the format to render label for node corresponded to changeset in visualized graph.

Format string for -f option should consists of following characters.

For example, -f rUd causes renderring label 123/who committed <mail@address>/2007-01-01T00:00:00.

User name aliasing

To reduce label length when username is used as part of it, you can specify alias configuration file. This file should consists lines in the following format, or lines which start with '#' as comment.

AliasName=ActualName

Alias conversion is enabled when you use u(small u) as label format.

Client side image map

For example, you can get HTML page imagemap.html, which cooperates with hg serve running at local host port 8000, by following procedure.

% hg graphviz ... -u http://localhost:8000 ... > imagemap.dot

% dot -Tjpg -o imagemap.jpg imagemap.dot

% cat <<END > imagemap.html
<html>
<head><title>Changeset graph between .... </title></head>
<body>
<image src="imagemap.jpg" usemap="_anonymous_0">
END

% dot -Tcmapx imagemap.dot >> imagemap.html

% cat <<END >> imagemap.html
</body>
</html>
END

Renderring customize

Please specify module name by --hook option, if you want to customize attribute of 'node'. Such module should have the function definition shown below(name of function should be attrhook exactlly):

def attrhook(repository, revision, node, changes):

Arguments are:

Non empty string returned by attrhook is joinned to attribute of 'node', so you can highlight 'node's corresponded to changesets which certain use made by code shown below, for example.

def attrhook(repository, revision, node, changes):
    return ((changes[1] == 'someone highlighted')
            and 'style = "filled", color = "black", fontcolor = "white"'
            or None)


CategoryExtension