Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
fd1165f
A cache manager
shana Sep 19, 2017
896dae9
Merge branch 'master' into features/cache-manager
StanleyGoldman Oct 20, 2017
f55b9d8
Updating branch cache on branch change
StanleyGoldman Oct 20, 2017
289038d
Initializing BranchCache
StanleyGoldman Oct 20, 2017
91f919d
Migrating GitLogCache to CacheManager
StanleyGoldman Oct 20, 2017
f0083d9
Adding some logging for sanity
StanleyGoldman Oct 20, 2017
f8c951e
Unintentional class move
StanleyGoldman Oct 20, 2017
fcf8667
Undoing more unintentional change
StanleyGoldman Oct 20, 2017
0fd147a
Adding cache managers and making use of the RepositoryInfoCacheManage…
StanleyGoldman Oct 25, 2017
55038c9
Increasing timeout
StanleyGoldman Oct 25, 2017
b3fafd8
Firing events on the main thread
StanleyGoldman Oct 25, 2017
360851a
Figuring out a base class sytem that works for these cache objects
StanleyGoldman Oct 25, 2017
748c126
Using this new base class
StanleyGoldman Oct 26, 2017
f00b333
Removing more test cache code
StanleyGoldman Oct 26, 2017
952a142
Removing last instance of that test cache object
StanleyGoldman Oct 26, 2017
7f4428e
Setting default value on lastUpdated and lastVerified values
StanleyGoldman Oct 26, 2017
ffd2f1b
Renaming some variables
StanleyGoldman Oct 26, 2017
89936f7
Merge branch 'fixes/application-cache-double-call' into features/cach…
StanleyGoldman Oct 26, 2017
76aa8a9
Merge branch 'master' into features/cache-manager
StanleyGoldman Oct 26, 2017
144da6c
Moving where CacheContainer is created and how it gets into Repository
StanleyGoldman Oct 26, 2017
9eea8a6
Changing how the cache items are created
StanleyGoldman Oct 26, 2017
181ca0a
Missing save in base class
StanleyGoldman Oct 26, 2017
41b105f
Renaming file
StanleyGoldman Oct 26, 2017
1b7862b
Changing the struct GitBranch to use a default constructor and fields
StanleyGoldman Oct 27, 2017
e2d1c7f
Merge branch 'fixes/oh-my-struct-constructor' into features/cache-man…
StanleyGoldman Oct 27, 2017
14a1a83
Using default values for structs correctly
StanleyGoldman Oct 27, 2017
86530ac
Removing reset during invalidation
StanleyGoldman Oct 27, 2017
5e1879a
Kneecapping data timeout
StanleyGoldman Oct 27, 2017
08c566d
Disabling RepositoryManagerTests
StanleyGoldman Oct 27, 2017
a20de1e
Disabling RepositoryTests as well
StanleyGoldman Oct 27, 2017
51d37b3
Removing log from CacheContainer constructor
StanleyGoldman Oct 27, 2017
fcb9481
Removing unused logger
StanleyGoldman Oct 27, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/GitHub.Api/Application/ApplicationManagerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public ITask InitializeRepository()
.Then(GitClient.Commit("Initial commit", null))
.Then(_ =>
{
Environment.InitializeRepository();
Environment.InitializeRepository(CacheContainer);
RestartRepository();
})
.ThenInUI(InitializeUI);
Expand Down Expand Up @@ -214,6 +214,7 @@ public void Dispose()
public ISettings LocalSettings { get; protected set; }
public ISettings SystemSettings { get; protected set; }
public ISettings UserSettings { get; protected set; }
public ICacheContainer CacheContainer { get; protected set; }
public IUsageTracker UsageTracker { get; protected set; }

protected TaskScheduler UIScheduler { get; private set; }
Expand Down
1 change: 1 addition & 0 deletions src/GitHub.Api/Application/IApplicationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public interface IApplicationManager : IDisposable
ISettings LocalSettings { get; }
ISettings UserSettings { get; }
ITaskManager TaskManager { get; }
ICacheContainer CacheContainer { get; }
IGitClient GitClient { get; }
IUsageTracker UsageTracker { get; }

