views:

159

answers:

2

I have a project into which I'd like to embed the revision number automagically.

In this case, it's a multi-file perl script. In the main file, I have a line that looks like this:

my $revision = '$Revision: 24 $';

When I make a release, I checkout the project to my release dir.

The revision number does change whenever I check-in a change to THAT FILE. The $Revision$ attribute is updated on check-in, but not check-out.

The thing is, the main file doesn't change that often, so even though the other files in the project are now at 27, the main still has 24.

Is there a way that I can get the main file to reflect the latest rev number? The one that svn prints out at the end of the checkout, ie "Checked out revision 27."

+1  A: 
if (! -e '.version')
{
    open VERSION, '>.version';
    print VERSION `svnversion -n | cut -f1 -d:`;
    close VERSION;
}

my $revision = '$Revision: ' . `cat .version` . ' $';

(Note: a puppy will die if you use this code as-is)

Sean Bright
Why not directly use the output of the svnversion command instead of creating a temporary file?
x-way
In case you didn't want to run 'svnversion' each time your script ran.
Sean Bright
+2  A: 

It is similar to CVS, you can use $Revision$ you just have to set the keyword property for that file for SVN to know it is supposed to do a keyword replace.

From the manual:

"With no svn:keywords property set on that file, Subversion will do nothing special. Now, let's enable substitution of the LastChangedDate keyword. $ svn propset svn:keywords "Date Author" weather.txt property 'svn:keywords' set on 'weather.txt' $ "

http://svnbook.red-bean.com/en/1.5/svn-book.pdf

Evan
While true and informative, this does not even come close to answering the question that was asked.
Sean Bright