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

Removing IsActive from GitBranch #674

Merged
merged 2 commits into from
Apr 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 5 additions & 9 deletions src/GitHub.Api/Cache/CacheInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,16 @@ public interface IConfigRemoteDictionary : IDictionary<string, ConfigRemote>

public interface IBranchCache : IManagedCache
{
GitBranch[] LocalBranches { get; set; }
GitBranch[] RemoteBranches { get; set; }
GitRemote[] Remotes { get; set; }
GitBranch[] LocalBranches { get; }
GitBranch[] RemoteBranches { get; }
GitRemote[] Remotes { get; }

ILocalConfigBranchDictionary LocalConfigBranches { get; }
IRemoteConfigBranchDictionary RemoteConfigBranches { get; }
IConfigRemoteDictionary ConfigRemotes { get; }

void RemoveLocalBranch(string branch);
void AddLocalBranch(string branch);
void AddRemoteBranch(string remote, string branch);
void RemoveRemoteBranch(string remote, string branch);
void SetRemotes(Dictionary<string, ConfigRemote> remoteDictionary, Dictionary<string, Dictionary<string, ConfigBranch>> branchDictionary);
void SetLocals(Dictionary<string, ConfigBranch> branchDictionary);
void SetRemotes(Dictionary<string, ConfigRemote> remoteConfigs, Dictionary<string, Dictionary<string, ConfigBranch>> configBranches, GitRemote[] gitRemotes, GitBranch[] gitBranches);
void SetLocals(Dictionary<string, ConfigBranch> configBranches, GitBranch[] gitBranches);
}

public interface IRepositoryInfoCacheData
Expand Down
11 changes: 3 additions & 8 deletions src/GitHub.Api/Git/GitBranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,20 @@ public struct GitBranch

public string name;
public string tracking;
public bool isActive;

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

this.name = name;
this.tracking = tracking;
this.isActive = active;
}

public override int GetHashCode()
{
int hash = 17;
hash = hash * 23 + (name?.GetHashCode() ?? 0);
hash = hash * 23 + (tracking?.GetHashCode() ?? 0);
hash = hash * 23 + isActive.GetHashCode();
return hash;
}

Expand All @@ -40,8 +37,7 @@ public bool Equals(GitBranch other)
{
return
String.Equals(name, other.name) &&
String.Equals(tracking, other.tracking) &&
isActive == other.isActive;
String.Equals(tracking, other.tracking);
}

public static bool operator ==(GitBranch lhs, GitBranch rhs)
Expand All @@ -65,11 +61,10 @@ public bool Equals(GitBranch other)

public string Name => name;
public string Tracking => tracking;
public bool IsActive => isActive;

public override string ToString()
{
return $"{Name} Tracking? {Tracking} Active? {IsActive}";
return $"{Name} Tracking? {Tracking}";
}
}
}
33 changes: 14 additions & 19 deletions src/GitHub.Api/Git/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,9 @@ private void RepositoryManagerOnCurrentBranchUpdated(ConfigBranch? branch, Confi
name = null;
cloneUrl = null;
cacheContainer.RepositoryInfoCache.UpdateData(data);
var n = Name; // force refresh of the Name and CloneUrl property
// update active state in local branches
cacheContainer.BranchCache.LocalBranches = LocalConfigBranches;
// update tracking state in remote branches
cacheContainer.BranchCache.RemoteBranches = RemoteConfigBranches;

// force refresh of the Name and CloneUrl propertys
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be properties, not "propertys"

var n = Name;
});
}

Expand Down Expand Up @@ -262,21 +260,22 @@ private void RepositoryManagerOnGitLocksUpdated(List<GitLock> gitLocks)
taskManager.RunInUI(() => cacheContainer.GitLocksCache.GitLocks = gitLocks);
}

private void RepositoryManagerOnRemoteBranchesUpdated(Dictionary<string, ConfigRemote> remotes,
Dictionary<string, Dictionary<string, ConfigBranch>> branches)
private void RepositoryManagerOnRemoteBranchesUpdated(Dictionary<string, ConfigRemote> remoteConfigs,
Dictionary<string, Dictionary<string, ConfigBranch>> remoteConfigBranches)
{
taskManager.RunInUI(() => {
cacheContainer.BranchCache.SetRemotes(remotes, branches);
cacheContainer.BranchCache.Remotes = ConfigRemotes;
cacheContainer.BranchCache.RemoteBranches = RemoteConfigBranches;
var gitRemotes = remoteConfigs.Values.Select(GetGitRemote).ToArray();
var gitRemoteBranches = remoteConfigBranches.Values.SelectMany(x => x.Values).Select(GetRemoteGitBranch).ToArray();

cacheContainer.BranchCache.SetRemotes(remoteConfigs, remoteConfigBranches, gitRemotes, gitRemoteBranches);
});
}

