Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting SVN revision number into a program automatically

I have a python project under SVN, and I'm wanting to display the version number when it is run. Is there any way of doing this (such as automatically running a short script on commit which could update a version file, or querying an SVN repository in Python?)

like image 684
Smashery Avatar asked Sep 20 '09 00:09

Smashery


People also ask

How do I find my svn revision number?

To find information about the history of a file or directory, use the svn log command. svn log will provide you with a record of who made changes to a file or directory, at what revision it changed, the time and date of that revision, and, if it was provided, the log message that accompanied the commit.

How does svn revision number work?

Each time the repository accepts a commit, this creates a new state of the filesystem tree, called a revision. Each revision is assigned a unique natural number, one greater than the number assigned to the previous revision.

How do I find previous versions in svn?

On the file, simply right-click => Team => Switch to another branch/tag/revision. Besides the revision field, you click select, and you'll see all the versions of that file.


1 Answers

I'm not sure about the Python specifics, but if put the string $Revision$ into your file somewhere and you have enable-auto-props=true in your SVN config, it'll get rewritten to something like $Revision: 144$. You could then parse this in your script.

There are a number of property keywords you can use in this way.

This won't have any overhead, e.g. querying the SVN repo, because the string is hard-coded into your file on commit or update.

I'm not sure how you'd parse this in Python but in PHP I'd do:

$revString = '$Revision: 144$';
if(preg_match('/: ([0-9]+)\$/', $revString, $matches) {
    echo 'Revision is ' . $matches[1];
}
like image 144
Ciaran McNulty Avatar answered Sep 28 '22 09:09

Ciaran McNulty