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

Commit bddb47d

Browse files
Responding to RepositoryManager events
1 parent a54f8d9 commit bddb47d

File tree

5 files changed

+229
-139
lines changed

5 files changed

+229
-139
lines changed

src/GitHub.Api/Git/Repository.cs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ public void Initialize(IRepositoryManager initRepositoryManager)
4747
Guard.ArgumentNotNull(initRepositoryManager, nameof(initRepositoryManager));
4848

4949
repositoryManager = initRepositoryManager;
50-
repositoryManager.OnCurrentBranchAndRemoteUpdated += RepositoryManager_OnCurrentBranchAndRemoteUpdated;
51-
repositoryManager.OnLocalBranchListUpdated += RepositoryManager_OnLocalBranchListUpdated;
52-
repositoryManager.OnRemoteBranchListUpdated += RepositoryManager_OnRemoteBranchListUpdated;
50+
repositoryManager.CurrentBranchUpdated += RepositoryManagerOnCurrentBranchUpdated;
51+
repositoryManager.GitStatusUpdated += RepositoryManagerOnGitStatusUpdated;
52+
repositoryManager.GitLogUpdated += RepositoryManagerOnGitLogUpdated;
53+
repositoryManager.LocalBranchesUpdated += RepositoryManagerOnLocalBranchesUpdated;
54+
repositoryManager.RemoteBranchesUpdated += RepositoryManagerOnRemoteBranchesUpdated;
5355
}
5456

5557
public ITask SetupRemote(string remote, string remoteUrl)
@@ -343,7 +345,7 @@ private void HandleBranchCacheUpdatedEvent(CacheUpdateEvent cacheUpdateEvent)
343345
LocalAndRemoteBranchListChanged?.Invoke(cacheUpdateEvent);
344346
}
345347

