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

Commit 4ff2a3c

Browse files
committed
Merge master into enhancements/showing-diffs
2 parents 68d700e + 862f680 commit 4ff2a3c

Some content is hidden

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

57 files changed

+1594
-845
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ You can reach the team right here by opening a [new issue](https://github.com/gi
66

77
[![Build Status](https://ci.appveyor.com/api/projects/status/github/github-for-unity/Unity?branch=master&svg=true)](https://ci.appveyor.com/project/github-windows/unity)
88

9-
[![Join the chat at https://gitter.im/github-for-unity/Unity](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/github-for-unity/Unity?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
109
[![Join the chat at https://discord.gg/5zH8hVx](https://img.shields.io/badge/discord-join%20chat-7289DA.svg)](https://discord.gg/5zH8hVx)
1110
[![GitHub for Unity live coding on Twitch](https://img.shields.io/badge/twitch-live%20coding-6441A4.svg)](https://www.twitch.tv/sh4na)
1211

script

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ abstract class ApplicationManagerBase : IApplicationManager
1616
private Progress progress = new Progress(TaskBase.Default);
1717
protected bool isBusy;
1818
private bool firstRun;
19-
protected bool FirstRun { get { return firstRun; } set { firstRun = value; } }
19+
protected bool FirstRun { get { return firstRun; } set { firstRun = value; } }
2020
private Guid instanceId;
2121
protected Guid InstanceId { get { return instanceId; } set { instanceId = value; } }
2222

@@ -47,7 +47,7 @@ protected void Initialize()
4747
ApplicationConfiguration.WebTimeout = UserSettings.Get(Constants.WebTimeoutKey, ApplicationConfiguration.WebTimeout);
4848
Platform.Initialize(ProcessManager, TaskManager);
4949
progress.OnProgress += progressReporter.UpdateProgress;
50-
UsageTracker = new UsageTracker(UserSettings, Environment, InstanceId.ToString());
50+
UsageTracker = new UsageTracker(TaskManager, UserSettings, Environment, InstanceId.ToString());
5151

5252
#if ENABLE_METRICS
5353
var metricsService = new MetricsService(ProcessManager,
@@ -64,18 +64,22 @@ public void Run()
6464
isBusy = true;
6565
progress.UpdateProgress(0, 100, "Initializing...");
6666

67+
if (firstRun)
68+
{
69+
UsageTracker.IncrementNumberOfStartups();
70+
}
71+
6772
var thread = new Thread(() =>
6873
{
6974
GitInstallationState state = new GitInstallationState();
7075
try
7176
{
72-
SetupMetrics();
7377
if (Environment.IsMac)
7478
{
7579
var getEnvPath = new SimpleProcessTask(TaskManager.Token, "bash".ToNPath(), "-c \"/usr/libexec/path_helper\"")
7680
.Configure(ProcessManager, dontSetupGit: true)
7781
.Catch(e => true); // make sure this doesn't throw if the task fails
78-
var path = getEnvPath.RunWithReturn(true);
82+
var path = getEnvPath.RunSynchronously();
7983
if (getEnvPath.Successful)
8084
{
8185
Logger.Trace("Existing Environment Path Original:{0} Updated:{1}", Environment.Path, path);
@@ -187,14 +191,15 @@ public void SetupGit(GitInstaller.GitInstallationState state)
187191
if (Environment.RepositoryPath.IsInitialized)
188192
{
189193
ConfigureMergeSettings();
194+
CaptureRepoSize();
190195

191196
GitClient.LfsInstall()
192197
.Catch(e =>
193198
{
194199
Logger.Error(e, "Error running lfs install");
195200
return true;
196201
})
197-
.RunWithReturn(true);
202+
.RunSynchronously();
198203
}
199204

200205
if (Environment.IsWindows)
@@ -204,7 +209,7 @@ public void SetupGit(GitInstaller.GitInstallationState state)
204209
{
205210
Logger.Error(e, "Error getting the credential helper");
206211
return true;
207-
}).RunWithReturn(true);
212+
}).RunSynchronously();
208213

209214
if (string.IsNullOrEmpty(credentialHelper))
210215
{
@@ -215,7 +220,7 @@ public void SetupGit(GitInstaller.GitInstallationState state)
215220
Logger.Error(e, "Error setting the credential helper");
216221
return true;
217222
})
218-
.RunWithReturn(true);
223+
.RunSynchronously();
219224
}
220225
}
221226
}
@@ -238,24 +243,23 @@ public void InitializeRepository()
238243

239244
var filesForInitialCommit = new List<string> { gitignore, gitAttrs, assetsGitignore };
240245

241-
GitClient.Init().RunWithReturn(true);
246+
GitClient.Init().RunSynchronously();
242247
progress.UpdateProgress(10, 100, "Initializing...");
243248

244249
ConfigureMergeSettings();
245250
progress.UpdateProgress(20, 100, "Initializing...");
246251

247-
GitClient.LfsInstall().RunWithReturn(true);
252+
GitClient.LfsInstall().RunSynchronously();
248253
progress.UpdateProgress(30, 100, "Initializing...");
249254

250255
AssemblyResources.ToFile(ResourceType.Generic, ".gitignore", targetPath, Environment);
251256
AssemblyResources.ToFile(ResourceType.Generic, ".gitattributes", targetPath, Environment);
252257
assetsGitignore.CreateFile();
253-
GitClient.Add(filesForInitialCommit).RunWithReturn(true);
258+
GitClient.Add(filesForInitialCommit).RunSynchronously();
254259
progress.UpdateProgress(60, 100, "Initializing...");
255-
GitClient.Commit("Initial commit", null).RunWithReturn(true);
260+
GitClient.Commit("Initial commit", null).RunSynchronously();
256261
progress.UpdateProgress(70, 100, "Initializing...");
257262
Environment.InitializeRepository();
258-
UsageTracker.IncrementProjectsInitialized();
259263
}
260264
catch (Exception ex)
261265
{
@@ -269,6 +273,7 @@ public void InitializeRepository()
269273
progress.UpdateProgress(90, 100, "Initializing...");
270274
RestartRepository();
271275
TaskManager.RunInUI(InitializeUI);
276+
UsageTracker.IncrementProjectsInitialized();
272277
progress.UpdateProgress(100, 100, "Initialized");
273278
}
274279
isBusy = false;
@@ -287,12 +292,43 @@ private void ConfigureMergeSettings()
287292
GitClient.SetConfig("merge.unityyamlmerge.cmd", yamlMergeCommand, GitConfigSource.Local).Catch(e => {
288293
Logger.Error(e, "Error setting merge.unityyamlmerge.cmd");
289294
return true;
290-
}).RunWithReturn(true);
295+
}).RunSynchronously();
291296

292297
GitClient.SetConfig("merge.unityyamlmerge.trustExitCode", "false", GitConfigSource.Local).Catch(e => {
293298
Logger.Error(e, "Error setting merge.unityyamlmerge.trustExitCode");
294299
return true;
295-
}).RunWithReturn(true);
300+
}).RunSynchronously();
301+
}
302+
303+
private void CaptureRepoSize()
304+
{
305+
GitClient.CountObjects()
306+
.Finally((success, gitObjects) =>
307+
{
308+
if (success)
309+
{
310+
UsageTracker.UpdateRepoSize(gitObjects.kilobytes);
311+
}
312+
})
313+
.Start();
314+
315+
var gitLfsDataPath = Environment.RepositoryPath.Combine(".git", "lfs");
316+
if (gitLfsDataPath.Exists())
317+
{
318+
var diskUsageTask = Environment.IsWindows
319+
? (IProcessTask<int>)new WindowsDiskUsageTask(gitLfsDataPath, TaskManager.Token)
320+
: new LinuxDiskUsageTask(gitLfsDataPath, TaskManager.Token);
321+
322+
diskUsageTask
323+
.Configure(ProcessManager)
324+
.Finally((success, kilobytes) =>
325+
{
326+
if (success)
327+
{
328+
UsageTracker.UpdateLfsDiskUsage(kilobytes);
329+
}
330+
}).Start();
331+
}
296332
}
297333

298334
public void RestartRepository()
@@ -310,14 +346,6 @@ public void RestartRepository()
310346
Logger.Trace($"Got a repository? {(Environment.Repository != null ? Environment.Repository.LocalPath : "null")}");
311347
}
312348

313-
protected void SetupMetrics()
314-
{
315-
if (firstRun)
316-
{
317-
UsageTracker.IncrementNumberOfStartups();
318-
}
319-
}
320-
321349
protected abstract void InitializeUI();
322350
protected abstract void InitializationComplete();
323351

src/GitHub.Api/Authentication/LoginManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public ITask Logout(UriString hostAddress)
138138
{
139139
Guard.ArgumentNotNull(hostAddress, nameof(hostAddress));
140140

141-
return new ActionTask(keychain.Clear(hostAddress, true)) { Message = "Signing out" }.Start();
141+
return new TPLTask(keychain.Clear(hostAddress, true)) { Message = "Signing out" }.Start();
142142
}
143143

144144
private async Task<LoginResultData> TryLogin(

src/GitHub.Api/Git/GitClient.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public interface IGitClient
3838
ITask<List<GitLogEntry>> Log(BaseOutputListProcessor<GitLogEntry> processor = null);
3939
ITask<TheVersion> Version(IOutputProcessor<TheVersion> processor = null);
4040
ITask<TheVersion> LfsVersion(IOutputProcessor<TheVersion> processor = null);
41+
ITask<GitCountObjects> CountObjects(IOutputProcessor<GitCountObjects> processor = null);
4142
ITask<GitUser> SetConfigNameAndEmail(string username, string email);
4243
ITask<string> GetHead(IOutputProcessor<string> processor = null);
4344
}
@@ -99,6 +100,12 @@ public ITask<TheVersion> LfsVersion(IOutputProcessor<TheVersion> processor = nul
99100
.Configure(processManager);
100101
}
101102

103+
public ITask<GitCountObjects> CountObjects(IOutputProcessor<GitCountObjects> processor = null)
104+
{
105+
return new GitCountObjectsTask(cancellationToken, processor)
106+
.Configure(processManager);
107+
}
108+
102109
public ITask<string> GetConfig(string key, GitConfigSource configSource, IOutputProcessor<string> processor = null)
103110
{
104111
return new GitConfigGetTask(key, configSource, cancellationToken, processor)

src/GitHub.Api/Git/GitCountObjects.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
3+
namespace GitHub.Unity
4+
{
5+
[Serializable]
6+
public struct GitCountObjects
7+
{
8+
public static GitCountObjects Default = new GitCountObjects();
9+
10+
public int objects;
11+
public int kilobytes;
12+
13+
public GitCountObjects(int objects, int kilobytes)
14+
{
15+
this.objects = objects;
16+
this.kilobytes = kilobytes;
17+
}
18+
19+
public int Objects => objects;
20+
21+
public int Kilobytes => kilobytes;
22+
}
23+
}

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ public ITask UpdateRepositoryInfo()
394394
ConfigBranch? branch;
395395
ConfigRemote? remote;
396396
GetCurrentBranchAndRemote(out branch, out remote);
397-
var currentHead = GitClient.GetHead().RunWithReturn(true);
397+
var currentHead = GitClient.GetHead().RunSynchronously();
398398
CurrentBranchUpdated?.Invoke(branch, remote, currentHead);
399399
})
400400
{ Message = "Updating repository info..." };
@@ -461,7 +461,7 @@ private ITask HookupHandlers(ITask task, bool filesystemChangesExpected)
461461
}
462462
};
463463

