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

Commit 34b2cc8

Browse files
Merge pull request #390 from github-for-unity/features/using-cache-manager
Adding and using the CacheManager
2 parents 615955f + 08705a7 commit 34b2cc8

32 files changed

+2271
-1080
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ public void Dispose()
215215
public ISettings SystemSettings { get; protected set; }
216216
public ISettings UserSettings { get; protected set; }
217217
public IUsageTracker UsageTracker { get; protected set; }
218-
219218
protected TaskScheduler UIScheduler { get; private set; }
220219
protected SynchronizationContext SynchronizationContext { get; private set; }
221220
protected IRepositoryManager RepositoryManager { get { return repositoryManager; } }
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace GitHub.Unity
5+
{
6+
public enum CacheType
7+
{
8+
RepositoryInfoCache,
9+
BranchCache,
10+
GitLogCache,
11+
GitStatusCache,
12+
GitLocksCache,
13+
GitUserCache
14+
}
15+
16+
public interface ICacheContainer
17+
{
18+
event Action<CacheType> CacheInvalidated;
19+
event Action<CacheType, DateTimeOffset> CacheUpdated;
20+
21+
IBranchCache BranchCache { get; }
22+
IGitLogCache GitLogCache { get; }
23+
IGitStatusCache GitStatusCache { get; }
24+
IGitLocksCache GitLocksCache { get; }
25+
IGitUserCache GitUserCache { get; }
26+
IRepositoryInfoCache RepositoryInfoCache { get; }
27+
void Validate(CacheType cacheType);
28+
void ValidateAll();
29+
void Invalidate(CacheType cacheType);
30+
void InvalidateAll();
31+
}
32+
33+
public interface IManagedCache
34+
{
35+
event Action CacheInvalidated;
36+
event Action<DateTimeOffset> CacheUpdated;
37+
38+
void ValidateData();
39+
void InvalidateData();
40+
41+
DateTimeOffset LastUpdatedAt { get; }
42+
DateTimeOffset LastVerifiedAt { get; }
43+
}
44+
45+
public interface IGitLocksCache : IManagedCache
46+
{
47+
List<GitLock> GitLocks { get; set; }
48+
}
49+
50+
public interface IGitUserCache : IManagedCache
51+
{
52+
User User { get; }
53+
}
54+
55+
public interface IGitStatusCache : IManagedCache
56+
{
57+
GitStatus GitStatus { get; set; }
58+
}
59+
60+
public interface ILocalConfigBranchDictionary : IDictionary<string, ConfigBranch>
61+
{
62+
63+
}
64+
65+
public interface IRemoteConfigBranchDictionary : IDictionary<string, IDictionary<string, ConfigBranch>>
66+
{
67+
68+
}
69+
70+
public interface IConfigRemoteDictionary : IDictionary<string, ConfigRemote>
71+
{
72+
73+
}
74+
75+
public interface IBranchCache : IManagedCache
76+
{
77+
ConfigRemote? CurrentConfigRemote { get; set; }
78+
ConfigBranch? CurentConfigBranch { get; set; }
79+
80+
GitBranch[] LocalBranches { get; set; }
81+
GitBranch[] RemoteBranches { get; set; }
82+
GitRemote[] Remotes { get; set; }
83+
84+
ILocalConfigBranchDictionary LocalConfigBranches { get; }
85+
IRemoteConfigBranchDictionary RemoteConfigBranches { get; }
86+
IConfigRemoteDictionary ConfigRemotes { get; }
87+
88+
void RemoveLocalBranch(string branch);
89+
void AddLocalBranch(string branch);
90+
void AddRemoteBranch(string remote, string branch);
91+
void RemoveRemoteBranch(string remote, string branch);
92+
void SetRemotes(Dictionary<string, ConfigRemote> remoteDictionary, Dictionary<string, Dictionary<string, ConfigBranch>> branchDictionary);
93+
void SetLocals(Dictionary<string, ConfigBranch> branchDictionary);
94+
}
95+
96+
public interface IRepositoryInfoCache : IManagedCache
97+
{
98+
GitRemote? CurrentGitRemote { get; set; }
99+
GitBranch? CurentGitBranch { get; set; }
100+
}
101+
102+
public interface IGitLogCache : IManagedCache
103+
{
104+
List<GitLogEntry> Log { get; set; }
105+
}
106+
}

src/GitHub.Api/Cache/IBranchCache.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/GitHub.Api/Git/GitLogEntry.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public string PrettyTimeString
4242
}
4343
}
4444

45-
[NonSerialized] public DateTimeOffset? timeValue;
45+
[NonSerialized] private DateTimeOffset? timeValue;
4646
public DateTimeOffset Time
4747
{
4848
get
@@ -56,7 +56,7 @@ public DateTimeOffset Time
5656
}
5757
}
5858

