davidmytton
davidmytton

Reputation: 39264

How do I get the current mercurial revision without calling hg?

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.

Upvotes: 12

Views: 8523

Answers (3)

Vikrant Chaudhary
Vikrant Chaudhary

Reputation: 11319

hg id --debug -i -r .

Upvotes: 2

Steve Losh
Steve Losh

Reputation: 19892

$ 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"?

Upvotes: 27

Tom
Tom

Reputation: 4782

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.

Upvotes: 0

Related Questions