464-
task.Finally(success =>
464+
task.OnEnd += (_, __, ___) =>
465465
{
466466
if (filesystemChangesExpected)
467467
{
@@ -474,6 +474,21 @@ private ITask HookupHandlers(ITask task, bool filesystemChangesExpected)
474474
//Logger.Trace("Ended Operation - Clearing Busy Flag");
475475
IsBusy = false;
476476
}
477+
};
478+
task.Catch(_ =>
479+
{
480+
if (filesystemChangesExpected)
481+
{
482+
//Logger.Trace("Ended Operation - Enable Watcher");
483+
watcher.Start();
484+
}
485+
486+
if (isExclusive)
487+
{
488+
//Logger.Trace("Ended Operation - Clearing Busy Flag");
489+
IsBusy = false;
490+
}
491+
477492
});
478493
return task;
479494
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Threading;
2+
3+
namespace GitHub.Unity
4+
{
5+
class GitCountObjectsTask : ProcessTask<GitCountObjects>
6+
{
7+
private const string TaskName = "git count-objects";
8+
9+
public GitCountObjectsTask(CancellationToken token, IOutputProcessor<GitCountObjects> processor = null)
10+
: base(token, processor ?? new GitCountObjectsProcessor())
11+
{
12+
Name = TaskName;
13+
}
14+
15+
public override string ProcessArguments
16+
{
17+
get { return "count-objects"; }
18+
}
19+
public override TaskAffinity Affinity { get { return TaskAffinity.Exclusive; } }
20+
public override string Message { get; set; } = "Counting git objects...";
21+
}
22+
}

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@
8080
<HintPath>$(SolutionDir).\packages\TaskParallelLibrary.1.0.3333.0\lib\Net35\System.Threading.dll</HintPath>
8181
<Private>True</Private>
8282
</Reference>
83-
<Reference Include="System.Xml.Linq" />
84-
<Reference Include="System.Data.DataSetExtensions" />
85-
<Reference Include="System.Data" />
86-
<Reference Include="System.Xml" />
8783
</ItemGroup>
8884
<ItemGroup>
8985
<Compile Include="Application\ApplicationInfo.cs" />
@@ -95,9 +91,11 @@
9591
<Compile Include="Cache\CachingClasses.cs" />
9692
<Compile Include="Extensions\ActionExtensions.cs" />
9793
<Compile Include="Extensions\ListExtensions.cs" />
94+
<Compile Include="Git\GitCountObjects.cs" />
9895
<Compile Include="Git\Tasks\GitCheckoutTask.cs" />
9996
<Compile Include="Git\GitAheadBehindStatus.cs" />
10097
<Compile Include="Git\Tasks\GitAheadBehindStatusTask.cs" />
98+
<Compile Include="Git\Tasks\GitCountObjectsTask.cs" />
10199
<Compile Include="Git\Tasks\GitLfsVersionTask.cs" />
102100
<Compile Include="Git\Tasks\GitVersionTask.cs" />
103101
<Compile Include="Git\TreeData.cs" />
@@ -116,9 +114,12 @@
116114
<Compile Include="IO\FileSystem.cs" />
117115
<Compile Include="Managers\Downloader.cs" />
118116
<Compile Include="OutputProcessors\GitAheadBehindStatusOutputProcessor.cs" />
117+
<Compile Include="OutputProcessors\GitCountObjectsProcessor.cs" />
119118
<Compile Include="OutputProcessors\LfsVersionOutputProcessor.cs" />
119+
<Compile Include="OutputProcessors\LinuxDiskUsageOutputProcessor.cs" />
120120
<Compile Include="OutputProcessors\VersionOutputProcessor.cs" />
121121
<Compile Include="Helpers\TaskHelpers.cs" />
122+
<Compile Include="OutputProcessors\WindowsDiskUsageOutputProcessor.cs" />
122123
<Compile Include="Platform\DefaultEnvironment.cs" />
123124
<Compile Include="Extensions\EnvironmentExtensions.cs" />
124125
<Compile Include="Extensions\FileEventExtensions.cs" />
@@ -132,6 +133,8 @@
132133
<Compile Include="Git\IGitObjectFactory.cs" />
133134
<Compile Include="Git\Tasks\GitRevertTask.cs" />
134135
<Compile Include="Application\IApplicationManager.cs" />
136+
<Compile Include="Platform\LinuxDiskUsageTask.cs" />
137+
<Compile Include="Platform\WindowsDiskUsageTask.cs" />
135138
<Compile Include="Primitives\Package.cs" />
136139
<Compile Include="Primitives\TheVersion.cs" />
137140
<Compile Include="Tasks\ActionTask.cs" />

0 commit comments

Comments
 (0)