tags:

views:

312

answers:

3

In Git the current revision hash is stored in

.git/refs/heads/master

Is there an equivalent in Mercurial that doesn't require me making a call to hg log -l1? I know I can get the current branch in .hg/branch.

This is to "display" the current hg hash on screen when browsing a web page.

A: 

I'm not a mercurial expert, but taking the sledgehammer approach and doing a grep for the current revision hash in .hg yields only one possible, and that is .hg/branchheads.cache.

I believe this caches all the heads of the repository, so it may have multiple entries. By default, I think it will always have two entries, one for the default branch and one for the tip revision number.

I think that branchheads.cache is rebuilt whenever new changesets arrive, so it should always have the correct current revision hash in it.

Tom
grep for the binary version :) (it's actually in `.hg/dirstate`)
tonfa
Fair enough -- I should lock that sledgehammer away and engage brain.
Tom
+6  A: 
$ hg parents --template="{node}\n"
52b8cee1e59c91b9147635b7f44a3a8896ee0b00

$ hexdump -n 20 -e '1/1 "%02x"' .hg/dirstate
52b8cee1e59c91b9147635b7f44a3a8896ee0b00

But why can't you just call hg parents --template="{node}\n"?

Steve Losh
I'm impressed by your binary skills :)
tonfa
Heh, I just opened up dirstate.py and noticed that the parent hashes were the first two twenty-byte sections of dirstate.py. A bit of googling got me the proper hexdump formatting string (god those things are awful).
Steve Losh
A: 

hg id --debug -i -r .

Vikrant Chaudhary