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

Commit 2ba86f2

Browse files
Removing IsActive from GitBranch
- Removing unused functions in BranchCache - Consolidating means to update BranchCache - Removing IsActive from GitBranch - Changing BranchesView to use RepositoryInfoCache in addition to BranchCache for it's display
1 parent 977b32e commit 2ba86f2

File tree

10 files changed

+93
-211
lines changed

10 files changed

+93
-211
lines changed

src/GitHub.Api/Cache/CacheInterfaces.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,16 @@ public interface IConfigRemoteDictionary : IDictionary<string, ConfigRemote>
8484

8585
public interface IBranchCache : IManagedCache
8686
{
87-
GitBranch[] LocalBranches { get; set; }
88-
GitBranch[] RemoteBranches { get; set; }
89-
GitRemote[] Remotes { get; set; }
87+
GitBranch[] LocalBranches { get; }
88+
GitBranch[] RemoteBranches { get; }
89+
GitRemote[] Remotes { get; }
9090

9191
ILocalConfigBranchDictionary LocalConfigBranches { get; }
9292
IRemoteConfigBranchDictionary RemoteConfigBranches { get; }
9393
IConfigRemoteDictionary ConfigRemotes { get; }
9494

95-
void RemoveLocalBranch(string branch);
96-
void AddLocalBranch(string branch);
97-
void AddRemoteBranch(string remote, string branch);
98-
void RemoveRemoteBranch(string remote, string branch);
99-
void SetRemotes(Dictionary<string, ConfigRemote> remoteDictionary, Dictionary<string, Dictionary<string, ConfigBranch>> branchDictionary);
100-
void SetLocals(Dictionary<string, ConfigBranch> branchDictionary);
95+
void SetRemotes(Dictionary<string, ConfigRemote> remoteConfigs, Dictionary<string, Dictionary<string, ConfigBranch>> configBranches, GitRemote[] gitRemotes, GitBranch[] gitBranches);
96+
void SetLocals(Dictionary<string, ConfigBranch> configBranches, GitBranch[] gitBranches);
10197
}
10298

10399
public interface IRepositoryInfoCacheData

src/GitHub.Api/Git/GitBranch.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,20 @@ public struct GitBranch
99

1010
public string name;
1111
public string tracking;
12-
public bool isActive;
1312

14-
public GitBranch(string name, string tracking, bool active)
13+
public GitBranch(string name, string tracking)
1514
{
1615
Guard.ArgumentNotNullOrWhiteSpace(name, "name");
1716

1817
this.name = name;
1918
this.tracking = tracking;
20-
this.isActive = active;
2119
}
2220

2321
public override int GetHashCode()
2422
{
2523
int hash = 17;
2624
hash = hash * 23 + (name?.GetHashCode() ?? 0);
2725
hash = hash * 23 + (tracking?.GetHashCode() ?? 0);
28-
hash = hash * 23 + isActive.GetHashCode();
2926
return hash;
3027
}
3128

@@ -40,8 +37,7 @@ public bool Equals(GitBranch other)
4037
{
4138
return
4239
String.Equals(name, other.name) &&
43-
String.Equals(tracking, other.tracking) &&
44-
isActive == other.isActive;
40+
String.Equals(tracking, other.tracking);
4541
}
4642

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

6662
public string Name => name;
6763
public string Tracking => tracking;
68-
public bool IsActive => isActive;
6964

7065
public override string ToString()
7166
{
72-
return $"{Name} Tracking? {Tracking} Active? {IsActive}";
67+
return $"{Name} Tracking? {Tracking}";
7368
}
7469
}
7570
}

src/GitHub.Api/Git/Repository.cs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,9 @@ private void RepositoryManagerOnCurrentBranchUpdated(ConfigBranch? branch, Confi
225225
name = null;
226226
cloneUrl = null;
227227
cacheContainer.RepositoryInfoCache.UpdateData(data);
228-
var n = Name; // force refresh of the Name and CloneUrl property
229-
// update active state in local branches
230-
cacheContainer.BranchCache.LocalBranches = LocalConfigBranches;
231-
// update tracking state in remote branches
232-
cacheContainer.BranchCache.RemoteBranches = RemoteConfigBranches;
228+
229+
// force refresh of the Name and CloneUrl propertys
230+
var n = Name;
233231
});
234232
}
235233

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

