Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed version information in source code with Mercurial

Tags:

mercurial

I would like to embed some version information on top of my source code file with information such as version number, author, and date of edit.

Is there a simple way to do this with Mercurial?

like image 377
segfault Avatar asked May 12 '12 14:05

segfault


4 Answers

This has been asked a lot here on Stackoverflow and the short answer is: you shouldn't do it.

You don't want a file that changes with every commit it makes merging a nightmare.

Better options are:

  • write the version string to a file on update
  • have you build/deploy script run $(hg id) and put that into the build at that time

Trust me, revision strings in files is CVS/SVN thinking. It has no place in a git / Mercurial world.

like image 78
Ry4an Brase Avatar answered Nov 19 '22 10:11

Ry4an Brase


As comments and other answers mention, it is not a good idea to rely on CVS-like, automatically expanded, tags. Specially since you can extract whatever meta-information you need at any time and almost any granularity afterwards.

However, if you really need it (because your boss says so, for instance), the closest you can get is by making use of the keyword extension that comes bundled with mercurial.

like image 37
C2H5OH Avatar answered Nov 19 '22 09:11

C2H5OH


My favorite way is to use the hgversioninfo plugin. It generates a version.py file on the fly on "hg commit", "hg update", etc.

like image 1
drrossum Avatar answered Nov 19 '22 10:11

drrossum


Yes it is possible, but you need to enable it. What you are asking for is basically the keyword extension. Be careful when enabling this the first time (read the section about kwshrink, kwexpand), because you wouldn't want the actual expanded keywords to become part of the revision history.

like image 1
0xC0000022L Avatar answered Nov 19 '22 08:11

0xC0000022L