【问题标题】:Retrieve list of files using SVN revision number使用 SVN 版本号检索文件列表
【发布时间】:2016-08-25 09:29:13
【问题描述】:

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

【问题讨论】:

    标签: vba svn com tortoisesvn


    【解决方案1】:

    我最终使用了以下方法:

    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
    

    【讨论】:

      猜你喜欢
      • 2017-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多