265-
private void RepositoryManagerOnRemoteBranchesUpdated(Dictionary<string, ConfigRemote> remotes,
266-
Dictionary<string, Dictionary<string, ConfigBranch>> branches)
263+
private void RepositoryManagerOnRemoteBranchesUpdated(Dictionary<string, ConfigRemote> remoteConfigs,
264+
Dictionary<string, Dictionary<string, ConfigBranch>> remoteConfigBranches)
267265
{
268266
taskManager.RunInUI(() => {
269-
cacheContainer.BranchCache.SetRemotes(remotes, branches);
270-
cacheContainer.BranchCache.Remotes = ConfigRemotes;
271-
cacheContainer.BranchCache.RemoteBranches = RemoteConfigBranches;
267+
var gitRemotes = remoteConfigs.Values.Select(GetGitRemote).ToArray();
268+
var gitRemoteBranches = remoteConfigBranches.Values.SelectMany(x => x.Values).Select(GetRemoteGitBranch).ToArray();
269+
270+
cacheContainer.BranchCache.SetRemotes(remoteConfigs, remoteConfigBranches, gitRemotes, gitRemoteBranches);
272271
});
273272
}
274273

275-
private void RepositoryManagerOnLocalBranchesUpdated(Dictionary<string, ConfigBranch> branches)
274+
private void RepositoryManagerOnLocalBranchesUpdated(Dictionary<string, ConfigBranch> localConfigBranchDictionary)
276275
{
277276
taskManager.RunInUI(() => {
278-
cacheContainer.BranchCache.SetLocals(branches);
279-
cacheContainer.BranchCache.LocalBranches = LocalConfigBranches;
277+
var gitLocalBranches = localConfigBranchDictionary.Values.Select(x => GetLocalGitBranch(CurrentBranchName, x)).ToArray();
278+
cacheContainer.BranchCache.SetLocals(localConfigBranchDictionary, gitLocalBranches);
280279
});
281280
}
282281

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

291290

@@ -307,7 +306,7 @@ public void Dispose()
307306
}
308307

309308

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

313312
public GitRemote[] Remotes => cacheContainer.BranchCache.Remotes;
@@ -373,10 +372,6 @@ public string Name
373372
internal string DebuggerDisplay => String.Format(CultureInfo.InvariantCulture,
374373
"{0} Owner: {1} Name: {2} CloneUrl: {3} LocalPath: {4} Branch: {5} Remote: {6}", GetHashCode(), Owner, Name,
375374
CloneUrl, LocalPath, CurrentBranch, CurrentRemote);
376-
377-
private GitBranch[] RemoteConfigBranches => cacheContainer.BranchCache.RemoteConfigBranches.Values.SelectMany(x => x.Values).Select(GetRemoteGitBranch).ToArray();
378-
private GitRemote[] ConfigRemotes => cacheContainer.BranchCache.ConfigRemotes.Values.Select(GetGitRemote).ToArray();
379-
private GitBranch[] LocalConfigBranches => cacheContainer.BranchCache.LocalConfigBranches.Values.Select(x => GetLocalGitBranch(CurrentBranchName, x)).ToArray();
380375
}
381376

382377
public interface IUser

src/GitHub.Api/Git/TreeData.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Security.Cryptography.X509Certificates;
23

