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

Commit f2ee4ef

Browse files
committed
Fix initialization sequence and cache invalidation on startup
1 parent 24be3ee commit f2ee4ef

File tree

5 files changed

+33
-43
lines changed

5 files changed

+33
-43
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void Run(bool firstRun)
4747
{
4848
Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);
4949

50-
var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();
50+
var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();
5151
if (gitExecutablePath != null && gitExecutablePath.FileExists()) // we have a git path
5252
{
5353
Logger.Trace("Using git install path from settings: {0}", gitExecutablePath);
@@ -57,7 +57,10 @@ public void Run(bool firstRun)
5757
{
5858
Logger.Trace("No git path found in settings");
5959

60-
var initEnvironmentTask = new ActionTask<NPath>(CancellationToken, (b, path) => InitializeEnvironment(path)) { Affinity = TaskAffinity.UI };
60+
var initEnvironmentTask = new ActionTask<NPath>(CancellationToken, (b, path) =>
61+
{
62+
InitializeEnvironment(path);
63+
}) { Affinity = TaskAffinity.UI };
6164
var findExecTask = new FindExecTask("git", CancellationToken)
6265
.FinallyInUI((b, ex, path) => {
6366
if (b && path != null)
@@ -72,8 +75,7 @@ public void Run(bool firstRun)
7275
}
7376
});
7477

75-
var installDetails = new GitInstallDetails(Environment.UserCachePath, true);
76-
var gitInstaller = new GitInstaller(Environment, CancellationToken, installDetails);
78+
var gitInstaller = new GitInstaller(Environment, CancellationToken);
7779

7880
// if successful, continue with environment initialization, otherwise try to find an existing git installation
7981
gitInstaller.SetupGitIfNeeded(initEnvironmentTask, findExecTask);
@@ -171,34 +173,34 @@ protected void SetupMetrics(string unityVersion, bool firstRun)
171173
/// <param name="gitExecutablePath"></param>
172174
private void InitializeEnvironment(NPath gitExecutablePath)
173175
{
174-
var afterGitSetup = new ActionTask(CancellationToken, RestartRepository)
175-
.ThenInUI(InitializeUI);
176-
177176
Environment.GitExecutablePath = gitExecutablePath;
178177
Environment.User.Initialize(GitClient);
179178

179+
var afterGitSetup = new ActionTask(CancellationToken, RestartRepository)
180+
.ThenInUI(InitializeUI);
181+
182+
ITask task = afterGitSetup;
180183
if (Environment.IsWindows)
181184
{
182-
var task = GitClient
183-
.GetConfig("credential.helper", GitConfigSource.Global)
184-
.Then((b, credentialHelper) => {
185-
if (string.IsNullOrEmpty(credentialHelper))
185+
var credHelperTask = GitClient.GetConfig("credential.helper", GitConfigSource.Global);
186+
credHelperTask.OnEnd += (thisTask, credentialHelper, success, exception) =>
187+
{
188+
if (!success || string.IsNullOrEmpty(credentialHelper))
186189
{
187190
Logger.Warning("No Windows CredentialHelper found: Setting to wincred");
188-
throw new ArgumentNullException(nameof(credentialHelper));
191+
thisTask
192+
.Then(GitClient.SetConfig("credential.helper", "wincred", GitConfigSource.Global))
193+
.Then(afterGitSetup);
189194
}
190-
});
191-
// if there's no credential helper, set it before restarting the repository
192-
task.Then(GitClient.SetConfig("credential.helper", "wincred", GitConfigSource.Global), TaskRunOptions.OnFailure)
193-
.Then(afterGitSetup, taskIsTopOfChain: true);
194-
195-
// if there's a credential helper, we're good, restart the repository
196-
task.Then(afterGitSetup, TaskRunOptions.OnSuccess, taskIsTopOfChain: true);
195+
else
196+
thisTask.Then(afterGitSetup);
197+
};
198+
task = credHelperTask;
197199
}
198-
199-
afterGitSetup.Start();
200+
task.Start();
200201
}
201202

203+
202204
private bool disposed = false;
203205
protected virtual void Dispose(bool disposing)
204206
{

src/GitHub.Api/Git/Repository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ private void CacheContainer_OnCacheInvalidated(CacheType cacheType)
298298
break;
299299

300300
case CacheType.RepositoryInfoCache:
301+
repositoryManager?.UpdateRepositoryInfo();
301302
break;
302303

303304
case CacheType.GitStatusEntriesCache:

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public interface IRepositoryManager : IDisposable
4646
IGitConfig Config { get; }
4747
IGitClient GitClient { get; }
4848
bool IsBusy { get; }
49+
void UpdateRepositoryInfo();
4950
}
5051

5152
interface IRepositoryPathConfiguration
@@ -443,7 +444,7 @@ private void SetupWatcher()
443444
private void UpdateHead()
444445
{
445446
Logger.Trace("UpdateHead");
446-
UpdateCurrentBranchAndRemote();
447+
UpdateRepositoryInfo();
447448
UpdateGitLog();
448449
}
449450

@@ -452,7 +453,7 @@ private string GetCurrentHead()
452453
return repositoryPaths.DotGitHead.ReadAllLines().FirstOrDefault();
453454
}
454455

455-
private void UpdateCurrentBranchAndRemote()
456+
public void UpdateRepositoryInfo()
456457
{
457458
ConfigBranch? branch;
458459
ConfigRemote? remote;

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,12 @@ class GitInstaller
8686
private NPath gitLfsArchivePath;
8787

8888
public GitInstaller(IEnvironment environment, CancellationToken cancellationToken,
89-
GitInstallDetails installDetails)
90-
: this(environment, ZipHelper.Instance, cancellationToken, installDetails, null, null)
91-
{}
92-
93-
public GitInstaller(IEnvironment environment, CancellationToken cancellationToken,
94-
GitInstallDetails installDetails, NPath gitArchiveFilePath, NPath gitLfsArchivePath)
95-
: this(environment, ZipHelper.Instance, cancellationToken, installDetails,
96-
gitArchiveFilePath, gitLfsArchivePath)
97-
{}
98-
99-
public GitInstaller(IEnvironment environment, IZipHelper sharpZipLibHelper, CancellationToken cancellationToken,
100-
GitInstallDetails installDetails, NPath gitArchiveFilePath, NPath gitLfsArchivePath)
89+
GitInstallDetails installDetails = null, NPath gitArchiveFilePath = null, NPath gitLfsArchivePath = null)
10190
{
10291
this.environment = environment;
103-
this.sharpZipLibHelper = sharpZipLibHelper;
92+
this.sharpZipLibHelper = ZipHelper.Instance;
10493
this.cancellationToken = cancellationToken;
105-
this.installDetails = installDetails;
94+
this.installDetails = installDetails ?? new GitInstallDetails(environment.UserCachePath, environment.IsWindows);
10695
this.gitArchiveFilePath = gitArchiveFilePath;
10796
this.gitLfsArchivePath = gitLfsArchivePath;
10897
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,10 @@ protected ManagedCacheBase(bool invalidOnFirstRun)
151151
public void ValidateData()
152152
{
153153
var initialized = ValidateInitialized();
154-
if (initialized)
154+
if (!initialized || DateTimeOffset.Now - LastUpdatedAt > DataTimeout)
155155
{
156-
if (DateTimeOffset.Now - LastUpdatedAt > DataTimeout)
157-
{
158-
Logger.Trace("Timeout Invalidation");
159-
InvalidateData();
160-
}
156+
Logger.Trace("Timeout Invalidation");
157+
InvalidateData();
161158
}
162159
}
163160

0 commit comments

Comments
 (0)