Inserting keywords/variables in Subversion with auto-props

Spent a little time this week investing how to get keyword variables related to our Subversion repositories (version, last modified by, date, etc) automatically inserted into our code when we commit. My end goal was to have our code looking like the sample below with an initial comment header including our SVN information:


/**
 * ------------------------------------------------------------
 * Copyright (c) 2010 Some Company.
 * This software is the proprietary information of Some Company
 * All Right Reserved.
 * ------------------------------------------------------------
 *
 * SVN revision information:
 * @version $Revision: 82 $:
 * @author	$Author: kris $:
 * @date	$Date: 2010-07-10 08:36:02 +0200 (Sat, 10 Jul 2010) $:
 */
package com.somecompany.common.somepackage
{
	import flash.display.MovieClip;

	/**
	 * SomeClass description
	 *
	 * @author krisrange
	 */
	public function SomeClass
		extends MovieClip
	{
		/**
		 * Constructor
		 */
		public function SomeClass()
		{
			super();
		}
	}
}

As you can see, the SVN revision version, last modified author and last modified date show up in our headers. This is really important as a developer can look at the header and quickly know who last modified the file and who to talk to in case the initial author of the file may not be the developer who last updated functionality.

I will be writing this from the perspective of working on MacOS but most of this information is transferrable directly to a Windows machine except a few things like directory structures.

We need to make sure that files are setup to have their properties changed. The best thing to do is to change this globally for new files/repositories and then go back into any previous projects you have worked on and recursively loop through and add this functionality.

Modifying the Global Setting:

On MacOS, go into your home directory and open the “Config” file that lives in the hidden folder “.subversion”. Once you have this text file opened, uncomment the “enable_auto_props” variable in the “[miscellany]” section and set it’s value to “yes”. Then add the file types you would like include in the “[auto-props]” section with the value of “svn:keywords=Date Revision Author Id”. See sample below where I’ve set auto_props to modify all *.as and *.mxml files:


[miscellany]
### Automatic properties are defined in the section 'auto-props'.
enable-auto-props = yes

### Section for configuring automatic properties.
[auto-props]
*.as = svn:keywords=Date Revision Author Id
*.mxml = svn:keywords=Date Revision Author Id

Modifying Previous Projects

In order for previous projects to gain access to this information, we need to set the properties on all the files we have already committed to set the properties on themselves when they are committed into our repositories. To do this, just type the following command for every file type that you want to have auto_props enabled for.

find * -type f -name '*.as' -exec svn propset svn:keywords "Date Revision Author Id" {}  \;

Getting the Values to Show Up

After that is all setup, just insert the values in your document based on the corresponding ID. So for example, if you wanted to insert the Last Modified Author, insert it like below and SVN will replace the content inbetween the word “Author” and “$:” with the actual value:

$Author: $:

For more information on what keywords/properties are available, there is good documentation from Subversion.

This entry was posted in development and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment

  1. Posted July 30, 2010 at 10:10 pm | Permalink

    Thanks. I needed a quick and dirty how-to on SVN variable substitution and this guide was just right. I appreciate you sharing your expertise.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>