private void RepositoryManagerOnLocalBranchesUpdated(Dictionary<string, ConfigBranch> branches)
private void RepositoryManagerOnLocalBranchesUpdated(Dictionary<string, ConfigBranch> localConfigBranchDictionary)
{
taskManager.RunInUI(() => {
cacheContainer.BranchCache.SetLocals(branches);
cacheContainer.BranchCache.LocalBranches = LocalConfigBranches;
var gitLocalBranches = localConfigBranchDictionary.Values.Select(x => GetLocalGitBranch(CurrentBranchName, x)).ToArray();
cacheContainer.BranchCache.SetLocals(localConfigBranchDictionary, gitLocalBranches);
});
}

Expand All @@ -285,7 +284,7 @@ private static GitBranch GetLocalGitBranch(string currentBranchName, ConfigBranc
var branchName = x.Name;
var trackingName = x.IsTracking ? x.Remote.Value.Name + "/" + branchName : "[None]";
var isActive = branchName == currentBranchName;
return new GitBranch(branchName, trackingName, isActive);
return new GitBranch(branchName, trackingName);
}


Expand All @@ -307,7 +306,7 @@ public void Dispose()
}


private static GitBranch GetRemoteGitBranch(ConfigBranch x) => new GitBranch(x.Remote.Value.Name + "/" + x.Name, "[None]", false);
private static GitBranch GetRemoteGitBranch(ConfigBranch x) => new GitBranch(x.Remote.Value.Name + "/" + x.Name, "[None]");
private static GitRemote GetGitRemote(ConfigRemote configRemote) => new GitRemote(configRemote.Name, configRemote.Url);

public GitRemote[] Remotes => cacheContainer.BranchCache.Remotes;
Expand Down Expand Up @@ -373,10 +372,6 @@ public string Name
internal string DebuggerDisplay => String.Format(CultureInfo.InvariantCulture,
"{0} Owner: {1} Name: {2} CloneUrl: {3} LocalPath: {4} Branch: {5} Remote: {6}", GetHashCode(), Owner, Name,
CloneUrl, LocalPath, CurrentBranch, CurrentRemote);

private GitBranch[] RemoteConfigBranches => cacheContainer.BranchCache.RemoteConfigBranches.Values.SelectMany(x => x.Values).Select(GetRemoteGitBranch).ToArray();
private GitRemote[] ConfigRemotes => cacheContainer.BranchCache.ConfigRemotes.Values.Select(GetGitRemote).ToArray();
private GitBranch[] LocalConfigBranches => cacheContainer.BranchCache.LocalConfigBranches.Values.Select(x => GetLocalGitBranch(CurrentBranchName, x)).ToArray();
}

public interface IUser
Expand Down
12 changes: 8 additions & 4 deletions src/GitHub.Api/Git/TreeData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Security.Cryptography.X509Certificates;

namespace GitHub.Unity
{
Expand All @@ -11,19 +12,22 @@ public interface ITreeData
[Serializable]
public struct GitBranchTreeData : ITreeData
{
public static GitBranchTreeData Default = new GitBranchTreeData(Unity.GitBranch.Default);
public static GitBranchTreeData Default = new GitBranchTreeData(Unity.GitBranch.Default, false);

public GitBranch GitBranch;
public bool isActive;

public GitBranchTreeData(GitBranch gitBranch)
public GitBranchTreeData(GitBranch gitBranch, bool isActive)
{
GitBranch = gitBranch;
this.isActive = isActive;
}

public override int GetHashCode()
{
int hash = 17;
hash = hash * 23 + GitBranch.GetHashCode();
hash = hash * 23 + isActive.GetHashCode();
return hash;
}

Expand All @@ -36,7 +40,7 @@ public override bool Equals(object other)

public bool Equals(GitBranchTreeData other)
{
return GitBranch.Equals(other.GitBranch);
return GitBranch.Equals(other.GitBranch) && IsActive == other.IsActive;
}

public static bool operator ==(GitBranchTreeData lhs, GitBranchTreeData rhs)
Expand All @@ -59,7 +63,7 @@ public bool Equals(GitBranchTreeData other)
}

public string Path => GitBranch.Name;
public bool IsActive => GitBranch.IsActive;
public bool IsActive => isActive;
}

[Serializable]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override void LineReceived(string line)
trackingName = proc.ReadChunk('[', ']');
}

var branch = new GitBranch(name, trackingName, active);
var branch = new GitBranch(name, trackingName);

RaiseOnEntry(branch);
}
Expand Down
168 changes: 14 additions & 154 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -480,174 +480,34 @@ sealed class BranchesCache : ManagedCacheBase<BranchesCache>, IBranchCache
public BranchesCache() : base(CacheType.Branches)
{ }

public GitBranch[] LocalBranches
{
get { return localBranches; }
set
{
var now = DateTimeOffset.Now;
var isUpdated = false;

Logger.Trace("Updating: {0} localBranches:{1}", now, value);

var localBranchesIsNull = localBranches == null;
var valueIsNull = value == null;

if (localBranchesIsNull != valueIsNull ||
!localBranchesIsNull && !localBranches.SequenceEqual(value))
{
localBranches = value;
isUpdated = true;
}

SaveData(now, isUpdated);
}
}

