The text from the SVNBook is probably relevant here:
New users are often confused by how the $Rev$ keyword works. Since the
repository has a single, globally increasing revision number, many
people assume that it is this number that is reflected by the $Rev$
keyword's value. But $Rev$ expands to show the last revision in which
the file changed, not the last revision to which it was updated.
Understanding this clears the confusion, but frustration often
remains—without the support of a Subversion keyword to do so, how can
you automatically get the global revision number into your files?
To do this, you need external processing. Subversion ships with a tool
called svnversion, which was designed for just this purpose. It crawls
your working copy and generates as output the revision(s) it finds.
You can use this program, plus some additional tooling, to embed that
revision information into your files. For more information on
svnversion, see the section called “svnversion”.
In my project we ended up not using svnversion
, primarily because our source tree is huge and this command seemed to take an inordinate amount of time. But we did end up with something similar to get the revision number into our software. The configure
script executes the following command
svn info . > svn_revision
This assumes the command is executed from a directory where that was checked out from the svn repository. To parse this data, I have a Makefile that greps various strings into constants
SVN_REV = $(shell cat svn_revision | grep "Last Changed Rev" | cut -f4 -d\ )
This is fed through a template file I call version.cc.template
, there's a Makefile rule to turn it into a .cc
file
version.cc: version.cc.template /svn_revision
sed -e "s/REVISION/$(SVN_REV)/" version.cc.template > $@
so I end up with something like this
version.h
namespace project {
extern const char* Revision;
extern const unsigned int SvnRevision;
}
version.cc
namespace project {
const char* Revision = "1234";
const unsigned int SvnRevision = 1234;
}
The version.cc
file may not be needed in your case, the constants can be defined in the header as well.