如何獲得svn的版本號信息?


  • 方法一  popen(可獲取命令行執行后的輸出結果)

轉載自:

C++執行命令行指令並獲取命令行執行后的輸出結果

 1 /*
 2 Execute command line commands and get specific results by comparison cTemplate
 3 result storage in cResult
 4 
 5 Example:
 6 
 7     d:\SVN>svn info D:\SVN\ZVideoProcessor
 8     Path: ZVideoProcessor
 9     Working Copy Root Path: D:\SVN
10     URL: http://192.168.2.196/svn/Repos/ZVideoProcessor
11     Relative URL: ^/ZVideoProcessor
12     Repository Root: http://192.168.2.196/svn/Repos
13     Repository UUID: 43546b21-47e8-432e-acd4-bb9acb1f9fba
14     Revision: 1270
15     Node Kind: directory
16     Schedule: normal
17     Last Changed Author: sam.zhen
18     Last Changed Rev: 1268
19     Last Changed Date: 2018-11-01 20:29:28 +0800 (周四, 01 十一月 2018)
20 
21     cmd: svn info D:\SVN\ZVideoProcessor
22     cTemplate: Revision: 
23     cResult: 1270
24 */
25 int execmd(char* cmd,char* cResult,char* cTemplate) 
26 {
27     int iTemplateSize=strlen(cTemplate);
28     char buffer[128];                                                
29     FILE* pipe = _popen(cmd, "r");//open pipe ,execute cmd 
30     if (!pipe)
31     {
32         cout<<"execute "<<cmd<<"error"<<endl;
33         return -1;    
34     }
35 
36     while(!feof(pipe)) 
37     {
38         if(fgets(buffer, 128, pipe))
39         {                         
40             //if cTemplate in buffer,then storage result in cResult
41             int res=strncmp(cTemplate,buffer,iTemplateSize);
42             if(res==0)
43             {
44                 strncat(cResult,buffer+iTemplateSize,10);
45                 int i=strlen(cResult);//because have '\n'
46                 cResult[i-1]='\0';
47                 break;
48             }
49             else
50             {
51                 continue;
52             }
53         }
54     }
55 
56     _pclose(pipe);//close pipe
57     return 0;                                  
58 }
59 
60 int main()
61 {
62     //get svn version
63     char cSvnVersionNum[10];
64     memset(cSvnVersionNum,0,sizeof(cSvnVersionNum));
65     execmd("svn info ../../../SVN",cSvnVersionNum,"Revision: ");
66   return 0;
67 }
  • 方法二 通過預處理方式

轉載自:

c++代碼中,使用svn版本號作為程序版本號的實現方法

1.編寫版本模板文件svn_revision_template.h

1 #ifndef _SVN_REISION_H_
2 #define _SVN_REVISION_H_
3 #define AMG_LIB_VER_SVN_VERSION            "$WCREV$"
4 #endif // !_SVN_REISION_H_

 

注意$WCREV$這里不能修改

 2.新建版本文件svn_revision.h

1 #ifndef _SVN_REISION_H_
2 #define _SVN_REVISION_H_
3 #define AMG_LIB_VER_SVN_VERSION            "1267"
4 #endif // !_SVN_REISION_H_

 

 

3.通過預先生成事件,添加下面的批處理命令

subwcrev.exe .\   .\svn_revision_template.h  .\svn_revision.h

注意第一個參數.\ 指需要獲取哪個路徑的svn號碼

第二個參數.\svn_revision_template.h 指模板文件路徑

第三個參數.\svn_revision.h 指修改后文件保存路徑

 

4.代碼中使用:直接使用.\svn_revision.h文件中的宏

AMG_LIB_VER_SVN_VERSION


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM