Problem
As you have already determined, you really created the Catch-22 here .
You cannot put significant information into the version.num file until the changes are committed, and since you save version.num in the repository, you cannot commit the changes to the repository until you complete the version.num file.
My decision
I would suggest the following:
- Get rid of the "pre-commit" hook and
hg forget the version.num file. - Add
version.num to your .hgignore file. Adjust version_gen.sh to consist of:
hg parent --template "r{node|short}_{date|shortdate}" > version.num
In the makefile, verify that version_gen.sh running before version.num used to set the version parameter.
My reasons
As @ Ry4an suggests that the build system insert revision information into the software during build, using version control information is a much better option. The only problem with this is to try to compile the code from the hg archive repository, where the build system cannot extract the relevant information.
I would be inclined to prevent this, however - in my own build system, the assembly failed if the revision information could not be extracted.
Also, as @Kai Inkinen suggests , using version numbers is not portable. Rev 21 on one machine may be rev 22 on another. Although this may not be a problem right now, it may be in the future if you start working with other people.
Finally, I explain the reasons why I do not like the Keyword extension in question regarding similar questions to your own question:
I looked at the Mercurials Keyword extension, as this seemed like an obvious solution. Nevertheless, the more I looked at him and read the opinions of people, the more I came to the conclusion that this is not quite what needs to be done.
I also remember the problems associated with replacing keywords in projects of previous companies ....
Also, I don’t really want to include Mercurial extensions to complete the build. I want the solution to be taken for granted, so that the application is not just accidentally compiled without built-in version information just because the extension is not included or the correct supporting software was not installed.
Then in the comments to the answer that suggested using the keyword extension:
... I rejected the use of the keyword extension, as it would be too easy to end up with the string "$ Id $" being compiled into an executable. If the keyword extension was built into the mercurial and not the extension, and by default I could consider it, but since it is worth it, it just would not be reliable. - Mark Booth
And do not think that there may be a more reliable solution. What if someone accidentally damages .hg or builds not from a clone, but from an archive? - Mr.Cat
@ Mr.Cat - I don’t think there can be a less reliable solution than expanding keywords. Anywhere where you explicitly did not enable the extension (or someone turned it off), you will get the literal string "$ID$" compiled into an object file without complaints. If the mercury or repo is damaged (not sure what you meant), you still need to fix it. As for the hg archive , my original solution will not compile if you try to create it from the archive! This is exactly what I want. I do not want any source to be compiled into our applications without a source controlled by the audit! - Mark Booth