如何在程序中添加svn版本信息

来源:互联网 发布:淘宝服装店货源七浦路 编辑:程序博客网 时间:2024/06/06 04:32

如果一个可执行文件能输出版本信息,会带来非常大的便利,本文就是介绍一种自动添加svn版本信息的方法。

Svn keywords可以实现自动更新,比如ID, Version, Author等,可以利用这些svn关键词来实现。主要的keywords如下所示:

     svn:keywords                          - Keywords to be expanded.  Valid keywords are:

     URL,HeadURL                       - The URL for the head version of the object.

     Author, LastChangedBy        - The last person to modify the file.

     Date, LastChangedDate       - The date/time the object was lastmodified.

     Rev, Revision,                         -The last revision the object changed.

     LastChangedRevision          - last revision

     Id                                                - A compressed summary of the previous 4 keywords.

     Header                                     - Similar to Id but includes the full URL.


 我在自己机器上试了一下,好像并非上述的每个关键词都能工作。

首先在.subversion/config文件中添加以下信息

enable-auto-props = yes

 [auto-props]
* = svn:keywords=Rev Author URL Date LastChangedRevision Id Header


我们可以这么实现,比如新建一个文件叫Conifg.h,内容如下

string version = "

$Rev$: Revision of last commit

$Author$: Author of last commit";

Svn check in以后会自动更新成如下内容:

$Rev:8466 $: Revision of last commit

$Author:zhangle $: Author of last commit

这样我们就可以把它include到main.cpp文件中,每次提交代码后就可以自动生成你指定的信息。代码中可以解析该string,获取当前的版本信息。

现在还有一个问题是需要Conifg.h的内容发生改变时,关键词才能自动扩展,所以还需要思考以下如何才能更加自动化。


0 0
原创粉丝点击