Search code examples
pythonsvnrevision

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?)


Solution

  • 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];
    }