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

Commit 2746d52

Browse files
Merge branch 'master' into fixes/synccontext
2 parents 7272152 + 833acff commit 2746d52

File tree

69 files changed

+1931
-952
lines changed

Some content is hidden

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

69 files changed

+1931
-952
lines changed

common/properties.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<PropertyGroup>
55
<BuildType Condition="Exists('$(SolutionDir)script\src\MetricsService.cs')">Internal</BuildType>
66
<BuildDefs Condition="Exists('$(SolutionDir)script\src\MetricsService.cs')">ENABLE_METRICS</BuildDefs>
7+
<BuildDefs>ENABLE_MONO</BuildDefs>
78

89
<UnityDir Condition="$(UnityDir) == '' and Exists('$(SolutionDir)\script\lib\Managed\UnityEditor.dll')">$(SolutionDir)script\lib\</UnityDir>
910
<UnityDir Condition="$(UnityDir) == '' and Exists('$(SolutionDir)\lib\Managed\UnityEditor.dll')">$(SolutionDir)lib\</UnityDir>

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/Cache/CacheInterfaces.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public interface IRepositoryInfoCacheData
102102
GitBranch? CurrentGitBranch { get; }
103103
ConfigRemote? CurrentConfigRemote { get; }
104104
ConfigBranch? CurrentConfigBranch { get; }
105+
string CurrentHead { get; }
105106
}
106107

107108
public interface IRepositoryInfoCache : IManagedCache, IRepositoryInfoCacheData, ICanUpdate<IRepositoryInfoCacheData>

src/GitHub.Api/Cache/CachingClasses.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ sealed class RepositoryInfoCacheData : IRepositoryInfoCacheData
1414
public GitBranch? CurrentGitBranch { get; set; }
1515
public ConfigRemote? CurrentConfigRemote { get; set; }
1616
public ConfigBranch? CurrentConfigBranch { get; set; }
17+
public string CurrentHead { get; set; }
1718
}
1819
}

src/GitHub.Api/Git/GitClient.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ 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);
43+
ITask<string> GetHead(IOutputProcessor<string> processor = null);
4244
}
4345

4446
class GitClient : IGitClient
@@ -98,6 +100,12 @@ public ITask<TheVersion> LfsVersion(IOutputProcessor<TheVersion> processor = nul
98100
.Configure(processManager);
99101
}
100102

103+
public ITask<GitCountObjects> CountObjects(IOutputProcessor<GitCountObjects> processor = null)
104+
{
105+
return new GitCountObjectsTask(cancellationToken, processor)
106+
.Configure(processManager);
107+
}
108+
101109
public ITask<string> GetConfig(string key, GitConfigSource configSource, IOutputProcessor<string> processor = null)
102110
{
103111
return new GitConfigGetTask(key, configSource, cancellationToken, processor)
@@ -303,6 +311,12 @@ public ITask<string> Unlock(NPath file, bool force,
303311
.Configure(processManager);
304312
}
305313

314+
public ITask<string> GetHead(IOutputProcessor<string> processor = null)
315+
{
316+
return new FirstNonNullLineProcessTask(cancellationToken, "rev-parse --short HEAD") { Name = "Getting current head..." }
317+
.Configure(processManager);
318+
}
319+
306320
protected static ILogging Logger { get; } = LogHelper.GetLogger<GitClient>();
307321
}
308322

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/IRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public interface IRepository : IEquatable<IRepository>, IDisposable, IBackedByCa
6060
string CurrentBranchName { get; }
6161
List<GitLogEntry> CurrentLog { get; }
6262
bool IsBusy { get; }
63+
string CurrentHead { get; }
6364

6465
event Action<CacheUpdateEvent> LogChanged;
6566
event Action<CacheUpdateEvent> TrackingStatusChanged;

src/GitHub.Api/Git/Repository.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ private void CacheHasBeenInvalidated(CacheType cacheType)
238238
}
239239
}
240240

241-
private void RepositoryManagerOnCurrentBranchUpdated(ConfigBranch? branch, ConfigRemote? remote)
241+
private void RepositoryManagerOnCurrentBranchUpdated(ConfigBranch? branch, ConfigRemote? remote, string head)
242242
{
243243
taskManager.RunInUI(() =>
244244
{
@@ -247,6 +247,7 @@ private void RepositoryManagerOnCurrentBranchUpdated(ConfigBranch? branch, Confi
247247
data.CurrentGitBranch = branch.HasValue ? (GitBranch?)GetLocalGitBranch(branch.Value.name, branch.Value) : null;
248248
data.CurrentConfigRemote = remote;
249249
data.CurrentGitRemote = remote.HasValue ? (GitRemote?)GetGitRemote(remote.Value) : null;
250+
data.CurrentHead = head;
250251
name = null;
251252
cloneUrl = null;
252253
cacheContainer.RepositoryInfoCache.UpdateData(data);
@@ -347,6 +348,7 @@ public void Dispose()
347348
public GitRemote? CurrentRemote => cacheContainer.RepositoryInfoCache.CurrentGitRemote;
348349
public List<GitLogEntry> CurrentLog => cacheContainer.GitLogCache.Log;
349350
public List<GitLock> CurrentLocks => cacheContainer.GitLocksCache.GitLocks;
351+
public string CurrentHead => cacheContainer.RepositoryInfoCache.CurrentHead;
350352

351353
public UriString CloneUrl
352354
{

0 commit comments

Comments
 (0)