且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

自动获取 SVN 修订号到程序中

更新时间:2023-02-12 19:23:14

我不确定 Python 的具体细节,但是如果将字符串 $Revision$ 放入您的文件中的某个位置并且您在其中启用了 enable-auto-props=true您的 SVN 配置,它将被重写为类似 $Revision: 144$ 的内容.然后你可以在你的脚本中解析它.

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.

一个数字您可以通过这种方式使用的属性关键字.

这不会有任何开销,例如查询 SVN 存储库,因为该字符串在提交或更新时被硬编码到您的文件中.

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.

我不确定你会如何在 Python 中解析它,但在 PHP 中我会这样做:

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