34
namespace GitHub.Unity
45
{
@@ -11,19 +12,22 @@ public interface ITreeData
1112
[Serializable]
1213
public struct GitBranchTreeData : ITreeData
1314
{
14-
public static GitBranchTreeData Default = new GitBranchTreeData(Unity.GitBranch.Default);
15+
public static GitBranchTreeData Default = new GitBranchTreeData(Unity.GitBranch.Default, false);
1516

1617
public GitBranch GitBranch;
18+
public bool isActive;
1719

18-
public GitBranchTreeData(GitBranch gitBranch)
20+
public GitBranchTreeData(GitBranch gitBranch, bool isActive)
1921
{
2022
GitBranch = gitBranch;
23+
this.isActive = isActive;
2124
}
2225

2326
public override int GetHashCode()
2427
{
2528
int hash = 17;
2629
hash = hash * 23 + GitBranch.GetHashCode();
30+
hash = hash * 23 + isActive.GetHashCode();
2731
return hash;
2832
}
2933

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

3741
public bool Equals(GitBranchTreeData other)
3842
{
39-
return GitBranch.Equals(other.GitBranch);
43+
return GitBranch.Equals(other.GitBranch) && IsActive == other.IsActive;
4044
}
4145

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

6165
public string Path => GitBranch.Name;
62-
public bool IsActive => GitBranch.IsActive;
66+
public bool IsActive => isActive;
6367
}
6468

6569
[Serializable]

src/GitHub.Api/OutputProcessors/BranchListOutputProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public override void LineReceived(string line)
3636
trackingName = proc.ReadChunk('[', ']');
3737
}
3838

39-
var branch = new GitBranch(name, trackingName, active);
39+
var branch = new GitBranch(name, trackingName);
4040

4141
RaiseOnEntry(branch);
4242
}

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

Lines changed: 14 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -480,174 +480,34 @@ sealed class BranchesCache : ManagedCacheBase<BranchesCache>, IBranchCache
480480
public BranchesCache() : base(CacheType.Branches)
481481
{ }
482482

483-
public GitBranch[] LocalBranches
484-
{
485-
get { return localBranches; }
486-
set
487-
{
488-
var now = DateTimeOffset.Now;
489-
var isUpdated = false;
490-
491-
Logger.Trace("Updating: {0} localBranches:{1}", now, value);
492-
493-
var localBranchesIsNull = localBranches == null;
494-
var valueIsNull = value == null;
495-
496-
if (localBranchesIsNull != valueIsNull ||
497-
!localBranchesIsNull && !localBranches.SequenceEqual(value))
498-
{
499-
localBranches = value;
500-
isUpdated = true;
501-
}
502-
503-
SaveData(now, isUpdated);
504-
}
505-
}
506-
507-
public GitBranch[] RemoteBranches
508-
{
509-
get { return remoteBranches; }
510-
set
511-
{
512-
var now = DateTimeOffset.Now;
513-
var isUpdated = false;
514-
515-
Logger.Trace("Updating: {0} remoteBranches:{1}", now, value);
516-
517-
var remoteBranchesIsNull = remoteBranches == null;
518-
var valueIsNull = value == null;
519-
520-
if (remoteBranchesIsNull != valueIsNull ||
521-
!remoteBranchesIsNull && !remoteBranches.SequenceEqual(value))
522-
{
523-
remoteBranches = value;
524-
isUpdated = true;
525-
}
526-
527-
SaveData(now, isUpdated);
528-
}
529-
}
530-
531-
public GitRemote[] Remotes
532-
{
533-
get { return remotes; }
534-
set
535-
{
536-
var now = DateTimeOffset.Now;
537-
var isUpdated = false;
538-
539-
Logger.Trace("Updating: {0} remotes:{1}", now, value);
540-
541-
var remotesIsNull = remotes == null;
542-
var valueIsNull = value == null;
543-
544-
if (remotesIsNull != valueIsNull ||
545-
!remotesIsNull && !remotes.SequenceEqual(value))
546-
{
547-
remotes = value;
548-
isUpdated = true;
549-
}
550-
551-
SaveData(now, isUpdated);
552-
}
553-
}
554-
555-
public void RemoveLocalBranch(string branch)
556-
{
557-
if (LocalConfigBranches.ContainsKey(branch))
558-
{
559-
var now = DateTimeOffset.Now;
560-
LocalConfigBranches.Remove(branch);
561-
Logger.Trace("RemoveLocalBranch {0} branch:{1} ", now, branch);
562-
SaveData(now, true);
563-
}
564-
else
565-
{
566-
Logger.Warning("Branch {0} is not found", branch);
567-
}
568-
}
569-
570-
public void AddLocalBranch(string branch)
571-
{
572-
if (!LocalConfigBranches.ContainsKey(branch))
573-
{
574-
var now = DateTimeOffset.Now;
575-
LocalConfigBranches.Add(branch, new ConfigBranch(branch));
576-
Logger.Trace("AddLocalBranch {0} branch:{1} ", now, branch);
577-
SaveData(now, true);
578-
}
579-
else
580-
{
581-
Logger.Warning("Branch {0} is already present", branch);
582-
}
583-
}
584-
585-
public void AddRemoteBranch(string remote, string branch)
586-
{
587-
Dictionary<string, ConfigBranch> branchList;
588-
if (RemoteConfigBranches.TryGetValue(remote, out branchList))
589-
{
590-
if (!branchList.ContainsKey(branch))
591-
{
592-
var now = DateTimeOffset.Now;
593-
branchList.Add(branch, new ConfigBranch(branch, ConfigRemotes[remote]));
594-
Logger.Trace("AddRemoteBranch {0} remote:{1} branch:{2} ", now, remote, branch);
595-
SaveData(now, true);
596-
}
597-
else
598-
{
599-
Logger.Warning("Branch {0} is already present in Remote {1}", branch, remote);
600-
}
601-
}
602-
else
603-
{
604-
Logger.Warning("Remote {0} is not found", remote);
605-
}
606-
}
607-
608-
public void RemoveRemoteBranch(string remote, string branch)
609-
{
610-
Dictionary<string, ConfigBranch> branchList;
611-
if (RemoteConfigBranches.TryGetValue(remote, out branchList))
612-
{
613-
if (branchList.ContainsKey(branch))
614-
{
615-
var now = DateTimeOffset.Now;
616-
branchList.Remove(branch);
617-
Logger.Trace("RemoveRemoteBranch {0} remote:{1} branch:{2} ", now, remote, branch);
618-
SaveData(now, true);
619-
}
620-
else
621-
{
622-
Logger.Warning("Branch {0} is not found in Remote {1}", branch, remote);
623-
}
624-
}
625-
else
626-
{
627-
Logger.Warning("Remote {0} is not found", remote);
628-
}
629-
}
630-
631-
public void SetRemotes(Dictionary<string, ConfigRemote> remoteDictionary, Dictionary<string, Dictionary<string, ConfigBranch>> branchDictionary)
483+
public void SetRemotes(Dictionary<string, ConfigRemote> remoteConfigs, Dictionary<string, Dictionary<string, ConfigBranch>> configBranches, GitRemote[] gitRemotes, GitBranch[] gitBranches)
632484
{
633485
var now = DateTimeOffset.Now;
634-
configRemotes = new ConfigRemoteDictionary(remoteDictionary);
635-
remoteConfigBranches = new RemoteConfigBranchDictionary(branchDictionary);
486+
configRemotes = new ConfigRemoteDictionary(remoteConfigs);
487+
remoteConfigBranches = new RemoteConfigBranchDictionary(configBranches);
488+
remotes = gitRemotes;
489+
remoteBranches = gitBranches;
490+
636491
Logger.Trace("SetRemotes {0}", now);
637492
SaveData(now, true);
638493
}
639494

