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

Commit 1a65195

Browse files
Refreshing the log cache properly
1 parent b06a737 commit 1a65195

File tree

5 files changed

+41
-23
lines changed

5 files changed

+41
-23
lines changed

src/GitHub.Api/Git/IRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public interface IRepository : IEquatable<IRepository>
6262
event Action<string> OnCurrentBranchChanged;
6363
event Action<string> OnCurrentRemoteChanged;
6464
event Action OnLocalBranchListChanged;
65-
event Action OnLocalBranchChanged;
65+
event Action OnCurrentBranchUpdated;
6666
event Action<IEnumerable<GitLock>> OnLocksChanged;
6767
event Action OnRepositoryInfoChanged;
6868
event Action OnRemoteBranchListChanged;

src/GitHub.Api/Git/Repository.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Repository : IEquatable<Repository>, IRepository
2020
private IRepositoryManager repositoryManager;
2121
public event Action<string> OnCurrentBranchChanged;
2222
public event Action<string> OnCurrentRemoteChanged;
23-
public event Action OnLocalBranchChanged;
23+
public event Action OnCurrentBranchUpdated;
2424
public event Action OnLocalBranchListChanged;
2525
public event Action<IEnumerable<GitLock>> OnLocksChanged;
2626
public event Action OnRemoteBranchListChanged;
@@ -196,8 +196,8 @@ private void RepositoryManager_OnLocalBranchUpdated(string name)
196196
{
197197
if (name == currentBranch?.Name)
198198
{
199-
Logger.Trace("OnLocalBranchChanged: {0}", name);
200-
OnLocalBranchChanged?.Invoke();
199+
Logger.Trace("OnCurrentBranchUpdated: {0}", name);
200+
OnCurrentBranchUpdated?.Invoke();
201201
Refresh();
202202
}
203203
}

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public override void OnEnable()
7474
{
7575
base.OnEnable();
7676
AttachHandlers(Repository);
77-
logHasChanged = true;
77+
CheckLogCache();
7878
}
7979

8080
public override void OnDisable()
@@ -110,6 +110,30 @@ public override void OnGUI()
110110
OnEmbeddedGUI();
111111
}
112112

113+
public void CheckLogCache()
114+
{
115+
string firstItemCommitID = null;
116+
if (history.Any())
117+
{
118+
firstItemCommitID = history.First().CommitID;
119+
}
120+
121+
var cachedList = GitLogCache.Instance.Log;
122+
123+
string firstCachedItemCommitID = null;
124+
if (cachedList.Any())
125+
{
126+
firstCachedItemCommitID = cachedList.First().CommitID;
127+
}
128+
129+
if (firstItemCommitID != firstCachedItemCommitID)
130+
{
131+
Logger.Trace("CommitID {0} != Cached CommitId {1}", firstItemCommitID ?? "[NULL]", firstCachedItemCommitID ?? "[NULL]");
132+
logHasChanged = true;
133+
Redraw();
134+
}
135+
}
136+
113137
private void AttachHandlers(IRepository repository)
114138
{
115139
if (repository == null)

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,6 @@ private void RefreshOnMainThread()
198198
new ActionTask(TaskManager.Token, Refresh) { Affinity = TaskAffinity.UI }.Start();
199199
}
200200

201-
private void Repository_OnCurrentRemoteChanged(string s)
202-
{
203-
UpdateLog();
204-
}
205-
206-
private void Repository_OnCurrentBranchChanged(string s)
207-
{
208-
UpdateLog();
209-
}
210-
211201
private bool MaybeUpdateData(out string repoRemote)
212202
{
213203
repoRemote = null;
@@ -254,15 +244,15 @@ private void AttachHandlers(IRepository repository)
254244
if (repository == null)
255245
return;
256246
repository.OnRepositoryInfoChanged += RefreshOnMainThread;
257-
repository.OnCurrentBranchChanged += Repository_OnCurrentBranchChanged;
258-
repository.OnCurrentRemoteChanged += Repository_OnCurrentRemoteChanged;
247+
repository.OnCurrentBranchUpdated += UpdateLog;
259248
}
260-
249+
261250
private void DetachHandlers(IRepository repository)
262251
{
263252
if (repository == null)
264253
return;
265254
repository.OnRepositoryInfoChanged -= RefreshOnMainThread;
255+
repository.OnCurrentBranchUpdated -= UpdateLog;
266256
}
267257

268258
private void DoHeaderGUI()
@@ -409,18 +399,22 @@ private static SubTab TabButton(SubTab tab, string title, SubTab activeTab)
409399

410400
private void UpdateLog()
411401
{
412-
Logger.Trace("Updating Log");
413-
414402
if (Repository != null)
415403
{
404+
Logger.Trace("Updating Log");
405+
416406
Repository
417407
.Log()
418-
.ThenInUI((success, log) => {
408+
.FinallyInUI((success, exception, log) => {
419409
if (success)
420410
{
421411
Logger.Trace("Updated Log");
422412
GitLogCache.Instance.Log = log;
423-
Redraw();
413+
414+
if (activeTab == SubTab.History)
415+
{
416+
HistoryView.CheckLogCache();
417+
}
424418
}
425419
}).Start();
426420
}

src/tests/TestUtils/Events/IRepositoryListener.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static void AttachListener(this IRepositoryListener listener,
8484
repositoryEvents?.OnRemoteBranchListChanged.Set();
8585
};
8686

87-
repository.OnLocalBranchChanged += () =>
87+
repository.OnCurrentBranchUpdated += () =>
8888
{
8989
logger?.Debug("OnHeadChanged");
9090
listener.OnHeadChanged();

0 commit comments

Comments
 (0)