Profile photo of Steve White

About Steve White

Software Engineer

Steve WhiteSVN Keywords and PropSet PowerShell Script

How we are using SVN Keywords and PropSet PowerShell Script

Some of our source code remains in an SVN repository and uses keyword substitution. By using SVN Keywords and PropSet PowerShell Script together we can provide up to date version and revision information. Keywords are generally defined in comments or variables in the format “$TagName: TagValue $:” in any source code. See the following link for more information.

A C source file may use keywords to insert version header information which can be pulled out by a version parameter (-v) passed to it, e.g:


const char *SVNVERSION={“@(#) $Revision: 1234 $:”};
const char *CODEAUTHOR={“@(#) $Author: steve.white $:”};
const char *DATEMOD={“@(#) $Date: 2013-01-01 12:00:00 +0100 (Tue, 01 Jan 2013) $:”};


Quite often, running a UNIX “strings” on the C generated binary will return the above information in its output which is useful for identifying binaries from an unknown source. So far I’ve noticed this works well with binaries produced by gcc on Linux, Solaris, Windows and AIX.

Eventually our code will all be migrated to a distributed version control system (DVCS) such as Git or Mercurial. However, keywords are not recommended so we will have to have a re-think as to how this is done.

Source Code with Missing Keywords

We recently discovered that TortoiseSVN on some of our developer machines had SVN keywords disabled. This meant that newly added source files hadn’t had them added and as a result keywords were not being updated upon a commit. Instead of running an SVN command manually against each source file I wrote a quick PowerShell script to do the legwork for us:


# Save as: svnPropSetSrc.ps1
# Change to source root and run: PowerShell .\path\to\svnPropSetSrc.ps1
# Recursively set SVN properties for common source files

$srcFiles=gci . -recurse -name -include @(“*.cpp”,”*.c”,”*.h”,”*.js”,”*.java”,”*.cs”)
Foreach ($Item in $srcFiles)
Write-Host $Item
svn propset “svn:eol-style” native $Item
svn propset “svn:keywords” “Author Date Id HeadURL Revision” $Item


This uses “gci” which is an alias for the Get-ChildItem PowerShell Cmdlet and outputs the file it’s modifying to standard output. It’s probably worth running this and piping output to a file so you can track what’s changed and see if there have been any errors reported.

One thought on “SVN Keywords and PropSet PowerShell Script

Leave a Reply