How to embed version information in source code using Mercurial

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

Is there an easy way to do this with Mercurial?

+4
source share
4 answers

As comments and other answers point out, don't rely on CVS-like, automatically extensible tags. Especially, since you can extract any meta-information that you need, at any time and almost any detail afterwards.

However, if you really need it (because your boss says so, for example), the closest thing you can get is to use the extension that comes with mercurial.

+3
source

This has been asked here many times on Stackoverflow, and the short answer is: you shouldn't do this.

You do not want a file that changes with each commit to merge a nightmare.

The best options:

  • write the version string to the file on update
  • You create / deploy a script, run $ (hg id) and put it in the assembly at that time.

Believe me, change lines in files are CVS / SVN thinking. This is not a place in the git / Mercurial world.

+4
source

Yes, it is possible, but you need to enable it. What you are asking for is basically an extension. Be careful when you first turn it on (read the section on kwshrink , kwexpand ) because you do not want the actual advanced keywords to become part of the change history.

+1
source

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

+1
source

Source: https://habr.com/ru/post/1412153/


All Articles