Expand Down
98 changes: 98 additions & 0 deletions src/GitHub.Api/Cache/CacheInterfaces.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;

namespace GitHub.Unity
{
public enum CacheType
{
BranchCache,
GitLogCache,
RepositoryInfoCache,
GitStatusCache,
GitLocksCache,
GitUserCache
}

public interface ICacheContainer
{
event Action<CacheType> CacheInvalidated;
event Action<CacheType, DateTimeOffset> CacheUpdated;

IBranchCache BranchCache { get; }
IGitLogCache GitLogCache { get; }
IRepositoryInfoCache RepositoryInfoCache { get; }
IGitStatusCache GitStatusCache { get; }
IGitLocksCache GitLocksCache { get; }
IGitUserCache GitUserCache { get; }
void Validate(CacheType cacheType);
void ValidateAll();
void Invalidate(CacheType cacheType);
void InvalidateAll();
}

public interface IManagedCache
{
event Action CacheInvalidated;
event Action<DateTimeOffset> CacheUpdated;

void ValidateData();
void InvalidateData();

DateTimeOffset LastUpdatedAt { get; }
DateTimeOffset LastVerifiedAt { get; }
}

public interface IGitLocks
{
List<GitLock> GitLocks { get; }
}

public interface IGitLocksCache : IManagedCache, IGitLocks
{ }

public interface IGitUser
{
User User { get; }
}

public interface ITestCacheItem
{ }

public interface IGitUserCache : IManagedCache, IGitUser
{ }

public interface IGitStatus
{
GitStatus GitStatus { get; }
}

public interface IGitStatusCache : IManagedCache, IGitStatus
{ }

public interface IRepositoryInfo
{
ConfigRemote? CurrentConfigRemote { get; set; }
ConfigBranch? CurentConfigBranch { get; set; }
}

public interface IRepositoryInfoCache : IManagedCache, IRepositoryInfo
{
GitRemote? CurrentGitRemote { get; set; }
GitBranch? CurentGitBranch { get; set; }
}

public interface IBranch
{
void UpdateData(List<GitBranch> localBranchUpdate, List<GitBranch> remoteBranchUpdate);
List<GitBranch> LocalBranches { get; }
List<GitBranch> RemoteBranches { get; }
}

public interface IBranchCache : IManagedCache, IBranch
{ }

public interface IGitLogCache : IManagedCache
{
List<GitLogEntry> Log { get; }
}
}
10 changes: 0 additions & 10 deletions src/GitHub.Api/Cache/IBranchCache.cs

This file was deleted.

26 changes: 4 additions & 22 deletions src/GitHub.Api/Git/GitBranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,12 @@

namespace GitHub.Unity
{
interface ITreeData
{
string Name { get; }
bool IsActive { get; }
}

[Serializable]
public struct GitBranch : ITreeData
public struct GitBranch
{
private string name;
private string tracking;
private bool active;
public string Name { get { return name; } }
public string Tracking { get { return tracking; } }
public bool IsActive { get { return active; } }

public GitBranch(string name, string tracking, bool active)
{
Guard.ArgumentNotNullOrWhiteSpace(name, "name");

this.name = name;
this.tracking = tracking;
this.active = active;
}
public string Name;
public string Tracking;
public bool IsActive;

public override string ToString()
{
Expand Down
4 changes: 2 additions & 2 deletions src/GitHub.Api/Git/GitLogEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public string PrettyTimeString
}
}

[NonSerialized] public DateTimeOffset? timeValue;
[NonSerialized] private DateTimeOffset? timeValue;
public DateTimeOffset Time
{
get
Expand All @@ -56,7 +56,7 @@ public DateTimeOffset Time
}
}

