Why no "hg id --template..." ?

Giorgos Keramidas keramida at ceid.upatras.gr
Sat Mar 29 18:43:49 CDT 2008

On Fri, 28 Mar 2008 15:11:22 +0100, Marcin Kasperski <Marcin.Kasperski at softax.com.pl> wrote:
> I'd like to grab some information about working directory (revision,
> last change date etc). And just spotted, that while "hg tip" is able
> to provide everything, "hg id" is limited to just numeric revision id,
> branches and tags.
> I know that I can write
>    hg log -r `hg id -n`
> but it a) requires backticks (non-Win in particular), b) forces
> two processess spawns for trivial op and c) fails with
>    abort: unknown revision '188eb551b743+'!
> if there is any uncommited change.
> I ended up writing
>    hg log -r `hg id -n | sed s/\+//` --template "my template here"
> glazed at the incredible beauty of this command and started to write
> this post ;-)
> PS Just in case: I want to extract some revision-based data for the build.
> So it is interesting which revision is active, not what is the tip.

As Matt already wrote, you can use `hg log -r .' to get revision data
for the working directory.

For automated builds, it may be useful to use a predefined template
which directly generates something you can `include' in your build
scripts or Makefiles:

    $ TEMPLATE='REV={rev}; NODE={node|short}; export REV NODE\n'
    $ hg log -r. --template "${TEMPLATE}"
    REV=6389; NODE=0231f763ebc8; export REV NODE

More information about the Mercurial mailing list