Posted in Howto Linux Versioning
Subversion : automating svn:keywords
We’ll see here how you can automate the addition of SVN keywords to your newly added or imported file in your Subversion repository.
Changes are being made on the client computer, NOT the repository. It means you need to apply the following to every computer accessing the SVN repository.
For files already in the repository, you will need to manually set the keywords this way :
svn propset svn:keywords "Id" file.sh
To set scripts as executable :
svn propset svn:executable ON file.sh
1. Enabling auto properties
Edit ~/.subversion/config
Under the miscellany section, set enable-auto-props to yes
[miscellany]
enable-auto-props = yes
Then, you should find an auto-prop section :
[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
# *.cpp = svn:eol-style=native
# *.h = svn:eol-style=native
# *.dsp = svn:eol-style=CRLF
# *.dsw = svn:eol-style=CRLF
# *.sh = svn:eol-style=native;svn:executable
# *.txt = svn:eol-style=native
# *.png = svn:mime-type=image/png
# *.jpg = svn:mime-type=image/jpeg
# Makefile = svn:eol-style=native
If I wanted to have the “Id” keyword automatically added to *.sh files, I’d uncomment the *.sh line and add the keyword values, so it’d look like this :
*.sh = svn:eol-style=native;svn:executable;svn:keywords=Id
2. Editing your files
Just put somewhere in your bash script the “$Id$” keyword, add and commit :
$ vi test.sh
#!/bin/bash
# SVN : $Id$
echo "This is a test"
Add and commit :
$ svn add test.sh
A test.sh
$ svn commit -m “Testing auto keywords”
Sending test.sh
Transmitting file data .vi
Committed revision 30.
Once commited, the file would look like this :
#!/bin/bash
# SVN : $Id: test.sh 30 2007-01-10 23:34:59Z user $
echo "This is a test"
3. Verifying the properties of a file :
If you want to check out the properties set on a file, just do :
$ svn proplist test.sh
Properties on ‘test.sh’:
svn:executable
svn:keywords
svn:eol-style
If you want to check out the keywords set on that file :
$ svn proplist test.sh -v
Properties on ‘test.sh’:
svn:executable : *
svn:keywords : Id
svn:eol-style : native
Comments
Pryonic
It seems that is has to be set on the client machine rather than the server. This mean it must be set for each user on each client, rather than on the server which severly limits its use.
Johannes Egger
It does indeed severely limit its use. Also, the RedHat Certified Engineer link is messed up
Sébastien Wains
Hi Johannes,
I fixed the article, I’m now making it clear the changes must be set on every client machines. If you are aware of any way to enable auto keywords from the repository, feel free drop a comment.
Also, the RHCE link is fixed, thanks a lot for the notice. Apparently they changed the way they process the links to the “certification central”.
Cheers
Seb
Johannes Egger
Re: Redhat – yes, I thought that might be the case. Apologies for not contacting you privately (lazyness).
Concerning subversion: this issue is somewhat related: http://subversion.tigris.org/issues/show_bug.cgi?id=1974
I can’t help but wonder whether one could actually set properties using the post-commit hook?
Heike
Hi Sébastien,
I found your SVN information quite useful. Thanks a lot for providing it!
Additional to adding svn keywords like author, revision, etc. to my source files, I would like to add all the log messages. It doesn’t seem as simple as adding keywords. Do you know whether it’s possible to add log messages to source files and if so, how?
Thanks again!
Cheers, heike.
Sébastien Wains
Hi Heike,
This is not possible to my knowledge.
The official SVN guide doesn’t mention anything relevant as well.. http://svnbook.red-bean.com/en/1.1/ch07s02.html
Heike
Hi Sébastien,
hmm, I know it works with CVS and that’s why I was hoping it’s also possible with SVN; but obviously not. Anyway, thank you once more!
Cheers, heike.
Omurhan Akdemir
Roberto,
Guess you are working on windows.
It’s under c:\Documents and Settings\User\application data\Subversion
Cheers
omurhan
Josh
Yay! Thank you for this! I looked all over to find out how to do automatic revision numbers and dates.
mk
Hi,
I’m a SVN newbie.
I followed what you’ve mentioned above to get the following bit in my .CS file show the expected bit
/********************************************
* Revision: $Revision$
* LastChangedDate: $Date$
* LastChangedBy: $Author$
*********************************************/
tried to run ‘$ svn proplist XXX.cs’ but it shows ‘.’ is not an working folder.
what am I missing?
mk
forgot to add the entry at .subversion/config
*.aspx.cs = svn:eol-style=native;svn:keywords=Author Date Revision
mk
I meant this is my entry at that file…
Still no luck
Sebastien Wains
can you run svn info in the directory where the .cs file resides, and give me the output ?
mk
Hi Sebastian,
appreciate your kind response.
when I run ’svn info’ command in the repository directory (at repo server) all I get ” ‘.’ is not an working copy”. This makes me wonder whether I should be running that commnd at my dev machine, local working copy.
I’ve got only TortoiseSVN subversion client installed in dev machine. Do I need to install a full blown SVN in my machine? not sure…
Bit lost here.
thanks in advance..
MK
PS Repo server has got Visual SVN
mk
Hi,
I may have found the solution in the TSVN’s user manual…
thank you anyway…
MK
Khalid
If you manage a repository and want this to happen automatically, then here is a way to make subversion/svn recognize CVS Id and Revision tags centrally, without doing any client-side changes.
Leave Comment
Please consider visiting the partners below if you enjoyed this article :If this post saved you time and money, please consider checking my Amazon wishlist.







Roberto PRESEDO
Sorry, but I can’t find the ~/.subversion/config file… Where is it ? in the repository or in the Subversion folders