Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 61ee04b

Browse files
Merge branch 'fixes/changes-view-performance' into fixes/break-up-git-add
2 parents 9e13714 + 0e5f48b commit 61ee04b

File tree

15 files changed

+1034
-278
lines changed

15 files changed

+1034
-278
lines changed

src/GitHub.Api/Git/GitObjectFactory.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ public GitObjectFactory(IEnvironment environment)
1414

1515
public GitStatusEntry CreateGitStatusEntry(string path, GitFileStatus status, string originalPath = null, bool staged = false)
1616
{
17-
var npath = new NPath(path).MakeAbsolute();
18-
var relativePath = npath.RelativeTo(environment.RepositoryPath);
19-
var projectPath = npath.RelativeTo(environment.UnityProjectPath);
17+
var absolutePath = new NPath(path).MakeAbsolute();
18+
var relativePath = absolutePath.RelativeTo(environment.RepositoryPath);
19+
var projectPath = absolutePath.RelativeTo(environment.UnityProjectPath);
2020

21-
return new GitStatusEntry(relativePath, npath, projectPath, status, originalPath?.ToNPath(), staged);
21+
return new GitStatusEntry(relativePath, absolutePath, projectPath, status, originalPath?.ToNPath(), staged);
2222
}
2323

2424
public GitLock CreateGitLock(string path, string user, int id)

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@
221221
<Compile Include="Extensions\UriExtensions.cs" />
222222
<Compile Include="Platform\Platform.cs" />
223223
<Compile Include="Git\GitCredentialManager.cs" />
224+
<Compile Include="UI\FileTreeNode.cs" />
225+
<Compile Include="UI\GitCommitTarget.cs" />
226+
<Compile Include="UI\TreeBuilder.cs" />
224227
</ItemGroup>
225228
<Choose>
226229
<When Condition="$(Buildtype) == 'Internal'">

src/GitHub.Api/GitHub.Api.csproj.DotSettings

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=platform/@EntryIndexedValue">True</s:Boolean>
1515
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=primitives/@EntryIndexedValue">True</s:Boolean>
1616
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=process/@EntryIndexedValue">True</s:Boolean>
17-
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=tasks/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
17+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=tasks/@EntryIndexedValue">True</s:Boolean>
18+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=ui/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

src/GitHub.Api/GitHub.Api.v3.ncrunchproject

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<ProjectConfiguration>
22
<Settings>
3+
<AdditionalFilesToIncludeForProject>
4+
<Value>..\..\script\lib\UnityEditor.dll</Value>
5+
<Value>..\..\script\lib\UnityEngine.dll</Value>
6+
</AdditionalFilesToIncludeForProject>
37
<HiddenComponentWarnings />
48
<PreviouslyBuiltSuccessfully>True</PreviouslyBuiltSuccessfully>
59
</Settings>

