Adding SVN Information to File Headers

(see the revised edition of this post => http://blogchuck.com/2009/09/adding-svn-headers-revisited/ )

In the past as I have examined open source php applications, I have noticed the comments in the top of the files contain SVN information about the file. At first, I thought that maybe the developers added the information to the top of each file manually. I soon discovered that would be a rediculous requirement to put on the coders. A bunch of unnecessary red tape from their perspective. So I began to research. It didn’t take long to find the answers I was looking for.First, you must tell SVN that you want to assign keywords to specific files. You can do this in one of two ways. For each file you want to assign information to you run the command: svn propset svn:keywords “list of keywords here” name_of_file.ext. There is no global command using this function from the command line. However, you can set your SVN client to automatically set these properties.

vi ~/.subversion/config

[note: You could set this on the entire repository using the global config typically stored at /etc/subversion/config]

Look for the [miscellany] section and set enable-auto-props = yes. Then in the [auto-props] section, add the keywords for the file types you are working with. For example, if you are working with php files, you may add something like:

*.php = svn:keywords:Date Author Id Copyright Revision LastChangedBy LastChangedDate License URL

Something you should know about a few of these keywords. There are two of them you will need to define before SVN will add them into your header files.

svn propset copyright “(c)2007 My Company. All Rights Reserved.” ./*

will set the copyright for the entire project.

svn propset license -F /path/to/LICENSE ./

will tell svn to reference a file for the license information.

The only other thing you need to do is add some place holders in the header of each file you want SVN to add it’s information to. I have formulated a sample PHP header that will include more than you will probably ever want to add to your comment header. Some of the information I included in the same will be manually added, but everything inside double dollar signes ($sample$), will be replaced with SVN information automatically on every commit. You will never have to do anything to the header again to have SVN keep the information updated.
/* SVN FILE: $Id$ */
/**
* Project Name : Project Description
*
* @package className
* @subpackage subclassName
* @author $Author$
* @copyright $Copyright$
* @version $Revision$
* @lastrevision $Date$
* @modifiedby $LastChangedBy$
* @lastmodified $LastChangedDate$
* @license $License$
* @filesource $URL$
*/

That’s it. Simple enough to get valuable information into the comment headers of your files.

Like it? Post to your favorite location and share.
  • Digg
  • del.icio.us
  • Facebook
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Twitter

9 Comments

TheDel  on March 5th, 2009

Great idea adding SVN Info to file headers. Which SVN Client are you using? I cannot figure a way to modify the configuration of my SVN client to accomplish this.

~Peace~
TheDel

Chuck  on March 5th, 2009

I use command line SVN on Mac or Linux.

salunkerahul  on March 9th, 2009

Chuck,
I happened to move over from using CVS to SVN and your page was quite informative. I’ve added
I enocunter the following error when committing a new file
“svn: At least one property change failed; repository is unchanged
svn: Server sent unexpected return value (400 Bad Request) in response to PROPPATCH request for xyz.xyz.
Would you have a clue as to where I’m wrong? I’m using svn version 1.5.4
I could not find any good results googling for the error that I encounter.

Thanks in advance,
-Rahul

Chuck  on March 10th, 2009

Rahul,
This sounds more like an apache config issue than anything. Are you running svn in apache? Has it worked prior? One thing you may want to check is that the Location /to/your/svn in httpd.conf has the DAV svn in it.

JDThomsen  on August 7th, 2009

So, I just spent a bit of time trying to get this to work, and after failing to make custom svn keyword substitution for “Copyright” and “License”, I did a bit of googling, and the concensus seems to be that custom keyword substitution can’t be done in SVN.
I would like to know what version of SVN and potentially what patch you used to get this to work?

Chuck  on August 7th, 2009

JDThompsen, you can read more about it in the subversion book. (http://svnbook.red-bean.com/nightly/en/svn-book.html#svn.ref.svn.c.propset) Hope that helps.

surbhi  on November 13th, 2009

I could not make custom svn keyword substitution for Copyright” and “License”. Could you please help me?

surbhi  on November 13th, 2009

I am using svn, version 1.5.0 (r31699)
Do we need to do something special in order to make custom keyword substitution to work?

Chuck Burgess  on January 15th, 2010

Please refer to the revised edition of this post. Also, please make sure you are following all the steps. Please indicate what you have tried to get it working so I know where to start looking to help you trouble shoot.

Leave a Comment

You must be to post a comment.