One of the features I remember using in Visual Source Safe was the ability to put in custom keywords within my comments that would automatically be updated each time I did a check-in. I thought this feature was not available in Subversion, but I was wrong! Subversion uses Properties!
Subversion Properties
One of the features of Subversion is the ability to add your own Metadata to a file that goes along with the file each time it’s committed. Metadata can be changed for each commit and works the same way when your source code or document is committed. Subversion provides it’s own set of properties. One of the properties is svn:keywords.
svn:keywords Property
svn:keywords property allows specific keywords to be replaced when ever commit to file happens. This is great for leaving comments in your code that are updated each time a commit is done. In our latest project we want to update the Author, the Revision Number and the URL (Branch, Trunk or Tag) on each committed. This gives us a quick status of who last updated the file, what revision number was and where in the Repository. Thinking now, we should add the date as well.
So how do you set SVN Properties?
There is a couple of ways. One way is to go into the config file on the server where the repository is located and make the pattern change there to use it. So each time a file of that pattern is added to the repository the svn:keywords property is added. By default this is turned off.
The other way is add the property to each file through TortoiseSVN. This can be a pain if you have several files to do, but if you select all your files in your workspace, and then select the properties of the files, you are able to recursively add the property. However the drawback to this is that you need to add the property to any new files that you add to the repository. Sometimes you don’t have access to the repository config file so this is the only way to do then.
Once you’ve selected the properties of the file(s), you’ll see Subversion tab within the file’s property sheet. Select the tab and click the Properties… button.
A property window opens where you can edit or select a new property for the file(s).
Here I have already set up the svn:keywords. I have decided that for this file the only three (3) keyword values to replace are Author, URL and Rev. If I wanted to add/remove values, highlight the Property and click the Edit.. button.
I can then add or remove the property values. Currently there are five (5) values that svn:keywords will search and replace.
Author: The developer who last committed
Rev: The revision number when last committed
Date: The Date of when it was committed.
URL: the full URL to the latest version of the file in the repository.
Id: A combination of Author, Rev and Date
Once the keyword values for the svn:keywords property has been set to the file(s), subversion will look for these keywords and replace them with the information from the repository each time a commit happens.
Adding the Comment in your code that will be replaced by the svn:keywords
I’m doing this in C# but it really does not matter what programming language or file you are adding these keywords to. As long as it starts and ends with a $
In mode code I added the following 2 comment lines (It could have also been on the same line)
Here you see I have // $Author$ , //$Rev$ and //$URL$
Now if I commit the file the keywords will be replaced with the following information:
The SVN Commit replaced the $Author$ with $Author: nhansen$. If the next time someone else on the team commits the change, their name will show up here.
You can see that the revision number has jumped to 1290 when I commit some changes. (Several commits happened between when I first started working on this blog post)
This is a very cool feature of Subversion that happens to be hidden to most developers. Many don’t even realize that they have this option available to them. At Venice Consulting Group, we’ve begun using these new features on a few projects and I can say this has been a very positive experience so far.
If you have any other way of using the Subversion property feature, I’d love to hear them. Please add them to the comments section.