src/GitHub.Api/UI/FileTreeNode.cs

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace GitHub.Unity
6+
{
7+
enum CommitState
8+
{
9+
None,
10+
Some,
11+
All
12+
}
13+
14+
class FileTreeNode
15+
{
16+
private readonly Action<FileTreeNode> stateChangeCallback;
17+
private List<FileTreeNode> children;
18+
private string path;
19+
private CommitState state;
20+
21+
public object Icon;
22+
public string Label;
23+
public bool Open = true;
24+
public string RepositoryPath;
25+
public GitCommitTarget Target { get; set; }
26+
27+
public FileTreeNode(Action<FileTreeNode> stateChangeCallback)
28+
{
29+
this.stateChangeCallback = stateChangeCallback;
30+
children = new List<FileTreeNode>();
31+
}
32+
33+
public FileTreeNode(string path, Action<FileTreeNode> stateChangeCallback)
34+
{
35+
this.stateChangeCallback = stateChangeCallback;
36+
this.path = path ?? "";
37+
Label = this.path;
38+
children = new List<FileTreeNode>();
39+
}
40+
41+
public FileTreeNode Add(FileTreeNode child)
42+
{
43+
children.Add(child);
44+
return child;
45+
}
46+
47+
public CommitState State
48+
{
49+
get
50+
{
51+
if (children == null)
52+
return state;
53+
54+
var commitState = CommitState.None;
55+
if (Target != null)
56+
{
57+
commitState = Target.All ? CommitState.All : Target.Any ? CommitState.Some : CommitState.None;
58+
if (!children.Any())
59+
{
60+
state = commitState;
61+
return state;
62+
}
63+
}
64+
65+
var allCount = children.Count(c => c.State == CommitState.All);
66+
67+
if (allCount == children.Count && (commitState == CommitState.All || Target == null))
68+
{
69+
state = CommitState.All;
70+
return state;
71+
}
72+
73+
if (allCount > 0 || commitState == CommitState.Some)
74+
{
75+
state = CommitState.Some;
76+
return state;
77+
}
78+
79+
var someCount = children.Count(c => c.State == CommitState.Some);
80+
if (someCount > 0 || commitState == CommitState.Some)
81+
{
82+
state = CommitState.Some;
83+
return state;
84+
}
85+
state = CommitState.None;
86+
return state;
87+
}
88+
89+
set
90+
{
91+
if (value == state)
92+
{
93+
return;
94+
}
95+
96+
if (Target != null)
97+
{
98+
if (value == CommitState.None)
99+
{
100+
Target.Clear();
101+
}
102+
else if (value == CommitState.All)
103+
{
104+
Target.All = true;
105+
}
106+
}
107+
108+
state = value;
109+
stateChangeCallback?.Invoke(this);
110+
111+
if (children == null)
112+
{
113+
return;
114+
}
115+
116+
for (var index = 0; index < children.Count; ++index)
117+
{
118+
children[index].State = value;
119+
}
120+
}
121+
}
122+
123+
public string Path
124+
{
125+
get { return path; }
126+
}
127+
128+
public IEnumerable<FileTreeNode> Children
129+
{
130+
get {
131+
if (children == null)
132+
children = new List<FileTreeNode>();
133+
return children;
134+
}
135+
}
136+
137+
private ILogging logger;
138+
protected ILogging Logger
139+
{
140+
get
141+
{
142+
if (logger == null)
143+
logger = Logging.GetLogger(GetType());
144+
return logger;
145+
}
146+
}
147+
}
148+
}

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/GitCommitTarget.cs renamed to src/GitHub.Api/UI/GitCommitTarget.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using System;
2-
using UnityEngine;
32

