TortoiseSVN提供COM interface来检索有关文件的信息。
使用VBA,我可以通过执行以下操作获取有关SVN存储库中文件的信息:
Public Function getSvnURL(ByVal fullFilename As String)
Dim oSvn As Object
Set oSvn = CreateObject("SubWCRev.Object")
oSvn.GetWCInfo fullFilename, 1, 1
getSvnURL = oSvn.url
End Function
如果我有SVN版本号,那么我是否可以使用API来获取属于该提交的文件?类似的东西:
Public Function getFilesInRevision(revisionNumber As Integer) as Collection
Dim oSvn As Object
Set oSvn = CreateObject("SubWCRev.Object")
oSvn.GetWCInfo revisionNumber
getFilesInRevision= oSvn.fileList
End Function
答案 0 :(得分:0)
我最终使用以下方法:
Public Function getFilesForRevision(revisionNumber As Long, folder As String) As Collection
Dim command As String
command = "svn log -v -q -r " & revisionNumber & " " & folder
Dim rawText As String
rawText = ShellRun(command)
Dim lines() As String
lines = Split(rawText, vbLf)
Set getFilesForRevision = New Collection
Dim filenameRegex As Object
Set filenameRegex = CreateObject("VBScript.RegExp")
filenameRegex.Pattern = "\s{3}.\s(.*)"
Dim line As Variant
For Each line In lines
If filenameRegex.test(line) Then
getFilesForRevision.Add (filenameRegex.Execute(line).Item(0).submatches(0))
End If
Next line
End Function
依赖于此方法来运行命令并存储控制台输出:
'http://stackoverflow.com/questions/2784367/capture-output-value-from-a-shell-command-in-vba
Public Function ShellRun(sCmd As String) As String
'Run a shell command, returning the output as a string'
Dim oShell As Object
Set oShell = CreateObject("WScript.Shell")
'run command'
Dim oExec As Object
Dim oOutput As Object
Set oExec = oShell.Exec(sCmd)
Set oOutput = oExec.StdOut
'handle the results as they are written to and read from the StdOut object'
Dim s As String
Dim sLine As String
While Not oOutput.AtEndOfStream
sLine = oOutput.ReadLine
If sLine <> "" Then s = s & sLine & vbCrLf
Wend
ShellRun = s
End Function
可以这样调用:
Sub getFilesForRevisionTest()
Dim files As Collection
Set files = getFilesForRevision(111041, "C:\SVN\")
Dim fullFilename As Variant
For Each fullFilename In files
Debug.Print fullFilename
Next fullFilename
End Sub