[NonSerialized] public DateTimeOffset? commitTimeValue;
[NonSerialized] private DateTimeOffset? commitTimeValue;
public DateTimeOffset? CommitTime
{
get
Expand Down
90 changes: 50 additions & 40 deletions src/GitHub.Api/Git/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ namespace GitHub.Unity
[DebuggerDisplay("{DebuggerDisplay,nq}")]
class Repository : IEquatable<Repository>, IRepository
{
private ConfigBranch? currentBranch;
private IList<GitLock> currentLocks;
private ConfigRemote? currentRemote;
private GitStatus currentStatus;
private Dictionary<string, ConfigBranch> localBranches = new Dictionary<string, ConfigBranch>();
private Dictionary<string, Dictionary<string, ConfigBranch>> remoteBranches = new Dictionary<string, Dictionary<string, ConfigBranch>>();
private Dictionary<string, ConfigRemote> remotes;
private IRepositoryManager repositoryManager;
private ICacheContainer cacheContainer;
public event Action<string> OnCurrentBranchChanged;
public event Action<string> OnCurrentRemoteChanged;
public event Action OnCurrentBranchUpdated;
Expand All @@ -33,22 +32,24 @@ class Repository : IEquatable<Repository>, IRepository
/// </summary>
/// <param name="name">The repository name.</param>
/// <param name="localPath"></param>
public Repository(string name, NPath localPath)
/// <param name="container"></param>
public Repository(string name, NPath localPath, ICacheContainer container)
{
Guard.ArgumentNotNullOrWhiteSpace(name, nameof(name));
Guard.ArgumentNotNull(localPath, nameof(localPath));

Name = name;
LocalPath = localPath;
this.User = new User();
User = new User();

cacheContainer = container;
}

public void Initialize(IRepositoryManager repositoryManager)
public void Initialize(IRepositoryManager initRepositoryManager)
{
Guard.ArgumentNotNull(repositoryManager, nameof(repositoryManager));

this.repositoryManager = repositoryManager;
Guard.ArgumentNotNull(initRepositoryManager, nameof(initRepositoryManager));

repositoryManager = initRepositoryManager;
repositoryManager.OnCurrentBranchUpdated += RepositoryManager_OnCurrentBranchUpdated;
repositoryManager.OnCurrentRemoteUpdated += RepositoryManager_OnCurrentRemoteUpdated;
repositoryManager.OnStatusUpdated += status => CurrentStatus = status;
Expand Down Expand Up @@ -170,31 +171,31 @@ public bool Equals(IRepository other)

private void RepositoryManager_OnCurrentRemoteUpdated(ConfigRemote? remote)
{
if (!Nullable.Equals(currentRemote, remote))
if (!Nullable.Equals(CurrentConfigRemote, remote))
{
currentRemote = remote;
CurrentConfigRemote = remote;

Logger.Trace("OnCurrentRemoteChanged: {0}", currentRemote.HasValue ? currentRemote.Value.ToString() : "[NULL]");
OnCurrentRemoteChanged?.Invoke(currentRemote.HasValue ? currentRemote.Value.Name : null);
Logger.Trace("OnCurrentRemoteChanged: {0}", remote.HasValue ? remote.Value.ToString() : "[NULL]");
OnCurrentRemoteChanged?.Invoke(remote.HasValue ? remote.Value.Name : null);

UpdateRepositoryInfo();
}
}

private void RepositoryManager_OnCurrentBranchUpdated(ConfigBranch? branch)
{
if (!Nullable.Equals(currentBranch, branch))
if (!Nullable.Equals(CurrentConfigBranch, branch))
{
currentBranch = branch;
CurrentConfigBranch = branch;

Logger.Trace("OnCurrentBranchChanged: {0}", currentBranch.HasValue ? currentBranch.ToString() : "[NULL]");
OnCurrentBranchChanged?.Invoke(currentBranch.HasValue ? currentBranch.Value.Name : null);
Logger.Trace("OnCurrentBranchChanged: {0}", branch.HasValue ? branch.ToString() : "[NULL]");
OnCurrentBranchChanged?.Invoke(branch.HasValue ? branch.Value.Name : null);
}
}

private void RepositoryManager_OnLocalBranchUpdated(string name)
{
if (name == currentBranch?.Name)
if (name == CurrentConfigBranch?.Name)
{
Logger.Trace("OnCurrentBranchUpdated: {0}", name);
OnCurrentBranchUpdated?.Invoke();
Expand Down Expand Up @@ -325,17 +326,25 @@ private GitBranch GetLocalGitBranch(ConfigBranch x)
{
var name = x.Name;
var trackingName = x.IsTracking ? x.Remote.Value.Name + "/" + name : "[None]";
var isActive = name == currentBranch?.Name;
var isActive = name == CurrentConfigBranch?.Name;

return new GitBranch(name, trackingName, isActive);
return new GitBranch {
Name = name,
Tracking = trackingName,
IsActive = isActive
};
}

private GitBranch GetRemoteGitBranch(ConfigBranch x)
{
var name = x.Remote.Value.Name + "/" + x.Name;
var trackingName = "[None]";

return new GitBranch(name, trackingName, false);
return new GitBranch {
Name = name,
Tracking = trackingName,
IsActive = false
};
}

private GitRemote GetGitRemote(ConfigRemote configRemote)
Expand All @@ -349,34 +358,35 @@ private GitRemote GetGitRemote(ConfigRemote configRemote)

public IEnumerable<GitBranch> RemoteBranches => remoteBranches.Values.SelectMany(x => x.Values).Select(GetRemoteGitBranch);

public GitBranch? CurrentBranch
private ConfigBranch? CurrentConfigBranch
{
get
get { return this.cacheContainer.RepositoryInfoCache.CurentConfigBranch; }
set
{
if (currentBranch != null)
{
return GetLocalGitBranch(currentBranch.Value);
}

return null;
cacheContainer.RepositoryInfoCache.CurentConfigBranch = value;
cacheContainer.RepositoryInfoCache.CurentGitBranch = value != null
? (GitBranch?)GetLocalGitBranch(value.Value)
: null;
}
}

public string CurrentBranchName => currentBranch?.Name;

public GitRemote? CurrentRemote
private ConfigRemote? CurrentConfigRemote
{
get
{
if (currentRemote != null)
{
return GetGitRemote(currentRemote.Value);
}

return null;
get { return this.cacheContainer.RepositoryInfoCache.CurrentConfigRemote; }
set {
cacheContainer.RepositoryInfoCache.CurrentConfigRemote = value;
cacheContainer.RepositoryInfoCache.CurrentGitRemote = value != null
? (GitRemote?) GetGitRemote(value.Value)
: null;
}
}

public GitBranch? CurrentBranch => cacheContainer.RepositoryInfoCache.CurentGitBranch;

public string CurrentBranchName => CurrentConfigBranch?.Name;

public GitRemote? CurrentRemote => cacheContainer.RepositoryInfoCache.CurrentGitRemote;

public UriString CloneUrl { get; private set; }

public string Name { get; private set; }
Expand Down Expand Up @@ -432,7 +442,7 @@ public interface IUser
}

[Serializable]
class User : IUser
public class User : IUser
{
public override string ToString()
{
Expand Down
13 changes: 9 additions & 4 deletions src/GitHub.Api/Git/RepositoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,16 @@ private void UpdateCurrentBranchAndRemote(string head)
}
}

Logger.Trace("OnCurrentBranchUpdated: {0}", branch.HasValue ? branch.Value.ToString() : "[NULL]");
OnCurrentBranchUpdated?.Invoke(branch);
new ActionTask(taskManager.Token, () => {
Logger.Trace("OnCurrentBranchUpdated: {0}", branch.HasValue ? branch.Value.ToString() : "[NULL]");
OnCurrentBranchUpdated?.Invoke(branch);

Logger.Trace("OnCurrentRemoteUpdated: {0}", remote.HasValue ? remote.Value.ToString() : "[NULL]");
OnCurrentRemoteUpdated?.Invoke(remote);
Logger.Trace("OnCurrentRemoteUpdated: {0}", remote.HasValue ? remote.Value.ToString() : "[NULL]");
OnCurrentRemoteUpdated?.Invoke(remote);
})
{
Affinity = TaskAffinity.UI
}.Start();
}

private void Watcher_OnIndexChanged()
Expand Down
Loading