How to get log for head of current branch?

723 views Asked by At

I can get the head of the current branch via

hg head .

I can then get the data I need by copying and pasting the changeset ID from the output of that command into this one:

'hg' 'log' --'limit' '1' --'style' 'xml' --'verbose' --'rev' 'ac99e18fbca1'

The problem is that I need to do this programatically, and I'd prefer not to parse the output of hg head .. So, can I either:

  1. Do this with a single command? I couldn't find anything in revsets that would work.
  2. Format hg head . to give me just the changeset ID?
2

There are 2 answers

0
mpen On

Just noticed head accepts the --style param.

hg head . --style xml --verbose
0
Lazy Badger On
  • You can use in log any usable cset-id, not only short-hash

Revset for hg head . (may produce more than one changeset in case of anonymous branching)

hg log -l 1 --style xml -v -r "heads(branch(.))"

is perfectly valid and always usable single command for your task

  • For all log-style commands (including heads) output can be modified with --template and template-keywords

Only changeset-hash in head output will be something like

hg head . --template "{node|short}\n"

Test-case:

Standard head

>hg head .
changeset:   39:dc3bad781bc5
tag:         tip
user:        Ray Bream <...>
date:        Fri Aug 16 16:35:17 2013 +0600
summary:     ***

Templated head for the same repo

>hg head . --template "{node|short}\n"
dc3bad781bc5