0

TortoiseSVN provides a COM interface for retrieving information about a file.

Using VBA, I can get information about a file in the SVN repository by doing this:

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

If I have an SVN revision number however, is there an API I can use to get the files that were part of that commit? Something like:

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
Fidel
  • 7,027
  • 11
  • 57
  • 81

1 Answers1

0

I ended up using the following method:

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

Which relies on this method to run the command and store the console output:

'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

Which can be called like this:

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
Fidel
  • 7,027
  • 11
  • 57
  • 81