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

Commit 1b0456b

Browse files
authored
Merge pull request #561 from github-for-unity/enhancements/async-git-setup-rollup
Async git setup rollup
2 parents 155aa37 + 3bf5020 commit 1b0456b

File tree

100 files changed

+2444
-811
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2444
-811
lines changed

GitHub.Unity.sln

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TaskSystem", "src\tests\Tas
2727
EndProject
2828
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp", "src\tests\TestApp\TestApp.csproj", "{08B87D2A-8CF1-4211-B7AA-5209F00F72F8}"
2929
EndProject
30+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestWebServer", "src\tests\TestWebServer\TestWebServer.csproj", "{3DD3451C-30FA-4294-A3A9-1E080342F867}"
31+
EndProject
3032
Global
3133
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3234
Debug|Any CPU = Debug|Any CPU
@@ -94,6 +96,12 @@ Global
9496
{08B87D2A-8CF1-4211-B7AA-5209F00F72F8}.dev|Any CPU.Build.0 = Debug|Any CPU
9597
{08B87D2A-8CF1-4211-B7AA-5209F00F72F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
9698
{08B87D2A-8CF1-4211-B7AA-5209F00F72F8}.Release|Any CPU.Build.0 = Release|Any CPU
99+
{3DD3451C-30FA-4294-A3A9-1E080342F867}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
100+
{3DD3451C-30FA-4294-A3A9-1E080342F867}.Debug|Any CPU.Build.0 = Debug|Any CPU
101+
{3DD3451C-30FA-4294-A3A9-1E080342F867}.dev|Any CPU.ActiveCfg = Debug|Any CPU
102+
{3DD3451C-30FA-4294-A3A9-1E080342F867}.dev|Any CPU.Build.0 = Debug|Any CPU
103+
{3DD3451C-30FA-4294-A3A9-1E080342F867}.Release|Any CPU.ActiveCfg = Release|Any CPU
104+
{3DD3451C-30FA-4294-A3A9-1E080342F867}.Release|Any CPU.Build.0 = Release|Any CPU
97105
EndGlobalSection
98106
GlobalSection(SolutionProperties) = preSolution
99107
HideSolutionNode = FALSE
@@ -106,5 +114,6 @@ Global
106114
{66A1D219-F61D-4AE4-9BD7-AAEB97276FFF} = {D17F1B4C-42DC-4E78-BCEF-9F239A084C4D}
107115
{1A382F40-FD9E-43E1-89C1-320073F35CE9} = {D17F1B4C-42DC-4E78-BCEF-9F239A084C4D}
108116
{08B87D2A-8CF1-4211-B7AA-5209F00F72F8} = {D17F1B4C-42DC-4E78-BCEF-9F239A084C4D}
117+
{3DD3451C-30FA-4294-A3A9-1E080342F867} = {D17F1B4C-42DC-4E78-BCEF-9F239A084C4D}
109118
EndGlobalSection
110119
EndGlobal

GitHub.Unity.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@
335335
</TypePattern>
336336
&lt;/Patterns&gt;</s:String>
337337
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ID/@EntryIndexedValue">ID</s:String>
338+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MD/@EntryIndexedValue">MD</s:String>
338339
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SSH/@EntryIndexedValue">SSH</s:String>
339340
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
340341
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>

script

src/GitHub.Api/Application/ApiClient.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55
using Octokit;
6+
using GitHub.Logging;
67
using System.Runtime.Serialization;
78

89
namespace GitHub.Unity
@@ -17,10 +18,10 @@ public static IApiClient Create(UriString repositoryUrl, IKeychain keychain)
1718
var hostAddress = HostAddress.Create(repositoryUrl);
1819

1920
return new ApiClient(repositoryUrl, keychain,
20-
new GitHubClient(AppConfiguration.ProductHeader, credentialStore, hostAddress.ApiUri));
21+
new GitHubClient(ApplicationConfiguration.ProductHeader, credentialStore, hostAddress.ApiUri));
2122
}
2223

23-
private static readonly ILogging logger = Logging.GetLogger<ApiClient>();
24+
private static readonly ILogging logger = LogHelper.GetLogger<ApiClient>();
2425
public HostAddress HostAddress { get; }
2526
public UriString OriginalUrl { get; }
2627

