SharpSVN:获取整个存储库结构
SharpSVN: Getting Entire Repository Structure
我查看了以下 post (SharpSVN: Getting Repository Structure and Individual Files) 并且只能在主级别成功获取我的存储库的结构。我需要做的是获取主层下每个 folder/subfolder 的完整结构。这是我到目前为止的代码:
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
我错过了什么或者我需要递归调用函数并传入关卡吗?
您可以传递 SvnDepth.Infinite 可选参数对象的深度 属性,您可以传递给 .GetList。
但是在非常大的存储库的根目录上调用此函数时要小心,因为在您看到第一个结果之前,所有内容都缓存在 ram 中。
使用带有回调函数的 .List() 在结果到达时报告结果,允许 GC 在您完成后立即释放项目。
由于我的具体要求,我最终编写了自己的递归子程序:
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 创建文件夹的节点列表,只有 TAGS 文件夹深 2 层。这让我获得了给定项目的所有已部署标签。
我查看了以下 post (SharpSVN: Getting Repository Structure and Individual Files) 并且只能在主级别成功获取我的存储库的结构。我需要做的是获取主层下每个 folder/subfolder 的完整结构。这是我到目前为止的代码:
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
我错过了什么或者我需要递归调用函数并传入关卡吗?
您可以传递 SvnDepth.Infinite 可选参数对象的深度 属性,您可以传递给 .GetList。
但是在非常大的存储库的根目录上调用此函数时要小心,因为在您看到第一个结果之前,所有内容都缓存在 ram 中。
使用带有回调函数的 .List() 在结果到达时报告结果,允许 GC 在您完成后立即释放项目。
由于我的具体要求,我最终编写了自己的递归子程序:
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 创建文件夹的节点列表,只有 TAGS 文件夹深 2 层。这让我获得了给定项目的所有已部署标签。