4

I have a java project in NetBeans and im using Mercurial for version controlling. I want to see my project version number in about box and i want it to be updated according to Mercurial revision number. Any ideas how to do it? :)

gore_obsessed
  • 146
  • 2
  • 11

2 Answers2

5

Following 'Version numbering for auto builds with Mercurial', you can record in a VERSION.TXT file (that you about dialog would display) the result of:

hg log -r . --template '{latesttag}-{latesttagdistance}-{node|short}'

Lazy Badger comments:

log will be a lot better (and correct) with:

hg log -r tip --template "{latesttag}.{latesttagdistance}"

You have more options in "How good is my method of embedding version numbers into my application using Mercurial hooks?"

version_gen.sh with:

 hg parent --template "r{node|short}_{date|shortdate}" > version.num

In the makefile, make sure version_gen.sh is run before version.num is used to set the version parameter.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Example of a `version_gen.sh` script: https://bitbucket.org/artbugorski/postmed/src/tip/util/version_gen.sh – VonC Nov 05 '12 at 13:06
  • log will be a lot better (and correct) with `hg log -r tip --template "{latesttag}.{latesttagdistance}"` – Lazy Badger Nov 05 '12 at 13:51
  • @LazyBadger ok, I have included it in the answer for more visibility. – VonC Nov 05 '12 at 13:54
  • 1
    I have a need to get this (programmatically) from a given branch, so I used `hg log -l 1 -b --template "{node}\n"` – Dav Clark Jul 12 '14 at 19:19
0

If Windows, MercurialRev ("SubWCRev for Mercurial") may be useful also

Replaces revision information in a tagged text file.

MercurialRev <SourceFile> <DestinationFile> <RepositoryPath>

Tags:
    <$HG:REV_NUM$>
    <$HG:REV_LMOD_N$>
    <$HG:REV_LMOD_P$>
    <$HG:REV_ID$>
    <$HG:BRANCH$>
    <$HG:TAG$>
Lazy Badger
  • 94,711
  • 9
  • 78
  • 110