43
namespace GitHub.Unity
54
{
65
[Serializable]
76
class GitCommitTarget
87
{
9-
[SerializeField] public bool All = false;
8+
public bool All = false;
109

1110
public void Clear()
1211
{

src/GitHub.Api/UI/TreeBuilder.cs

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace GitHub.Unity
6+
{
7+
static class TreeBuilder
8+
{
9+
internal static void BuildChildNode(FileTreeNode parent, FileTreeNode node, List<string> foldedTreeEntries1, Action<FileTreeNode> stateChangeCallback1)
10+
{
11+
if (String.IsNullOrEmpty(node.Label))
12+
{
13+
// TODO: We should probably reassign this target onto the parent? Depends on how we want to handle .meta files for folders
14+
return;
15+
}
16+
17+
node.RepositoryPath = parent.RepositoryPath.ToNPath().Combine(node.Label);
18+
parent.Open = !foldedTreeEntries1.Contains(parent.RepositoryPath);
19+
20+
// Is this node inside a folder?
21+
var nodePath = node.Label.ToNPath();
22+
if (nodePath.Elements.Count() > 1)
23+
{
24+
// Figure out what the root folder is and chop it from the path
25+
var root = nodePath.Elements.First();
26+
node.Label = new NPath("").Combine(nodePath.Elements.Skip(1).ToArray());
27+
28+
// Look for a branch matching our root in the existing children
29+
var found = false;
30+
foreach (var child in parent.Children)
31+
{
32+
// If we found the branch, continue building from that branch
33+
if (child.Label.Equals(root))
34+
{
35+
found = true;
36+
BuildChildNode(child, node, foldedTreeEntries1, stateChangeCallback1);
37+
break;
38+
}
39+
}
40+
41+
// No existing branch - we will have to add a new one to build from
42+
if (!found)
43+
{
44+
var p = parent.RepositoryPath.ToNPath().Combine(root);
45+
BuildChildNode(parent.Add(new FileTreeNode(root, stateChangeCallback1) { RepositoryPath = p }), node, foldedTreeEntries1, stateChangeCallback1);
46+
}
47+
}
48+
else if (nodePath.ExtensionWithDot == ".meta")
49+
{
50+
// Look for a branch matching our root in the existing children
51+
var found = false;
52+
var searchLabel = nodePath.Parent.Combine(nodePath.FileNameWithoutExtension);
53+
foreach (var child in parent.Children)
54+
{
55+
// If we found the branch, continue building from that branch
56+
if (child.Label.Equals(searchLabel))
57+
{
58+
found = true;
59+
BuildChildNode(child, node, foldedTreeEntries1, stateChangeCallback1);
60+
break;
61+
}
62+
}
63+
if (!found)
64+
{
65+
parent.Add(node);
66+
}
67+
}
68+
// Not inside a folder - just add this node right here
69+
else
70+
{
71+
parent.Add(node);
72+
}
73+
}
74+
75+
internal static FileTreeNode BuildTreeRoot(IList<GitStatusEntry> newEntries, List<GitStatusEntry> gitStatusEntries, List<GitCommitTarget> gitCommitTargets, List<string> foldedTreeEntries, Action<FileTreeNode> stateChangeCallback, Func<string, object> iconLoaderFunc = null)
76+
{
77+
Guard.ArgumentNotNullOrEmpty(newEntries, "newEntries");
78+
79+
var newEntriesSetByPath = new HashSet<string>(newEntries.Select(entry => entry.Path));
80+
var gitStatusEntriesSetByPath = new HashSet<string>(gitStatusEntries.Select(entry => entry.Path));
81+
82+
// Remove what got nuked
83+
for (var index = 0; index < gitStatusEntries.Count;)
84+
{
85+
if (!newEntriesSetByPath.Contains(gitStatusEntries[index].Path))
86+
{
87+
gitStatusEntries.RemoveAt(index);
88+
gitCommitTargets.RemoveAt(index);
89+
}
90+
else
91+
{
92+
index++;
93+
}
94+
}
95+
96+
// Remove folding state of nuked items
97+
for (var index = 0; index < foldedTreeEntries.Count;)
98+
{
99+
if (newEntries.All(e => e.Path.IndexOf(foldedTreeEntries[index], StringComparison.CurrentCulture) != 0))
100+
{
101+
foldedTreeEntries.RemoveAt(index);
102+
}
103+
else
104+
{
105+
index++;
106+
}
107+
}
108+
109+
// Add new stuff
110+
for (var index = 0; index < newEntries.Count; ++index)
111+
{
112+
var entry = newEntries[index];
113+
if (!gitStatusEntriesSetByPath.Contains(entry.Path))
114+
{
115+
gitStatusEntries.Add(entry);
116+
gitCommitTargets.Add(new GitCommitTarget());
117+
}
118+
}
119+
120+
// TODO: Filter .meta files - consider adding them as children of the asset or folder they're supporting
121+
// TODO: In stead of completely rebuilding the tree structure, figure out a way to migrate open/closed states from the old tree to the new
122+
// Build tree structure
123+
124+
var tree = new FileTreeNode(FileSystemHelpers.FindCommonPath(gitStatusEntries.Select(e => e.Path)), stateChangeCallback);
125+
tree.RepositoryPath = tree.Path;
126+
127+
for (var index1 = 0; index1 < gitStatusEntries.Count; index1++)
128+
{
129+
var gitStatusEntry = gitStatusEntries[index1];
130+
var entryPath = gitStatusEntry.Path.ToNPath();
131+
if (entryPath.IsChildOf(tree.Path)) entryPath = entryPath.RelativeTo(tree.Path.ToNPath());
132+
133+
var node = new FileTreeNode(entryPath, stateChangeCallback) { Target = gitCommitTargets[index1] };
134+
if (!String.IsNullOrEmpty(gitStatusEntry.ProjectPath))
135+
{
136+
node.Icon = iconLoaderFunc?.Invoke(gitStatusEntry.ProjectPath);
137+
}
138+
139+
BuildChildNode(tree, node, foldedTreeEntries, stateChangeCallback);
140+
}
141+
142+
return tree;
143+
}
144+
}
145+
}

src/UnityExtension/Assets/Editor/GitHub.Unity/GitHub.Unity.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@
9797
<Compile Include="UI\BranchesView.cs" />
9898
<Compile Include="UI\ChangesetTreeView.cs" />
9999
<Compile Include="UI\ChangesView.cs" />
100-
<Compile Include="UI\GitCommitTarget.cs" />
101100
<Compile Include="UI\HistoryView.cs" />
102101
<Compile Include="UI\IView.cs" />
103102
<Compile Include="UI\SettingsView.cs" />
@@ -111,7 +110,7 @@
111110
</ItemGroup>
112111
<Choose>
113112
<When Condition="$(Buildtype) == 'Internal'">
114-
<ItemGroup >
113+
<ItemGroup>
115114
<Compile Include="$(SolutionDir)\script\src\MetricsInitialization.cs">
116115
<Link>Metrics\MetricsInitialization.cs</Link>
117116
</Compile>

0 commit comments

Comments
 (0)