简体   繁体   中英

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.

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

hg id --debug -i -r .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM