17 Mar 2008 aleix   » (Journeyer)

Handling external dependencies with Mercurial

In order to add external repository dependencies in Mercurial, I have created an extension similar to the multi-project management feature of GNU arch. This can be probably done with other existent extensions, but I have not been able to found one that exactly met my needs (the Forest extension can be used for non-versioned Mercurial dependencies, and, in fact, they could be used together, but it is not exactly the same). So please, if anyone knows similar extensions, I would happy to know it. My friend Lluís gave me the idea to also handle non-Mercurial dependencies, so thanks from here!

To download it just type:

hg clone http://hg.hacks-galore.org/aleix/hgdeps/

You can also browse it online.

The extension consists of two commands: deps and depsclone. Below, I am pasting the help of the deps command.

This extension is useful when a repository might depend on some external dependencies: other repositories (Mercurial, CVS, Subversion…), files not handled by a SCM tool or some other dependencies.

To enable this extension, add this to your global .hgrc file (or to your repository .hg/hgrc file):

hgext.deps =
# or, if deps.py is not in the hgext dir:
# deps = /path/to/deps.py

In order to define these external dependencies, you need to add a section [deps] in your repository .hg/hgrc file (or in the global .hgrc) where you will define how to find them. As an example, let’s say that our repository depends on two external libraries managed by different SCM tools: ‘libfoo’ managed by Mercurial and ‘libbar’ managed by CVS.

aliases = libfoo, libbar
alias.libfoo = /path/to/libfoo
alias.libbar = :pserver:anonymous@cvs.server.org:/sources/bar
alias.libbar.command = cvs -z3 -d$source co -r $rev -d $dest bar

Two aliases have been defined, one for each library, and also the sources where the libraries can be obtained. ‘libbar’ has two options: the library location and the CVS command to use in order to get the library. For ‘libfoo’ only a path to the Mercurial repository has been specified. $rev, $source, and $dest are substitution placeholders and will be explained later.

Once the location of the depedencies have been defined, dependency lists can be created. A depedency list has an associated name. Following the example above, two depedency lists will be created, one for version 0.9.1 of our repository and another for version 1.0. 0.9.1 and 1.0 will be used as the name of the lists.

f24139319bdb    libfoo    lib/foo
v0r8_0          libbar    lib/bar

3a9b061bada1    libfoo    lib/foo
v0r7_8          libbar    lib/bar

A dependency is defined by three fields: a revision name, the alias of the external dependency and a destination directory. The alias must be one of the aliases defined in the [deps] section (see above). The revision name will be substituted for the placeholder $rev also seen before. For Mercurial, the revision name will just be a Mercurial revision of the external repository. Finally, the destination directory will be substituted for $dest.

To facilitate version control, distribution, and merging of dependencies, they are stored as a file named ‘.hgdeps’ which is managed similarly to other project files and can be hand-edited if necessary.

Syndicated 2008-03-17 18:08:51 from axelio

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!