Mark Drew (Redux)- cf_etc...

a compendium of railo, cfml, cfeclipse and technology topics

Mark Drew (Redux)- cf_etc...

Using keyword substitution in Subversion

January 11, 2008 ·

When I previously used CVS, I was able to put in my code some keywords that I wanted to substitue, such as the checkin date, who had checked it in, which version it was etc. I have had a hell of a time finding out how to do this in Subversion (SVN). Thanks to a link sent to me by Tom Chiverton, I managed to figure out how to do it via Eclipse. First of, read the manual, especially the svn:keywords section. So, lets say I want to put the following in my headers: Author: $Author$
Date: $Date$
Revision: $Revision$
So in CFEclipse/Eclipse enter that in a file and check it in to your repository, nothing happens right? No changes to the file happen, we must first set the properties for that file (or group of files): 1. Right click on your file and do Team -> Set Property 2. Select the "svn:keywords" property from the drop down 3. In the text area add (without the quotes) "Date Author Revision" 4. Check in the file and reload when it asks if you want to reload the file (since SVN has changed it) TADDA!!! Your file should look like this now: Author: $Author: mark.drew $
Date: $Date: 2008-01-11 15:03:22 +0000 (Fri, 11 Jan 2008) $
Revision: $Revision: 2076 $
I hope that helps!

Tags: eclipse · webdev

6 responses

  • 1 Randy // Sep 22, 2008 at 4:13 PM

    It can also be done from the command line if you are using a property. See the propget, propedit, and propset commands. For example you can do something like: svn propedit svn:keywords file

    That should allow you to the same thing from the command line.
  • 2 Mark Drew // Sep 22, 2008 at 4:13 PM

    Yea, the link shows how to do it from the command line, but I presumed my audience would be using Eclipse ;)

    MD
  • 3 Rob Wilkerson // Sep 22, 2008 at 4:13 PM

    That's great for one-off keyword updates. Easier, I think, to open your client config file (usually ~/.subversion/config or Documents and Settings/username/subversion/config) and update the auto-props section. There you can identify the extensions you want to recognize and the keywords you want to replace automatically (you can also set a lot of other properties here). Now, as soon as you add a file - assuming it matches an extension in your config file - the property will just be set. Magic. :-)
  • 4 Gavin Baumanis // Sep 22, 2008 at 4:14 PM

    Since the SVN keywords add the words DATE / AUTHOR etc;
    you don't need the leading Date:"

    your example would go from;
    Date: $Date$
    to;
    $Date$
  • 5 Ben Burwick // Sep 22, 2008 at 4:14 PM

    Very handy -- I'll definitely use that! I wonder, is there a way to get the latest version number for the entire repository rather than for the file?
  • 6 ck // Sep 22, 2008 at 4:14 PM

    VSS supports the special keyword "$NoKeywords$" which turns off keyword substitution from the points where “$NoKeywords$” is included in the file onwards. (See http://msdn2.microsoft.com/en-us/library/d826hy97(VS.80).aspx)

    This prevents data that happens to look like a keyword from being ‘corrupted’.

    Does SVN have an equivalent?