Currently, my team is using Mercurial.
In a previous work environment we used CVS and then Subversion and somehow it was set up that when we checked in our java classes that a field was updated.
public class MyObject
{
private static final String ID = "$Id: MyObject.java 10000 2008-11-14 16:20:10Z userid $";
// rest of class
}
The $Id:
at the beginning and $
at the end were used as regex delimiters. When we did a commit, the ID string was updated such that 10000 would have been incremented to 10001, the date updated to the commit time and userid to the committer. This came in handy when looking at deployed code and needing to know exactly what version of class was deployed because you could do a strings
command on the class file and read that string.
We started this before there was Maven and better build/depency managment tools and for the most part this isn't needed anymore.
However, we've come across a situation where a project was merged/updated, the central Mercurial repo rebuilt from somebody's local one, and builds being done reverting the Maven version numbers... it's a bit of a mess. We're not sure exactly what version of the classes have currently deployed.
Is there any way that I can set Mercurial up to do this type of update on a commit or a push to the central repository? I haven't been able to find anything, but sometimes that's because the search terms are wrong.
You can use Mercurial Hooks for that. More specifically the pre-commit hook (you can find info on it on the hgrc help).
For example, to write the current date on a file before every commit, set up in your hgrc (either on ~/.hgrc
or project/.hg/hgrc
):
[hooks]
pre-commit = date > file.txt
The pre-commit setting must be set with a command to run before a commit is executed. For your case, you could write a shell script that cat and sed your java file to update the id with the new date and revision number.
The drawback of this solution is that you have to "deploy" that hgrc on every developer's machine to have the hook executed every time.