src/GitHub.Api/Application/AppConfiguration.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Reflection;
2+
using Octokit;
3+
4+
namespace GitHub.Unity
5+
{
6+
public static class ApplicationConfiguration
7+
{
8+
public const int DefaultWebTimeout = 3000;
9+
10+
static ApplicationConfiguration()
11+
{
12+
var executingAssembly = typeof(ApplicationConfiguration).Assembly;
13+
AssemblyName = executingAssembly.GetName();
14+
ProductHeader = new ProductHeaderValue(ApplicationInfo.ApplicationSafeName, AssemblyName.Version.ToString());
15+
}
16+
17+
/// <summary>
18+
/// The currently executing assembly.
19+
/// </summary>
20+
public static AssemblyName AssemblyName { get; }
21+
22+
/// <summary>
23+
/// The product header used in the user agent.
24+
/// </summary>
25+
public static ProductHeaderValue ProductHeader { get; private set; }
26+
27+
public static int WebTimeout { get; set; } = DefaultWebTimeout;
28+
}
29+
}

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 73 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
using System.Linq;
33
using System.Threading;
44
using System.Threading.Tasks;
5-
using Octokit;
65
using System.Collections.Generic;
6+
using GitHub.Logging;
77

88
namespace GitHub.Unity
99
{
1010
abstract class ApplicationManagerBase : IApplicationManager
1111
{
12-
protected static ILogging Logger { get; } = Logging.GetLogger<IApplicationManager>();
12+
protected static ILogging Logger { get; } = LogHelper.GetLogger<IApplicationManager>();
1313

1414
private RepositoryManager repositoryManager;
1515

@@ -36,49 +36,49 @@ protected void Initialize()
3636
LocalSettings.Initialize();
3737
SystemSettings.Initialize();
3838

39-
Logging.TracingEnabled = UserSettings.Get(Constants.TraceLoggingKey, false);
39+
LogHelper.TracingEnabled = UserSettings.Get(Constants.TraceLoggingKey, false);
4040
ProcessManager = new ProcessManager(Environment, Platform.GitEnvironment, CancellationToken);
4141
Platform.Initialize(ProcessManager, TaskManager);
42-
GitClient = new GitClient(Environment, ProcessManager, TaskManager);
42+
GitClient = new GitClient(Environment, ProcessManager, TaskManager.Token);
4343
SetupMetrics();
4444
}
4545

4646
public void Run(bool firstRun)
47-
{
48-
new ActionTask(SetupGit())
49-
.Then(RestartRepository)
50-
.ThenInUI(InitializeUI)
51-
.Start();
52-
}
53-
54-
private async Task SetupGit()
5547
{
5648
Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);
5749

58-
if (Environment.GitExecutablePath == null)
50+
var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();
51+
if (gitExecutablePath != null && gitExecutablePath.FileExists()) // we have a git path
5952
{
60-
Environment.GitExecutablePath = await DetermineGitExecutablePath();
61-
62-
Logger.Trace("Environment.GitExecutablePath \"{0}\" Exists:{1}", Environment.GitExecutablePath, Environment.GitExecutablePath.FileExists());
63-
64-
if (Environment.IsWindows)
65-
{
66-
var credentialHelper = await GitClient.GetConfig("credential.helper", GitConfigSource.Global).StartAwait();
67-
68-
if (!string.IsNullOrEmpty(credentialHelper))
69-
{
70-
Logger.Trace("Windows CredentialHelper: {0}", credentialHelper);
71-
}
72-
else
73-
{
74-
Logger.Warning("No Windows CredentialHeloper found: Setting to wincred");
75-
76-
await GitClient.SetConfig("credential.helper", "wincred", GitConfigSource.Global).StartAwait();
77-
}
78-
}
53+
Logger.Trace("Using git install path from settings: {0}", gitExecutablePath);
54+
InitializeEnvironment(gitExecutablePath);
55+
}
56+
else // we need to go find git
57+
{
58+
Logger.Trace("No git path found in settings");
59+
60+
var initEnvironmentTask = new ActionTask<NPath>(CancellationToken, (b, path) => InitializeEnvironment(path)) { Affinity = TaskAffinity.UI };
61+
var findExecTask = new FindExecTask("git", CancellationToken)
62+
.FinallyInUI((b, ex, path) => {
63+
if (b && path != null)
64+
{
65+
Logger.Trace("FindExecTask Success: {0}", path);
66+
InitializeEnvironment(gitExecutablePath);
67+
}
68+
else
69+
{
70+
Logger.Warning("FindExecTask Failure");
71+
Logger.Error("Git not found");
72+
}
73+
});
74+
75+
var applicationDataPath = Environment.GetSpecialFolder(System.Environment.SpecialFolder.LocalApplicationData).ToNPath();
76+
var installDetails = new GitInstallDetails(applicationDataPath, true);
77+
var gitInstaller = new GitInstaller(Environment, CancellationToken, installDetails);
78+
79+
// if successful, continue with environment initialization, otherwise try to find an existing git installation
80+
gitInstaller.SetupGitIfNeeded(initEnvironmentTask, findExecTask);
7981
}
80-
81-
Environment.User.Initialize(GitClient);
8282
}
8383

