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

Commit 73858ea

Browse files
Merge branch 'features/using-cache-manager' into fixes/repository-with-better-events
2 parents 6af5853 + 01736cb commit 73858ea

File tree

11 files changed

+166
-185
lines changed

11 files changed

+166
-185
lines changed

src/GitHub.Api/Git/GitBranch.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public struct GitBranch : ITreeData
1313
{
1414
public static GitBranch Default = new GitBranch();
1515

16-
public string name;
17-
public string tracking;
18-
public bool isActive;
16+
private string name;
17+
private string tracking;
18+
private bool isActive;
1919

2020
public string Name { get { return name; } }
2121
public string Tracking { get { return tracking; } }

src/GitHub.Api/Git/GitRemote.cs

Lines changed: 88 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,94 @@ public enum GitRemoteFunction
1414
[Serializable]
1515
public struct GitRemote
1616
{
17-
public string Name;
18-
public string Url;
19-
public string Login;
20-
public string User;
21-
public string Token;
22-
public string Host;
23-
public GitRemoteFunction Function;
17+
public static GitRemote Default = new GitRemote();
18+
19+
private string name;
20+
private string url;
21+
private string login;
22+
private string user;
23+
private string host;
24+
private GitRemoteFunction function;
25+
private readonly string token;
26+
27+
public string Name
28+
{
29+
get { return name; }
30+
}
31+
32+
public string Url
33+
{
34+
get { return url; }
35+
}
36+
37+
public string Login
38+
{
39+
get { return login; }
40+
}
41+
42+
public string User
43+
{
44+
get { return user; }
45+
}
46+
47+
public string Token
48+
{
49+
get { return token; }
50+
}
51+
52+
public string Host
53+
{
54+
get { return host; }
55+
}
56+
57+
public GitRemoteFunction Function
58+
{
59+
get { return function; }
60+
}
61+
62+
public GitRemote(string name, string host, string url, GitRemoteFunction function, string user, string login, string token)
63+
{
64+
this.name = name;
65+
this.url = url;
66+
this.host = host;
67+
this.function = function;
68+
this.user = user;
69+
this.login = login;
70+
this.token = token;
71+
}
72+
73+
public GitRemote(string name, string host, string url, GitRemoteFunction function, string user)
74+
{
75+
this.name = name;
76+
this.url = url;
77+
this.host = host;
78+
this.function = function;
79+
this.user = user;
80+
login = null;
81+
token = null;
82+
}
83+
84+
public GitRemote(string name, string host, string url, GitRemoteFunction function)
85+
{
86+
this.name = name;
87+
this.url = url;
88+
this.host = host;
89+
this.function = function;
90+
this.user = null;
91+
this.login = null;
92+
this.token = null;
93+
}
94+
95+
public GitRemote(string name, string url)
96+
{
97+
this.name = name;
98+
this.url = url;
99+
login = null;
100+
user = null;
101+
token = null;
102+
host = null;
103+
function = GitRemoteFunction.Unknown;
104+
}
24105

25106
public override string ToString()
26107
{

src/GitHub.Api/Git/Repository.cs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,9 @@ private void RepositoryManager_OnRemoteBranchListUpdated(IDictionary<string, Con
431431

432432
private void UpdateRemoteAndRemoteBranches()
433433
{
434-
cacheContainer.BranchCache.Remotes =
435-
cacheContainer.BranchCache.ConfigRemotes.Values.Select(GetGitRemote).ToArray();
434+
Remotes = ConfigRemotes.Values.Select(GetGitRemote).ToArray();
436435

437-
cacheContainer.BranchCache.RemoteBranches = cacheContainer
438-
.BranchCache.RemoteConfigBranches.Values.SelectMany(x => x.Values).Select(GetRemoteGitBranch).ToArray();
436+
RemoteBranches = RemoteConfigBranches.Values.SelectMany(x => x.Values).Select(GetRemoteGitBranch).ToArray();
439437
}
440438

441439
private void RepositoryManager_OnLocalBranchListUpdated(IDictionary<string, ConfigBranch> branches)
@@ -448,8 +446,7 @@ private void RepositoryManager_OnLocalBranchListUpdated(IDictionary<string, Conf
448446

449447
private void UpdateLocalBranches()
450448
{
451-
cacheContainer.BranchCache.LocalBranches = cacheContainer
452-
.BranchCache.LocalConfigBranches.Values.Select(GetLocalGitBranch).ToArray();
449+
LocalBranches = LocalConfigBranches.Values.Select(GetLocalGitBranch).ToArray();
453450
}
454451

455452
private void UpdateRepositoryInfo()
@@ -518,19 +515,37 @@ private static GitBranch GetRemoteGitBranch(ConfigBranch x)
518515

519516
private static GitRemote GetGitRemote(ConfigRemote configRemote)
520517
{
521-
return new GitRemote { Name = configRemote.Name, Url = configRemote.Url };
518+
return new GitRemote(configRemote.Name, configRemote.Url);
522519
}
523520

524-
public GitRemote[] Remotes => cacheContainer.BranchCache.Remotes;
521+
private IRemoteConfigBranchDictionary RemoteConfigBranches => cacheContainer.BranchCache.RemoteConfigBranches;
525522

526-
public GitBranch[] LocalBranches => cacheContainer.BranchCache.LocalBranches;
523+
private IConfigRemoteDictionary ConfigRemotes => cacheContainer.BranchCache.ConfigRemotes;
527524

528-
public GitBranch[] RemoteBranches => cacheContainer.BranchCache.RemoteBranches;
525+
private ILocalConfigBranchDictionary LocalConfigBranches => cacheContainer.BranchCache.LocalConfigBranches;
526+
527+
public GitRemote[] Remotes
528+
{
529+
get { return cacheContainer.BranchCache.Remotes; }
530+
set { cacheContainer.BranchCache.Remotes = value; }
531+
}
532+
533+
public GitBranch[] LocalBranches
534+
{
535+
get { return cacheContainer.BranchCache.LocalBranches; }
536+
set { cacheContainer.BranchCache.LocalBranches = value; }
537+
}
538+
539+
public GitBranch[] RemoteBranches
540+
{
541+
get { return cacheContainer.BranchCache.RemoteBranches; }
542+
set { cacheContainer.BranchCache.RemoteBranches = value; }
543+
}
529544

530545
private ConfigBranch? CurrentConfigBranch
531546
{
532547
get { return this.cacheContainer.BranchCache.CurentConfigBranch; }
533-
set { cacheContainer.BranchCache.CurentConfigBranch = value;}
548+
set { cacheContainer.BranchCache.CurentConfigBranch = value; }
534549
}
535550

536551
private ConfigRemote? CurrentConfigRemote

src/GitHub.Api/OutputProcessors/RemoteListOutputProcessor.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,7 @@ private void ReturnRemote()
9999
currentUrl = currentUrl.Substring(user.Length + 1);
100100
}
101101

102-
RaiseOnEntry(new GitRemote
103-
{
104-
Name = currentName,
105-
Host = host,
106-
Url = currentUrl,
107-
User = user,
108-
Function = remoteFunction
109-
});
110-
102+
RaiseOnEntry(new GitRemote(currentName, host, currentUrl, remoteFunction, user, null, null));
111103
Reset();
112104
}
113105

src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationCache.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,6 @@ public ConfigRemoteDictionary(IDictionary<string, ConfigRemote> dictionary)
415415
[Location("cache/repoinfo.yaml", LocationAttribute.Location.LibraryFolder)]
416416
sealed class RepositoryInfoCache : ManagedCacheBase<RepositoryInfoCache>, IRepositoryInfoCache
417417
{
418-
public static readonly GitRemote DefaultGitRemote = new GitRemote();
419-
public static readonly GitBranch DefaultGitBranch = new GitBranch();
420-
421418
[SerializeField] private string lastUpdatedAtString = DateTimeOffset.MinValue.ToString();
422419
[SerializeField] private string lastVerifiedAtString = DateTimeOffset.MinValue.ToString();
423420
[SerializeField] private GitRemote gitRemote;
@@ -428,7 +425,7 @@ public GitRemote? CurrentGitRemote
428425
get
429426
{
430427
ValidateData();
431-
return gitRemote.Equals(DefaultGitRemote) ? (GitRemote?)null : gitRemote;
428+
return gitRemote.Equals(GitRemote.Default) ? (GitRemote?)null : gitRemote;
432429
}
433430
set
434431
{
@@ -439,7 +436,7 @@ public GitRemote? CurrentGitRemote
439436

440437
if (!Nullable.Equals(gitRemote, value))
441438
{
442-
gitRemote = value ?? DefaultGitRemote;
439+
gitRemote = value ?? GitRemote.Default;
443440
isUpdated = true;
444441
}
445442

@@ -452,7 +449,7 @@ public GitBranch? CurentGitBranch
452449
get
453450
{
454451
ValidateData();
455-
return gitBranch.Equals(DefaultGitBranch) ? (GitBranch?)null : gitBranch;
452+
return gitBranch.Equals(GitBranch.Default) ? (GitBranch?)null : gitBranch;
456453
}
457454
set
458455
{
@@ -463,7 +460,7 @@ public GitBranch? CurentGitBranch
463460

464461
if (!Nullable.Equals(gitBranch, value))
465462
{
466-
gitBranch = value ?? DefaultGitBranch;
463+
gitBranch = value ?? GitBranch.Default;
467464
isUpdated = true;
468465
}
469466

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@ public override void OnDataUpdate()
8484
MaybeUpdateData();
8585
}
8686

87-
public override void OnRepositoryChanged(IRepository oldRepository)
88-
{
89-
base.OnRepositoryChanged(oldRepository);
90-
gitPathView.OnRepositoryChanged(oldRepository);
91-
userSettingsView.OnRepositoryChanged(oldRepository);
92-
}
93-
9487
public override void Refresh()
9588
{
9689
base.Refresh();

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Subview.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ public virtual void Finish(bool result)
4848
Parent.Finish(result);
4949
}
5050

51-
public virtual void OnRepositoryChanged(IRepository oldRepository)
52-
{}
53-
5451
protected IView Parent { get; private set; }
5552
public IApplicationManager Manager { get { return Parent.Manager; } }
5653
public IRepository Repository { get { return Parent.Repository; } }

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ public override void OnRepositoryChanged(IRepository oldRepository)
134134
}
135135

136136
UpdateActiveTab();
137-
138-
if (ActiveView != null)
139-
ActiveView.OnRepositoryChanged(oldRepository);
140137
}
141138

142139
public override void OnSelectionChange()

0 commit comments

Comments
 (0)