I have application I want to print out (in "about" box) its revision/version from mercurial. Suppose it is revision deadbeef
so it will know that. In old times in CVS could use something like $Revision$
to substitute automatically.
What is best prac开发者_StackOverflow社区tice with Mercurial for this?
The best approach is probably to use precommit hook to replace a designated file with the output of hg log -r tip
, possibly with a --template
arg to format it in a particular way.
Unfortunately, there's a bit of a chicken and egg problem. The revision is a checksum of the commited data, but the checksum is not available until after the commit has taken place. One option might be to actually hook on commit instead of precommit, and commit the version info in a seperate changeset.
You can use this to get the current revision in mercurial:
hg id -i
Mercurial's Keyword Extension is probably what you want. It supports the $Revision$
format pretty much exactly.
精彩评论