8484
public ITask InitializeRepository()
@@ -136,27 +136,6 @@ public void RestartRepository()
136136
}
137137
}
138138

139-
private async Task<NPath> DetermineGitExecutablePath(ProgressReport progress = null)
140-
{
141-
var gitExecutablePath = SystemSettings.Get(Constants.GitInstallPathKey)?.ToNPath();
142-
if (gitExecutablePath != null && gitExecutablePath.FileExists())
143-
{
144-
Logger.Trace("Using git install path from settings");
145-
return gitExecutablePath;
146-
}
147-
148-
var gitInstaller = new GitInstaller(Environment, CancellationToken);
149-
var setupDone = await gitInstaller.SetupIfNeeded(progress?.Percentage, progress?.Remaining);
150-
if (setupDone)
151-
{
152-
Logger.Trace("Setup performed using new path");
153-
return gitInstaller.GitExecutablePath;
154-
}
155-
156-
Logger.Trace("Finding git install path");
157-
return await GitClient.FindGitInstallation().SafeAwait();
158-
}
159-
160139
protected void SetupMetrics(string unityVersion, bool firstRun)
161140
{
162141
Logger.Trace("Setup metrics");
@@ -187,6 +166,45 @@ protected void SetupMetrics(string unityVersion, bool firstRun)
187166
protected abstract void InitializeUI();
188167
protected abstract void SetProjectToTextSerialization();
189168

169+
/// <summary>
170+
/// Initialize environment after finding where git is. This needs to run on the main thread
171+
/// </summary>
172+
/// <param name="gitExecutablePath"></param>
173+
private void InitializeEnvironment(NPath gitExecutablePath)
174+
{
175+
var afterGitSetup = new ActionTask(CancellationToken, RestartRepository)
176+
.ThenInUI(InitializeUI);
177+
178+
Environment.GitExecutablePath = gitExecutablePath;
179+
Environment.User.Initialize(GitClient);
180+
181+
if (Environment.IsWindows)
182+
{
183+
GitClient
184+
.GetConfig("credential.helper", GitConfigSource.Global)
185+
.Then((b, credentialHelper) => {
186+
if (!string.IsNullOrEmpty(credentialHelper))
187+
{
188+
Logger.Trace("Windows CredentialHelper: {0}", credentialHelper);
189+
afterGitSetup.Start();
190+
}
191+
else
192+
{
193+
Logger.Warning("No Windows CredentialHeloper found: Setting to wincred");
194+
195+
GitClient.SetConfig("credential.helper", "wincred", GitConfigSource.Global)
196+
.Then(afterGitSetup)
197+
.Start();
198+
}
199+
})
200+
.Start();
201+
}
202+
else
203+
{
204+
afterGitSetup.Start();
205+
}
206+
}
207+
190208
private bool disposed = false;
191209
protected virtual void Dispose(bool disposing)
192210
{

src/GitHub.Api/Authentication/Keychain.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55
using Octokit;
6+
using GitHub.Logging;
67

78
namespace GitHub.Unity
89
{
@@ -64,7 +65,7 @@ class Keychain : IKeychain
6465
{
6566
const string ConnectionFile = "connections.json";
6667

67-
private readonly ILogging logger = Logging.GetLogger<Keychain>();
68+
private readonly ILogging logger = LogHelper.GetLogger<Keychain>();
6869

6970
private readonly ICredentialManager credentialManager;
7071
private readonly NPath cachePath;

src/GitHub.Api/Authentication/LoginManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Net;
33
using System.Threading.Tasks;
44
using Octokit;
5+
using GitHub.Logging;
56

67
namespace GitHub.Unity
78
{
@@ -19,7 +20,7 @@ public enum LoginResultCodes
1920
/// </summary>
2021
class LoginManager : ILoginManager
2122
{
22-
private readonly ILogging logger = Logging.GetLogger<LoginManager>();
23+
private readonly ILogging logger = LogHelper.GetLogger<LoginManager>();
2324

2425
private readonly string[] scopes = { "user", "repo", "gist", "write:public_key" };
2526
private readonly IKeychain keychain;

src/GitHub.Api/Events/RepositoryWatcher.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66
using sfw.net;
7+
using GitHub.Logging;
78

89
namespace GitHub.Unity
910
{
@@ -293,7 +294,7 @@ public void Dispose()
293294
Dispose(true);
294295
}
295296

296-
protected static ILogging Logger { get; } = Logging.GetLogger<RepositoryWatcher>();
297+
protected static ILogging Logger { get; } = LogHelper.GetLogger<RepositoryWatcher>();
297298

298299
private enum EventType
299300
{

0 commit comments

Comments
 (0)