1. Christian Wyglendowski
  2. Mercurial Version Info Plugin



Mercurial Version Info Plugin


This plugin provides a way to easily record repository version information to a .py file that you can use at runtime in your code to display version information to your users. It provides a hook that can be run on commit and update.

The version file that is generated isn't meant to be versioned itself, but is meant to be distributed with your application. You should probably code defensively in case it isn't present for one reason or another though.

The Version Info File

The file that gets generated looks like this:

revision_id = '4519682deeb7cc8ca370410c251e9352ff45b1d8'
revision_number = 39
branch = 'default'
tags = ['tip']
date = 'Wed May 12 15:03:58 2010'


It's probably best to specify the settings below in your repo-local .hg/hgrc file instead of site wide, but do what works best for you.

To use the hook and extension you need to enable them in your .hgrc like so:

commit.versioninfo = python:hgversioninfo.hook
update.versioninfo = python:hgversioninfo.hook

version_file_path = relative/to/your/repo/version.py



The post-commit and update hooks are run automatically. A file with version info will appear at the path that you specify upon every commit and update.