640-
public void SetLocals(Dictionary<string, ConfigBranch> branchDictionary)
495+
public void SetLocals(Dictionary<string, ConfigBranch> configBranches, GitBranch[] gitBranches)
641496
{
642497
var now = DateTimeOffset.Now;
643-
localConfigBranches = new LocalConfigBranchDictionary(branchDictionary);
644-
Logger.Trace("SetRemotes {0}", now);
498+
localConfigBranches = new LocalConfigBranchDictionary(configBranches);
499+
localBranches = gitBranches;
500+
501+
Logger.Trace("SetLocals {0}", now);
645502
SaveData(now, true);
646503
}
647504

648505
public ILocalConfigBranchDictionary LocalConfigBranches { get { return localConfigBranches; } }
649506
public IRemoteConfigBranchDictionary RemoteConfigBranches { get { return remoteConfigBranches; } }
650507
public IConfigRemoteDictionary ConfigRemotes { get { return configRemotes; } }
508+
public GitBranch[] LocalBranches { get { return localBranches; } }
509+
public GitBranch[] RemoteBranches { get { return remoteBranches; } }
510+
public GitRemote[] Remotes { get { return remotes; } }
651511
public override TimeSpan DataTimeout { get { return TimeSpan.FromDays(1); } }
652512
}
653513

0 commit comments

Comments
 (0)