public GitBranch[] RemoteBranches
{
get { return remoteBranches; }
set
{
var now = DateTimeOffset.Now;
var isUpdated = false;

Logger.Trace("Updating: {0} remoteBranches:{1}", now, value);

var remoteBranchesIsNull = remoteBranches == null;
var valueIsNull = value == null;

if (remoteBranchesIsNull != valueIsNull ||
!remoteBranchesIsNull && !remoteBranches.SequenceEqual(value))
{
remoteBranches = value;
isUpdated = true;
}

SaveData(now, isUpdated);
}
}

public GitRemote[] Remotes
{
get { return remotes; }
set
{
var now = DateTimeOffset.Now;
var isUpdated = false;

Logger.Trace("Updating: {0} remotes:{1}", now, value);

var remotesIsNull = remotes == null;
var valueIsNull = value == null;

if (remotesIsNull != valueIsNull ||
!remotesIsNull && !remotes.SequenceEqual(value))
{
remotes = value;
isUpdated = true;
}

SaveData(now, isUpdated);
}
}

public void RemoveLocalBranch(string branch)
{
if (LocalConfigBranches.ContainsKey(branch))
{
var now = DateTimeOffset.Now;
LocalConfigBranches.Remove(branch);
Logger.Trace("RemoveLocalBranch {0} branch:{1} ", now, branch);
SaveData(now, true);
}
else
{
Logger.Warning("Branch {0} is not found", branch);
}
}

public void AddLocalBranch(string branch)
{
if (!LocalConfigBranches.ContainsKey(branch))
{
var now = DateTimeOffset.Now;
LocalConfigBranches.Add(branch, new ConfigBranch(branch));
Logger.Trace("AddLocalBranch {0} branch:{1} ", now, branch);
SaveData(now, true);
}
else
{
Logger.Warning("Branch {0} is already present", branch);
}
}

public void AddRemoteBranch(string remote, string branch)
{
Dictionary<string, ConfigBranch> branchList;
if (RemoteConfigBranches.TryGetValue(remote, out branchList))
{
if (!branchList.ContainsKey(branch))
{
var now = DateTimeOffset.Now;
branchList.Add(branch, new ConfigBranch(branch, ConfigRemotes[remote]));
Logger.Trace("AddRemoteBranch {0} remote:{1} branch:{2} ", now, remote, branch);
SaveData(now, true);
}
else
{
Logger.Warning("Branch {0} is already present in Remote {1}", branch, remote);
}
}
else
{
Logger.Warning("Remote {0} is not found", remote);
}
}

public void RemoveRemoteBranch(string remote, string branch)
{
Dictionary<string, ConfigBranch> branchList;
if (RemoteConfigBranches.TryGetValue(remote, out branchList))
{
if (branchList.ContainsKey(branch))
{
var now = DateTimeOffset.Now;
branchList.Remove(branch);
Logger.Trace("RemoveRemoteBranch {0} remote:{1} branch:{2} ", now, remote, branch);
SaveData(now, true);
}
else
{
Logger.Warning("Branch {0} is not found in Remote {1}", branch, remote);
}
}
else
{
Logger.Warning("Remote {0} is not found", remote);
}
}

public void SetRemotes(Dictionary<string, ConfigRemote> remoteDictionary, Dictionary<string, Dictionary<string, ConfigBranch>> branchDictionary)
public void SetRemotes(Dictionary<string, ConfigRemote> remoteConfigs, Dictionary<string, Dictionary<string, ConfigBranch>> configBranches, GitRemote[] gitRemotes, GitBranch[] gitBranches)
{
var now = DateTimeOffset.Now;
configRemotes = new ConfigRemoteDictionary(remoteDictionary);
remoteConfigBranches = new RemoteConfigBranchDictionary(branchDictionary);
configRemotes = new ConfigRemoteDictionary(remoteConfigs);
remoteConfigBranches = new RemoteConfigBranchDictionary(configBranches);
remotes = gitRemotes;
remoteBranches = gitBranches;

Logger.Trace("SetRemotes {0}", now);
SaveData(now, true);
}

public void SetLocals(Dictionary<string, ConfigBranch> branchDictionary)
public void SetLocals(Dictionary<string, ConfigBranch> configBranches, GitBranch[] gitBranches)
{
var now = DateTimeOffset.Now;
localConfigBranches = new LocalConfigBranchDictionary(branchDictionary);
Logger.Trace("SetRemotes {0}", now);
localConfigBranches = new LocalConfigBranchDictionary(configBranches);
localBranches = gitBranches;

Logger.Trace("SetLocals {0}", now);
SaveData(now, true);
}

public ILocalConfigBranchDictionary LocalConfigBranches { get { return localConfigBranches; } }
public IRemoteConfigBranchDictionary RemoteConfigBranches { get { return remoteConfigBranches; } }
public IConfigRemoteDictionary ConfigRemotes { get { return configRemotes; } }
public GitBranch[] LocalBranches { get { return localBranches; } }
public GitBranch[] RemoteBranches { get { return remoteBranches; } }
public GitRemote[] Remotes { get { return remotes; } }
public override TimeSpan DataTimeout { get { return TimeSpan.FromDays(1); } }
}

Expand Down
Loading