59-
[NonSerialized] public DateTimeOffset? commitTimeValue;
59+
[NonSerialized] private DateTimeOffset? commitTimeValue;
6060
public DateTimeOffset? CommitTime
6161
{
6262
get

src/GitHub.Api/Git/GitRemote.cs

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,59 @@ 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+
public string name;
20+
public string url;
21+
public string login;
22+
public string user;
23+
public string host;
24+
public GitRemoteFunction function;
25+
public string token;
26+
27+
public GitRemote(string name, string host, string url, GitRemoteFunction function, string user, string login, string token)
28+
{
29+
this.name = name;
30+
this.url = url;
31+
this.host = host;
32+
this.function = function;
33+
this.user = user;
34+
this.login = login;
35+
this.token = token;
36+
}
37+
38+
public GitRemote(string name, string host, string url, GitRemoteFunction function, string user)
39+
{
40+
this.name = name;
41+
this.url = url;
42+
this.host = host;
43+
this.function = function;
44+
this.user = user;
45+
this.login = null;
46+
this.token = null;
47+
}
48+
49+
public GitRemote(string name, string host, string url, GitRemoteFunction function)
50+
{
51+
this.name = name;
52+
this.url = url;
53+
this.host = host;
54+
this.function = function;
55+
this.user = null;
56+
this.login = null;
57+
this.token = null;
58+
}
59+
60+
public GitRemote(string name, string url)
61+
{
62+
this.name = name;
63+
this.url = url;
64+
this.login = null;
65+
this.user = null;
66+
this.token = null;
67+
this.host = null;
68+
this.function = GitRemoteFunction.Unknown;
69+
}
2470

2571
public override string ToString()
2672
{
@@ -33,5 +79,13 @@ public override string ToString()
3379
sb.AppendLine(String.Format("Function: {0}", Function));
3480
return sb.ToString();
3581
}
82+
83+
public string Name => name;
84+
public string Url => url;
85+
public string Login => login;
86+
public string User => user;
87+
public string Token => token;
88+
public string Host => host;
89+
public GitRemoteFunction Function => function;
3690
}
3791
}

src/GitHub.Api/Git/IRepository.cs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,26 @@ namespace GitHub.Unity
99
public interface IRepository : IEquatable<IRepository>
1010
{
1111
void Initialize(IRepositoryManager repositoryManager);
12-
void Refresh();
1312
ITask CommitAllFiles(string message, string body);
1413
ITask CommitFiles(List<string> files, string message, string body);
1514
ITask SetupRemote(string remoteName, string remoteUrl);
16-
ITask<List<GitLogEntry>> Log();
1715
ITask Pull();
1816
ITask Push();
1917
ITask Fetch();
2018
ITask Revert(string changeset);
21-
ITask ListLocks();
2219
ITask RequestLock(string file);
2320
ITask ReleaseLock(string file, bool force);
2421

22+
void CheckLogChangedEvent(CacheUpdateEvent gitLogCacheUpdateEvent);
23+
void CheckStatusChangedEvent(CacheUpdateEvent cacheUpdateEvent);
24+
void CheckCurrentBranchChangedEvent(CacheUpdateEvent cacheUpdateEvent);
25+
void CheckCurrentRemoteChangedEvent(CacheUpdateEvent cacheUpdateEvent);
26+
void CheckCurrentBranchAndRemoteChangedEvent(CacheUpdateEvent cacheUpdateEvent);
27+
void CheckLocalBranchListChangedEvent(CacheUpdateEvent cacheUpdateEvent);
28+
void CheckLocksChangedEvent(CacheUpdateEvent cacheUpdateEvent);
29+
void CheckRemoteBranchListChangedEvent(CacheUpdateEvent cacheUpdateEvent);
30+
void CheckLocalAndRemoteBranchListChangedEvent(CacheUpdateEvent cacheUpdateEvent);
31+
2532
/// <summary>
2633
/// Gets the name of the repository.
2734
/// </summary>
@@ -51,20 +58,22 @@ public interface IRepository : IEquatable<IRepository>
5158
/// </summary>
5259
GitBranch? CurrentBranch { get; }
5360
GitStatus CurrentStatus { get; }
54-
IList<GitRemote> Remotes { get; }
55-
IEnumerable<GitBranch> LocalBranches { get; }
56-
IEnumerable<GitBranch> RemoteBranches { get; }
61+
GitRemote[] Remotes { get; }
62+
GitBranch[] LocalBranches { get; }
63+
GitBranch[] RemoteBranches { get; }
5764
IUser User { get; set; }
58-
IList<GitLock> CurrentLocks { get; }
65+
List<GitLock> CurrentLocks { get; }
5966
string CurrentBranchName { get; }
67+
List<GitLogEntry> CurrentLog { get; }
6068

61-
event Action<GitStatus> OnStatusChanged;
62-
event Action<string> OnCurrentBranchChanged;
63-
event Action<string> OnCurrentRemoteChanged;
64-
event Action OnLocalBranchListChanged;
65-
event Action OnCurrentBranchUpdated;
66-
event Action<IEnumerable<GitLock>> OnLocksChanged;
67-
event Action OnRepositoryInfoChanged;
68-
event Action OnRemoteBranchListChanged;
69+
event Action<CacheUpdateEvent> LogChanged;
70+
event Action<CacheUpdateEvent> StatusChanged;
71+
event Action<CacheUpdateEvent> CurrentBranchChanged;
72+
event Action<CacheUpdateEvent> CurrentRemoteChanged;
73+
event Action<CacheUpdateEvent> CurrentBranchAndRemoteChanged;
74+
event Action<CacheUpdateEvent> LocalBranchListChanged;
75+
event Action<CacheUpdateEvent> LocksChanged;
76+
event Action<CacheUpdateEvent> RemoteBranchListChanged;
77+
event Action<CacheUpdateEvent> LocalAndRemoteBranchListChanged;
6978
}
7079
}

0 commit comments

Comments
 (0)