@@ -6,7 +6,7 @@ namespace GitHub.Unity
6
6
{
7
7
static class TreeBuilder
8
8
{
9
- internal static void BuildChildNode ( FileTreeNode parent , FileTreeNode node , List < string > foldedTreeEntries )
9
+ internal static void BuildChildNode ( FileTreeNode parent , FileTreeNode node , HashSet < string > foldedTreeSet )
10
10
{
11
11
if ( String . IsNullOrEmpty ( node . Label ) )
12
12
{
@@ -15,7 +15,7 @@ internal static void BuildChildNode(FileTreeNode parent, FileTreeNode node, List
15
15
}
16
16
17
17
node . RepositoryPath = parent . RepositoryPath . ToNPath ( ) . Combine ( node . Label ) ;
18
- parent . Open = ! foldedTreeEntries . Contains ( parent . RepositoryPath ) ;
18
+ parent . Open = ! foldedTreeSet . Contains ( parent . RepositoryPath ) ;
19
19
20
20
// Is this node inside a folder?
21
21
var nodePath = node . Label . ToNPath ( ) ;
@@ -33,7 +33,7 @@ internal static void BuildChildNode(FileTreeNode parent, FileTreeNode node, List
33
33
if ( child . Label . Equals ( root ) )
34
34
{
35
35
found = true ;
36
- BuildChildNode ( child , node , foldedTreeEntries ) ;
36
+ BuildChildNode ( child , node , foldedTreeSet ) ;
37
37
break ;
38
38
}
39
39
}
@@ -42,20 +42,21 @@ internal static void BuildChildNode(FileTreeNode parent, FileTreeNode node, List
42
42
if ( ! found )
43
43
{
44
44
var p = parent . RepositoryPath . ToNPath ( ) . Combine ( root ) ;
45
- BuildChildNode ( parent . Add ( new FileTreeNode ( root ) { RepositoryPath = p } ) , node , foldedTreeEntries ) ;
45
+ BuildChildNode ( parent . Add ( new FileTreeNode ( root ) { RepositoryPath = p } ) , node , foldedTreeSet ) ;
46
46
}
47
47
}
48
48
else if ( nodePath . ExtensionWithDot == ".meta" )
49
49
{
50
50
// Look for a branch matching our root in the existing children
51
51
var found = false ;
52
+ var searchLabel = nodePath . Parent . Combine ( nodePath . FileNameWithoutExtension ) ;
52
53
foreach ( var child in parent . Children )
53
54
{
54
55
// If we found the branch, continue building from that branch
55
- if ( child . Label . Equals ( nodePath . Parent . Combine ( nodePath . FileNameWithoutExtension ) ) )
56
+ if ( child . Label . Equals ( searchLabel ) )
56
57
{
57
58
found = true ;
58
- BuildChildNode ( child , node , foldedTreeEntries ) ;
59
+ BuildChildNode ( child , node , foldedTreeSet ) ;
59
60
break ;
60
61
}
61
62
}
@@ -75,10 +76,13 @@ internal static FileTreeNode BuildTreeRoot(IList<GitStatusEntry> newEntries, Lis
75
76
{
76
77
Guard . ArgumentNotNullOrEmpty ( newEntries , "newEntries" ) ;
77
78
79
+ var newEntriesSetByPath = new HashSet < string > ( newEntries . Select ( entry => entry . Path ) ) ;
80
+ var gitStatusEntriesSetByPath = new HashSet < string > ( gitStatusEntries . Select ( entry => entry . Path ) ) ;
81
+
78
82
// Remove what got nuked
79
83
for ( var index = 0 ; index < gitStatusEntries . Count ; )
80
84
{
81
- if ( ! newEntries . Contains ( gitStatusEntries [ index ] ) )
85
+ if ( ! newEntriesSetByPath . Contains ( gitStatusEntries [ index ] . Path ) )
82
86
{
83
87
gitStatusEntries . RemoveAt ( index ) ;
84
88
gitCommitTargets . RemoveAt ( index ) ;
@@ -92,7 +96,7 @@ internal static FileTreeNode BuildTreeRoot(IList<GitStatusEntry> newEntries, Lis
92
96
// Remove folding state of nuked items
93
97
for ( var index = 0 ; index < foldedTreeEntries . Count ; )
94
98
{
95
- if ( ! newEntries . Any ( e => e . Path . IndexOf ( foldedTreeEntries [ index ] ) = = 0 ) )
99
+ if ( newEntries . All ( e => e . Path . IndexOf ( foldedTreeEntries [ index ] , StringComparison . CurrentCulture ) ! = 0 ) )
96
100
{
97
101
foldedTreeEntries . RemoveAt ( index ) ;
98
102
}
@@ -102,11 +106,13 @@ internal static FileTreeNode BuildTreeRoot(IList<GitStatusEntry> newEntries, Lis
102
106
}
103
107
}
104
108
109
+ var foldedTreeSet = new HashSet < string > ( foldedTreeEntries ) ;
110
+
105
111
// Add new stuff
106
112
for ( var index = 0 ; index < newEntries . Count ; ++ index )
107
113
{
108
114
var entry = newEntries [ index ] ;
109
- if ( ! gitStatusEntries . Contains ( entry ) )
115
+ if ( ! gitStatusEntriesSetByPath . Contains ( entry . Path ) )
110
116
{
111
117
gitStatusEntries . Add ( entry ) ;
112
118
gitCommitTargets . Add ( new GitCommitTarget ( ) ) ;
@@ -132,7 +138,7 @@ internal static FileTreeNode BuildTreeRoot(IList<GitStatusEntry> newEntries, Lis
132
138
node . Icon = iconLoaderFunc ? . Invoke ( gitStatusEntry . ProjectPath ) ;
133
139
}
134
140
135
- BuildChildNode ( tree , node , foldedTreeEntries ) ;
141
+ BuildChildNode ( tree , node , foldedTreeSet ) ;
136
142
}
137
143
138
144
return tree ;
0 commit comments