我查看了以下帖子(SharpSVN: Getting Repository Structure and Individual Files),并且只能在主要级别成功获取我的存储库的结构。我需要做的是为主级别下的每个文件夹/子文件夹获取整个结构。这是我到目前为止的代码:
Dim svnUrl As String = "https:\\SVN MAIN LEVEL REPOSITORY"
Using svnClient As New SvnClient()
Dim contents As Collection(Of SvnListEventArgs)
Dim files As New List(Of String)()
If svnClient.GetList(New Uri(svnUrl), contents) Then
For Each item As SvnListEventArgs In contents
'files.Add(item.Path)
ListBox1.Items.Add(item.Path)
TreeView1.Nodes.Add(item.Path)
Next
End If
End Using
我缺少什么或者我需要递归调用函数并传递级别?
答案 0 :(得分:1)
您可以在可以传递给.GetList的可选args对象的Depth属性上传递SvnDepth.Infinite。
但要注意在一个非常庞大的存储库的根目录上调用此函数,因为在看到第一个结果之前,所有内容都在ram中缓存。
使用带有回调函数的.List()会在结果到达时报告结果,允许GC在您完成后立即释放项目。
答案 1 :(得分:1)
由于我的具体要求,我最终编写了自己的递归子:
If svnClient.GetList(New Uri(svnUrl), contents) Then
ReDim Preserve node_array(UBound(node_array) + 1)
node_array(UBound(node_array)) = LibraryNode.Text
For Each SubFolder As SvnListEventArgs In contents
Dim MainNode As TreeNode = New TreeNode(SubFolder.Name)
If SubFolder.Name <> "My Top Level Folder" Then
ReDim Preserve node_array(UBound(node_array) + 1)
node_array(UBound(node_array)) = LibraryNode.Text & "\" & MainNode.Text
Dim thelevel As String = LibraryNode.Text & "\" & MainNode.Text
LibraryNode.Nodes.Add(MainNode)
currentlevel = 0
FillTreeViewNodesSVN(SubFolder.Uri.ToString, MainNode, svnClient, thelevel, currentlevel)
End If
Next
End If
以上调用递归子:
Public Sub FillTreeViewNodesSVN(ByVal SubFolder As String, ByVal MainNode As TreeNode, ByVal svnClient As SvnClient, ByVal thelevel As String, ByVal currentlevel As Integer)
Dim contents As Collection(Of SvnListEventArgs)
Dim files As New List(Of String)()
If svnClient.GetList(New Uri(SubFolder), contents) Then
For Each item As SvnListEventArgs In contents
If item.Uri.ToString <> SubFolder And InStr(item.Uri.ToString, "tag") > 0 Then
Dim SubNode As TreeNode = New TreeNode(item.Name)
ReDim Preserve node_array(UBound(node_array) + 1)
node_array(UBound(node_array)) = thelevel & "\" & SubNode.Text
thelevel = thelevel & "\" & SubNode.Text
currentlevel = currentlevel + 1
If currentlevel < 2 Then
FillTreeViewNodesSVN(item.Uri.ToString, SubNode, svnClient, thelevel, currentlevel)
End If
currentlevel = currentlevel - 1
thelevel = thelevel.Replace("\" & SubNode.Text, "")
End If
Next
End If
End Sub
组合2创建一个文件夹的节点列表2级深度只有TAGS文件夹。这为我提供了给定项目的所有已部署TAG。