Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include SVN revision number in source code

My requirement is simple. At the beginning of each file there should be a block comment like this:

/*
 * This file was last modified by {username} at {date} and has revision number {revisionnumber}
 */

I want to populate the {username}, {date} and {revisionnumber} with the appropriate content from SVN.

How can I achieve this with NetBeans and Subversion? I have searched a lot but I can't find exactly what I need.

like image 320
Petar Minchev Avatar asked Feb 13 '12 15:02

Petar Minchev


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 revision number?

As you saw in the section called “Revisions”, revision numbers in Subversion are pretty straightforward—integers that keep getting larger as you commit more changes to your versioned data. Still, it doesn't take long before you can no longer remember exactly what happened in each and every revision.

How can I get previous revision from svn?

By far the easiest way to revert the changes from one or more revisions, is to use the revision log dialog. Select the file or folder in which you need to revert the changes. If you want to revert all changes, this should be the top level folder. Select TortoiseSVN → Show Log to display a list of revisions.


2 Answers

I looked at this question and got some useful information. It is not exactly duplicate because I am working with NetBeans but the idea is the same. This is my header:

/*
 * $LastChangedDate$
 * $LastChangedRevision$
 */

Then I go to Team > Subversion > Svn properties and add svn:keywords as property name and LastChangedDate LastChangedRevision as property value.

And when I commit from NetBeans it looks like this:

/*
 * $LastChangedDate: 2012-02-13 17:38:57 +0200 (Пн, 13 II 2012) $
 * $LastChangedRevision: 27 $
 */

Thanks all for the support! I will accept my answer because other answers do not include the NetBeans information. Nevertheless I give +1 to the other answers.

like image 77
Petar Minchev Avatar answered Oct 03 '22 01:10

Petar Minchev


As this data only exists after the file was committed it should be set by SVN itself, not a client program. (And client-side processing tends to get disabled or not configured at all.) This means there is no simple template/substitute like you want, because then after the first replacement the template variables would be lost.

You can find information abut SVN's keyword substitution here. Then things like $Rev$ can be replaced by $Rev: 12 $.

like image 30
Hauke Ingmar Schmidt Avatar answered Oct 03 '22 00:10

Hauke Ingmar Schmidt