如果您需要从其他程序访问 Subversion 版本信息,可以使用 SubWCRev 的 COM 接口。要创建的对象是 SubWCRev.object
,并支持以下方法
表 6.4. 支持的 COM/自动化方法
方法 | 描述 |
---|---|
.GetWCInfo |
此方法遍历工作副本,收集版本信息。当然,您必须在使用剩余方法访问信息之前调用此方法。第一个参数是路径。如果要包含文件夹版本,则第二个参数应为 true。等效于命令行开关 -f 。如果要包含 svn:externals,则第三个参数应为 true。等效于命令行开关 -e 。
|
.GetWCInfo2 |
与 GetWCInfo() 相同,但具有第四个参数,该参数设置等效于命令行开关 -E 。
|
.Revision |
工作副本中最高的提交版本。等效于 $WCREV$ 。
|
.Date |
最高提交版本的提交日期/时间。等效于 $WCDATE$ 。
|
.Author | 最高提交版本的作者,即最后提交更改到工作副本的人员。 |
.MinRev |
最小更新版本,如 $WCRANGE$ 中所示
|
.MaxRev |
最大更新版本,如 $WCRANGE$ 中所示
|
.HasModifications | 如果存在本地修改,则为 true |
.HasUnversioned | 如果存在未版本化的项目,则为 true |
.Url |
替换为 GetWCInfo 中使用的工作副本路径的存储库 URL。等效于 $WCURL$ 。
|
.RepoRoot |
替换为存储库根目录的 URL。等效于 $REPOROOT$ 。
|
.IsSvnItem | 如果项目已版本化,则为 true。 |
.NeedsLocking |
如果项目设置了 svn:needs-lock 属性,则为 true。
|
.IsLocked | 如果项目已锁定,则为 true。 |
.LockCreationDate | 表示锁定创建日期的字符串,如果项目未锁定,则为空字符串。 |
.LockOwner | 表示锁定所有者的字符串,如果项目未锁定,则为空字符串。 |
.LockComment | 创建锁定时输入的消息。 |
以下示例展示了如何使用该接口。
// testCOM.js - javascript file // test script for the SubWCRev COM/Automation-object filesystem = new ActiveXObject("Scripting.FileSystemObject"); revObject1 = new ActiveXObject("SubWCRev.object"); revObject2 = new ActiveXObject("SubWCRev.object"); revObject3 = new ActiveXObject("SubWCRev.object"); revObject4 = new ActiveXObject("SubWCRev.object"); revObject1.GetWCInfo( filesystem.GetAbsolutePathName("."), 1, 1); revObject2.GetWCInfo( filesystem.GetAbsolutePathName(".."), 1, 1); revObject3.GetWCInfo( filesystem.GetAbsolutePathName("SubWCRev.cpp"), 1, 1); revObject4.GetWCInfo2( filesystem.GetAbsolutePathName("..\\.."), 1, 1, 1); wcInfoString1 = "Revision = " + revObject1.Revision + "\nMin Revision = " + revObject1.MinRev + "\nMax Revision = " + revObject1.MaxRev + "\nDate = " + revObject1.Date + "\nURL = " + revObject1.Url + "\nAuthor = " + revObject1.Author + "\nHasMods = " + revObject1.HasModifications + "\nIsSvnItem = " + revObject1.IsSvnItem + "\nNeedsLocking = " + revObject1.NeedsLocking + "\nIsLocked = " + revObject1.IsLocked + "\nLockCreationDate = " + revObject1.LockCreationDate + "\nLockOwner = " + revObject1.LockOwner + "\nLockComment = " + revObject1.LockComment; wcInfoString2 = "Revision = " + revObject2.Revision + "\nMin Revision = " + revObject2.MinRev + "\nMax Revision = " + revObject2.MaxRev + "\nDate = " + revObject2.Date + "\nURL = " + revObject2.Url + "\nAuthor = " + revObject2.Author + "\nHasMods = " + revObject2.HasModifications + "\nIsSvnItem = " + revObject2.IsSvnItem + "\nNeedsLocking = " + revObject2.NeedsLocking + "\nIsLocked = " + revObject2.IsLocked + "\nLockCreationDate = " + revObject2.LockCreationDate + "\nLockOwner = " + revObject2.LockOwner + "\nLockComment = " + revObject2.LockComment; wcInfoString3 = "Revision = " + revObject3.Revision + "\nMin Revision = " + revObject3.MinRev + "\nMax Revision = " + revObject3.MaxRev + "\nDate = " + revObject3.Date + "\nURL = " + revObject3.Url + "\nAuthor = " + revObject3.Author + "\nHasMods = " + revObject3.HasModifications + "\nIsSvnItem = " + revObject3.IsSvnItem + "\nNeedsLocking = " + revObject3.NeedsLocking + "\nIsLocked = " + revObject3.IsLocked + "\nLockCreationDate = " + revObject3.LockCreationDate + "\nLockOwner = " + revObject3.LockOwner + "\nLockComment = " + revObject3.LockComment; wcInfoString4 = "Revision = " + revObject4.Revision + "\nMin Revision = " + revObject4.MinRev + "\nMax Revision = " + revObject4.MaxRev + "\nDate = " + revObject4.Date + "\nURL = " + revObject4.Url + "\nAuthor = " + revObject4.Author + "\nHasMods = " + revObject4.HasModifications + "\nIsSvnItem = " + revObject4.IsSvnItem + "\nNeedsLocking = " + revObject4.NeedsLocking + "\nIsLocked = " + revObject4.IsLocked + "\nLockCreationDate = " + revObject4.LockCreationDate + "\nLockOwner = " + revObject4.LockOwner + "\nLockComment = " + revObject4.LockComment; WScript.Echo(wcInfoString1); WScript.Echo(wcInfoString2); WScript.Echo(wcInfoString3); WScript.Echo(wcInfoString4);
以下列表展示了如何从 C# 使用 SubWCRev COM 对象。
using LibSubWCRev; SubWCRev sub = new SubWCRev(); sub.GetWCInfo("C:\\PathToMyFile\\MyFile.cc", true, true); if (sub.IsSvnItem == true) { MessageBox.Show("versioned"); } else { MessageBox.Show("not versioned"); }