Reputation: 655
I am using a combination of the id --num --rev tip
command and a small CMake script to generate a build number for a library.
It all works but the canonical version of the library lives in its own "vendor" branch so I need to be able to execute id --num --rev tip
with a parameter that tells it to look in a different branch from default.
All my attempts have failed - is this possible and if so, what is the right syntax?
Upvotes: 0
Views: 282
Reputation: 6044
Uh, none of those! Do NOT use the numerical revision in a mercurial repository in order to do versioning. The numerical revision number is strictly local to an individual repository and can even change when you do a local clone.
I very much recommend to use semantic versioning and possibly counting the commits since the last such tag. Your friend for these efforts are revsets and templating which allow you access to these (checkout also hg help revsets
and hg help templates
).
E.g.
hg log --rev="last(branch(BRANCHNAME))" --template"{latesttag}-{latesttagdistance}"
That gives for one of my repositories in default 0.4.4-11
and 0.2 branch 0.2.5-1
respectively. If you want a specific version instead of the latest in the given branch, just replace the --rev
-argument with the actual revision you are interested in.
Mind that in the above form there is still ambiguity if you work with branches which have several heads which branch after a tag made to it; thus there really is no good way around using the commit hashes in any versioning scheme. Thus for the currently checked-out version I usually use as version:
hg log -r. --template="{latesttag}-{latesttagdistance} (h{node|short})"
which gives me 0.4.4-11 (h96b8395ca393)
.
Upvotes: 2