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

Commit 447fd9c

Browse files
committed
Replay any cache invalidation requests that happen before RepositoryManager is set
1 parent a850584 commit 447fd9c

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public void RestartRepository()
150150
repositoryManager.Initialize();
151151
Environment.Repository.Initialize(repositoryManager);
152152
repositoryManager.Start();
153+
Environment.Repository.Start();
153154
Logger.Trace($"Got a repository? {Environment.Repository}");
154155
}
155156
}

src/GitHub.Api/Git/IRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,6 @@ public interface IRepository : IEquatable<IRepository>
7878
event Action<CacheUpdateEvent> LocksChanged;
7979
event Action<CacheUpdateEvent> RemoteBranchListChanged;
8080
event Action<CacheUpdateEvent> LocalAndRemoteBranchListChanged;
81+
void Start();
8182
}
8283
}

src/GitHub.Api/Git/Repository.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Repository : IEquatable<Repository>, IRepository
1515
private ICacheContainer cacheContainer;
1616
private UriString cloneUrl;
1717
private string name;
18+
private HashSet<CacheType> cacheInvalidationRequests = new HashSet<CacheType>();
1819

1920
public event Action<CacheUpdateEvent> LogChanged;
2021
public event Action<CacheUpdateEvent> TrackingStatusChanged;
@@ -39,7 +40,7 @@ public Repository(NPath localPath, ICacheContainer container)
3940
LocalPath = localPath;
4041

4142
cacheContainer = container;
42-
cacheContainer.CacheInvalidated += CacheContainer_OnCacheInvalidated;
43+
cacheContainer.CacheInvalidated += InvalidateCache;
4344
cacheContainer.CacheUpdated += CacheContainer_OnCacheUpdated;
4445
}
4546

@@ -58,6 +59,14 @@ public void Initialize(IRepositoryManager initRepositoryManager)
5859
repositoryManager.RemoteBranchesUpdated += RepositoryManagerOnRemoteBranchesUpdated;
5960
}
6061

62+
public void Start()
63+
{
64+
foreach (var req in cacheInvalidationRequests)
65+
{
66+
InvalidateCache(req);
67+
}
68+
}
69+
6170
public ITask SetupRemote(string remote, string remoteUrl)
6271
{
6372
Guard.ArgumentNotNullOrWhiteSpace(remote, "remote");
@@ -275,8 +284,16 @@ private void CheckBranchCacheEvent(CacheUpdateEvent cacheUpdateEvent)
275284
}
276285
}
277286

278-
private void CacheContainer_OnCacheInvalidated(CacheType cacheType)
287+
private void InvalidateCache(CacheType cacheType)
279288
{
289+
if (repositoryManager == null)
290+
{
291+
if (!cacheInvalidationRequests.Contains(cacheType))
292+
cacheInvalidationRequests.Add(cacheType);
293+
return;
294+
}
295+
296+
280297
switch (cacheType)
281298
{
282299
case CacheType.BranchCache:

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public interface IRepositoryManager : IDisposable
4242
void UpdateGitAheadBehindStatus();
4343
void UpdateLocks();
4444
int WaitForEvents();
45+
void UpdateRepositoryInfo();
4546

4647
IGitConfig Config { get; }
4748
IGitClient GitClient { get; }
4849
bool IsBusy { get; }
49-
void UpdateRepositoryInfo();
5050
}
5151

5252
interface IRepositoryPathConfiguration
@@ -400,7 +400,7 @@ private ITask HookupHandlers(ITask task, bool filesystemChangesExpected)
400400
var isExclusive = task.IsChainExclusive();
401401
task.GetTopOfChain().OnStart += t =>
402402
{
403-
if (t.Affinity == TaskAffinity.Exclusive)
403+
if (isExclusive)
404404
{
405405
Logger.Trace("Starting Operation - Setting Busy Flag");
406406
IsBusy = true;

0 commit comments

Comments
 (0)