Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the subversion repository number into code

I'd like to implement a way of recording the version of a project within code, so that it can be used when testing and to help track bugs. It seems the best version number to use would just be the current revision number from Subversion. Is there an easy way to hook this number into a (C++ in my case) header file or something, which I can then get at in code? I guess this is a post commit hook or something?

Does anyone have any experience of implementing this (with code to share, please?), or can suggest a better alternative? Thanks.

like image 440
Ali Parr Avatar asked Aug 19 '08 14:08

Ali Parr


People also ask

How do I find my SVN revision number?

To find information about the history of a file or directory, use the svn log command. svn log will provide you with a record of who made changes to a file or directory, at what revision it changed, the time and date of that revision, and, if it was provided, the log message that accompanied the commit.

What is SVN source code repository?

SVN is a Subversion control tool that helps us to maintain all the project artifacts in a script repository. It's a free/open-source tool that helps us to manage software versioning and revision control system. It is easy to understand and works faster when compared to the other tools (For Example, GIT, mercurial).


1 Answers

Two ways:

Embed $Id$ or $Revision$ within the code. Then set svn:keywords="Id Revision" property on the file. This will give you the last modified revision of that source file. Good for smaller projects and scripts.

Alternatively, use a Makefile driven process and the command line tool svnversion. (Language specific - this should work for C/C++)

echo -n "#define VERSION 1.0.1-" > version.h svnversion -n . >> version.h 

Or some more complex build script with sed and version.h.in. Then just #include version.h

That will give you the repository version number, which will change with every commit / update, and is probably a more appropriate version number for most projects.

Note: I also used a human readable version string that I manually update. The example would give: Version: 1.0.1-r13445

~J

like image 119
jmanning2k Avatar answered Sep 22 '22 06:09

jmanning2k