346-
private void RepositoryManager_OnCurrentBranchAndRemoteUpdated(ConfigBranch? branch, ConfigRemote? remote)
348+
private void RepositoryManagerOnCurrentBranchUpdated(ConfigBranch? branch, ConfigRemote? remote)
347349
{
348350
new ActionTask(CancellationToken.None, () => {
349351
if (!Nullable.Equals(CurrentConfigBranch, branch))
@@ -364,23 +366,31 @@ private void RepositoryManager_OnCurrentBranchAndRemoteUpdated(ConfigBranch? bra
364366
}) { Affinity = TaskAffinity.UI }.Start();
365367
}
366368

367-
private void RepositoryManager_OnRemoteBranchListUpdated(Dictionary<string, ConfigRemote> remotes,
368-
Dictionary<string, Dictionary<string, ConfigBranch>> branches)
369+
private void RepositoryManagerOnGitStatusUpdated(GitStatus gitStatus)
369370
{
370371
new ActionTask(CancellationToken.None, () => {
371-
cacheContainer.BranchCache.SetRemotes(remotes, branches);
372-
UpdateRemoteAndRemoteBranches();
372+
CurrentStatus = gitStatus;
373373
}) { Affinity = TaskAffinity.UI }.Start();
374374
}
375375

376-
private void UpdateRemoteAndRemoteBranches()
376+
private void RepositoryManagerOnGitLogUpdated(List<GitLogEntry> gitLogEntries)
377377
{
378-
Remotes = ConfigRemotes.Values.Select(GetGitRemote).ToArray();
378+
new ActionTask(CancellationToken.None, () => {
379+
CurrentLog = gitLogEntries;
380+
}) { Affinity = TaskAffinity.UI }.Start();
381+
}
379382

380-
RemoteBranches = RemoteConfigBranches.Values.SelectMany(x => x.Values).Select(GetRemoteGitBranch).ToArray();
383+
private void RepositoryManagerOnRemoteBranchesUpdated(Dictionary<string, ConfigRemote> remotes,
384+
Dictionary<string, Dictionary<string, ConfigBranch>> branches)
385+
{
386+
new ActionTask(CancellationToken.None, () => {
387+
cacheContainer.BranchCache.SetRemotes(remotes, branches);
388+
Remotes = ConfigRemotes.Values.Select(GetGitRemote).ToArray();
389+
RemoteBranches = RemoteConfigBranches.Values.SelectMany(x => x.Values).Select(GetRemoteGitBranch).ToArray();
390+
}) { Affinity = TaskAffinity.UI }.Start();
381391
}
382392

383-
private void RepositoryManager_OnLocalBranchListUpdated(Dictionary<string, ConfigBranch> branches)
393+
private void RepositoryManagerOnLocalBranchesUpdated(Dictionary<string, ConfigBranch> branches)
384394
{
385395
new ActionTask(CancellationToken.None, () => {
386396
cacheContainer.BranchCache.SetLocals(branches);

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ namespace GitHub.Unity
77
{
88
public interface IRepositoryManager : IDisposable
99
{
10-
event Action<ConfigBranch?, ConfigRemote?> OnCurrentBranchAndRemoteUpdated;
11-
event Action<bool> OnIsBusyChanged;
10+
event Action<bool> IsBusyChanged;
11+
event Action<ConfigBranch?, ConfigRemote?> CurrentBranchUpdated;
1212
event Action<GitStatus> GitStatusUpdated;
1313
event Action<List<GitLogEntry>> GitLogUpdated;
14-
event Action<Dictionary<string, ConfigBranch>> OnLocalBranchListUpdated;
15-
event Action<Dictionary<string, ConfigRemote>, Dictionary<string, Dictionary<string, ConfigBranch>>> OnRemoteBranchListUpdated;
14+
event Action<Dictionary<string, ConfigBranch>> LocalBranchesUpdated;
15+
event Action<Dictionary<string, ConfigRemote>, Dictionary<string, Dictionary<string, ConfigBranch>>> RemoteBranchesUpdated;
1616

1717
void Initialize();
1818
void Start();
@@ -96,12 +96,12 @@ class RepositoryManager : IRepositoryManager
9696

9797
private bool isBusy;
9898

99-
public event Action<ConfigBranch?, ConfigRemote?> OnCurrentBranchAndRemoteUpdated;
100-
public event Action<bool> OnIsBusyChanged;
99+
public event Action<ConfigBranch?, ConfigRemote?> CurrentBranchUpdated;
100+
public event Action<bool> IsBusyChanged;
101101
public event Action<GitStatus> GitStatusUpdated;
102102
public event Action<List<GitLogEntry>> GitLogUpdated;
103-
public event Action<Dictionary<string, ConfigBranch>> OnLocalBranchListUpdated;
104-
public event Action<Dictionary<string, ConfigRemote>, Dictionary<string, Dictionary<string, ConfigBranch>>> OnRemoteBranchListUpdated;
103+
public event Action<Dictionary<string, ConfigBranch>> LocalBranchesUpdated;
104+
public event Action<Dictionary<string, ConfigRemote>, Dictionary<string, Dictionary<string, ConfigBranch>>> RemoteBranchesUpdated;
105105

106106
public RepositoryManager(IPlatform platform, IGitConfig gitConfig,
107107
IRepositoryWatcher repositoryWatcher, IGitClient gitClient,
@@ -342,7 +342,7 @@ private void UpdateCurrentBranchAndRemote(string head)
342342

343343
Logger.Trace("CurrentBranch: {0}", branch.HasValue ? branch.Value.ToString() : "[NULL]");
344344
Logger.Trace("CurrentRemote: {0}", remote.HasValue ? remote.Value.ToString() : "[NULL]");
345-
OnCurrentBranchAndRemoteUpdated?.Invoke(branch, remote);
345+
CurrentBranchUpdated?.Invoke(branch, remote);
346346
}
347347

348348
private ITask HookupHandlers(ITask task, bool disableWatcher = false)
@@ -456,7 +456,7 @@ private void UpdateLocalBranches()
456456
UpdateLocalBranches(branches, repositoryPaths.BranchesPath, config.GetBranches().Where(x => x.IsTracking), "");
457457

458458
Logger.Trace("OnLocalBranchListUpdated {0} branches", branches.Count);
459-
OnLocalBranchListUpdated?.Invoke(branches);
459+
LocalBranchesUpdated?.Invoke(branches);
460460
}
461461

462462
private void UpdateLocalBranches(Dictionary<string, ConfigBranch> branches, NPath path, IEnumerable<ConfigBranch> configBranches, string prefix)
@@ -505,7 +505,7 @@ private void UpdateRemoteBranches()
505505
}
506506

507507
Logger.Trace("OnRemoteBranchListUpdated {0} remotes", remotes.Count);
508-
OnRemoteBranchListUpdated?.Invoke(remotes, remoteBranches);
508+
RemoteBranchesUpdated?.Invoke(remotes, remoteBranches);
509509
}
510510

511511
private bool disposed;
@@ -541,7 +541,7 @@ private set
541541
{
542542
Logger.Trace("IsBusyChanged Value:{0}", value);
543543
isBusy = value;
544-
OnIsBusyChanged?.Invoke(isBusy);
544+
IsBusyChanged?.Invoke(isBusy);
545545
}
546546
}
547547
}

0 commit comments

Comments
 (0)