Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically add svn keyword properties for new files (server-side)

I want to add svn properties (like svn:keyword=Id Date Rev Author) to files upon commits of new files.

For this to work there may be two main options:

  1. Client-side: altering the autoprops in the svn client configuration
  2. Server-side: do some magic with commit-hooks

The client side is not always desirable, as control over the client set up is needed. I want to solve this on the server. How can this be done.

like image 604
jochem Avatar asked Feb 23 '10 12:02

jochem


2 Answers

The Subversion docs say it's a bad idea to modify a commit on the server side.

Instead, you could do something like a customized version of the svn_apply_autoprops script periodically through cron (or even on the server triggered by a commit). The svn_apply_autoprops script is a little more general than what you need, but it should be straighforward to set up the appropriate config file.

As of this post, the subversion web site is migrating under apache.org, and I couldn't find the docs for the contrib tools.

like image 172
Dave Bacher Avatar answered Nov 07 '22 15:11

Dave Bacher


Since version 1.8 one can use a feature repository dictated configuration to automatically set properties on server side.

From Automatic Property Setting:

[...] a set of property definitions which all connecting clients automatically consider when operating on working copies checked out from a given server. Subversion 1.8 and newer clients support such functionality through the svn:auto-props inheritable property.

Note that you only need new enough client. Below you'll find a complete example where I used svn command line client 1.8.8. with svn server 1.6.11.

svn client version 1.8+ required

jani@dev:/tmp/testrepo/text-files$ svn --version --quiet
1.8.8

Files created before auto-props property setting

jani@dev:/tmp/testrepo/text-files$ file f?.txt
f1.txt: UTF-8 Unicode text
f2.txt: UTF-8 Unicode text, with CRLF line terminators
f3.txt: ASCII text, with CRLF line terminators
jani@dev:/tmp/testrepo/text-files$    

Set auto-props

jani@dev:/tmp/testrepo/text-files$ svn propset svn:auto-props "*.txt = svn:eol-style=LF" .
property 'svn:auto-props' set on '.'
jani@dev:/tmp/testrepo/text-files$ svn proplist -v --recursive
Properties on '.':
  svn:auto-props
    *.txt = svn:eol-style=LF
jani@dev:/tmp/testrepo/text-files$    

Create new file f4.txt with CRLF line terminators

jani@dev:/tmp/testrepo/text-files$ file f?.txt
f1.txt: UTF-8 Unicode text
f2.txt: UTF-8 Unicode text, with CRLF line terminators
f3.txt: ASCII text, with CRLF line terminators
f4.txt: UTF-8 Unicode text, with CRLF line terminators
jani@dev:/tmp/testrepo/text-files$    

The line terminators of f4.txt changes after commit

jani@dev:/tmp/testrepo/text-files$ svn add f4.txt
A         f4.txt
jani@dev:/tmp/testrepo/text-files$ svn commit -m 'just another test' .
Adding         f4.txt
Transmitting file data .
Committed revision 5.
jani@dev:/tmp/testrepo/text-files$ file f?.txt
f1.txt: UTF-8 Unicode text
f2.txt: UTF-8 Unicode text, with CRLF line terminators
f3.txt: ASCII text, with CRLF line terminators
f4.txt: UTF-8 Unicode text
jani@dev:/tmp/testrepo/text-files$ svn proplist -v --recursive
Properties on '.':
  svn:auto-props
    *.txt = svn:eol-style=LF

Properties on 'text-files/f4.txt':
  svn:eol-style
    LF
jani@dev:/tmp/testrepo/text-files$
like image 38
user272735 Avatar answered Nov 07 '22 16:11

user272735