Subversion and keyword substitution

July 24th, 2006 | Tags:

Last year I migrated a large CVS repository over to Subversion. One of the issues I missed during the migration was that unlike CVS, Subversion did not automatically set new files to expand keywords such as $Id$ to the very useful string:

$Id: MySpecialClass.java 12234 2004-05-21 00:23:08Z derek $

I did some research into the problem and unfortunately there wasn’t anything on the server side I could do to force this setting on all files as they are added and checked in to the SVN repository. To automatically enable keyword substitution you must do two things.

First, uncomment the enable-auto-props = yes line in ~/.subversion/config in each users home directory.

### Set enable-auto-props to 'yes' to enable automatic properties
### for 'svn add' and 'svn import', it defaults to 'no'.
### Automatic properties are defined in the section 'auto-props'.
enable-auto-props = yes

Then you must configure the file types to which you will apply keyword substitution:

### Section for configuring automatic properties.
[auto-props]
### The format of the entries is:
###   file-name-pattern = propname[=value][;propname[=value]...]
### The file-name-pattern can contain wildcards (such as '*' and
### '?').  All entries which match will be applied to the file.
### Note that auto-props functionality must be enabled, which
### is typically done by setting the 'enable-auto-props' option.
*.c = svn:eol-style=native;svn:keywords=Date Author Id Revision HeadURL

I appended ;svn:keywords=Date Author Id Revision HeadURL to the entry for .c files in ~/.subversion/config. Uncomment other file types in the file and adjust them as needed. Feel free to add new lines to the file for other source files such as .php and .java. These settings will take effect for all new files that you add to the repository.

If you happen to have existing files in the repository that need to have the keyword property set you can set it by running the command:
svn propset svn:keywords 'Author Date Id Revision HeadURL'

svn:keyword documentation

  1. rcharney
    September 2nd, 2007 at 16:31
    Reply | Quote | #1

    For the sample command to work properly, the double quotes need to be replaced by single quotes. So:

    svn propset svn:keywords “Author Date Id Revision HeadURL”

    should be:

    svn propset svn:keywords ‘Author Date Id Revision HeadURL’

    otherwise, the shell will treat the keywords as file names.

Comments are closed.