Getting SVN revision number into a program automatically

后端 未结 11 1482
孤城傲影
孤城傲影 2020-12-02 21:07

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 scrip

11条回答
  •  伪装坚强ぢ
    2020-12-02 21:50

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

提交回复
热议问题