tags:

views:

88

answers:

3

I am working on a project that stores multiple versions in the same svn repo but in different directories. For ease of reference for the coders working on the project I'd like to be able to add a commented tag similarly to

# $Revision: 144 $

However, instead of the file revision it should contain a simple version number like so:

# $Version: 1.63 $
# $Version: 1.64 $
# $Version: 2.0 $

Is there a way to get subversion to do this automatically for a specific directory and all sub-directories as well as for any new files added to those?

A: 

You can add arbitrary properties with propedit so for example:

svn propedit my:version path/to/dir`

However I'm not sure how to get that to be populated in a comment during co or commit. (it may even happen magically - ive never tried).

prodigitalson
we already thought about props, but afaik only keywords get inserted into the text automatically. The comment part is only so people don't try to give me perl code solutions. :) Would maybe propedit combined with a pre-commit hook do the trick? If so, how would i approach that? Also, are props propagated recursively into directoy contents automatically?
Mithaldu
the don't get populated, you can specify a fixed set of svn:keywords. It doesn't work for random properties
Sander Rijken
@sander: so you mean you can add custom keywords and then it would get populated or no?@mithaldu: i think that could work but i havent messed with hooks so i cant really ellaborate. though i would think if you set the prop on the top level dir for the version then your hook could read that prop and then set it recrusively on all files/dirs and add the string in the nessecary spot in the actual file bodies... that sounds kinda ugly though :-)
prodigitalson
I mean custom properties don't get populated, only valid settings for svn:keywords (like id, author, revision etc) will be populated
Sander Rijken
+5  A: 

stores multiple versions in the same svn repo but in different directories

Sounds suspiciously like tagging as described in the SVN documentation. Can you just do this instead?

SVN will automatically keep track of which revision all the files came from, so you won't have to embed anything in the files themselves.

Michael Hackner
A: 

It sounds as if you want to change the version number of a Perl module according to when it was last revised, e.g.

our $VERSION = '1.2.12345';

...where 12345 is the svn revision number where the module was last changed.

You can use the $Revision$ keyword in your code to do this, combined with a little Perl substitution magic to extract the integer:

package My::Module;
my $revision_str = '$Revision$';    # will be transformed to '$Revision: xxxxx $'
(our $VERSION = $revision_str) =~ s/^\$Revision: (\d+) \$$/1.2.$1/;
 $ svn propset svn:keywords "Revision" My/Module.pm  
 property 'svn:keywords' set on 'My/Module.pm'  
 $ svn commit My/Module.pm -m'adding svn:keywords property'
 Committed revision 12345.

 $ perl -I. -MMy::Module -wle'print $My::Module::VERSION'  
 1.2.12345

(See the documentation under "Special Keywords" for more about the svn:keywords property.)

Ether