Switch to the editor tasks library

This commit is contained in:
Andreia Gaita 2019-12-17 22:36:01 +01:00
Родитель 70bd50032d
Коммит deb7fe0433
184 изменённых файлов: 4373 добавлений и 4119 удалений

Просмотреть файл

@ -17,11 +17,11 @@ class DugiteManifestWindow : BaseWindow
var unityAssetsPath = Application.dataPath;
var unityApplication = EditorApplication.applicationPath;
var unityApplicationContents = EditorApplication.applicationContentsPath;
var extensionInstallPath = Application.dataPath.ToNPath().Parent;
var extensionInstallPath = Application.dataPath.ToSPath().Parent;
var unityVersion = Application.unityVersion;
var env = new DefaultEnvironment();
env.Initialize(unityVersion, extensionInstallPath, unityApplication.ToNPath(),
unityApplicationContents.ToNPath(), unityAssetsPath.ToNPath());
env.Initialize(unityVersion, extensionInstallPath, unityApplication.ToSPath(),
unityApplicationContents.ToSPath(), unityAssetsPath.ToSPath());
env.InitializeRepository();
TaskManager.Instance.Initialize(new UnityUIThreadSynchronizationContext());

Двоичный файл не отображается.

Двоичный файл не отображается.

Двоичный файл не отображается.

Двоичный файл не отображается.

Двоичный файл не отображается.

Двоичный файл не отображается.

Двоичный файл не отображается.

Просмотреть файл

@ -1,11 +1,21 @@
{
"registry": "https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-candidates",
"dependencies": {
"com.unity.package-manager-ui": "2.1.2",
"com.unity.git.api": "file:../../../src/com.unity.git.api",
"com.unity.git.ui": "file:../../../src/com.unity.git.ui",
"com.unity.ext.nunit": "1.0.0",
"com.unity.ide.rider": "1.1.0",
"com.unity.ide.vscode": "1.1.2",
"com.unity.package-manager-ui": "2.2.0",
"com.unity.package-validation-suite": "0.7.10-preview",
"com.unity.test-framework": "1.0.13",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.ui": "1.0.0",
"com.unity.git.api": "file:../../../src/com.unity.git.api",
"com.unity.git.ui": "file:../../../src/com.unity.git.ui"
"com.unity.editor.tasks": "1.2.12",
"com.unity.rpc": "1.0.11-preview",
"com.unity.process-server": "0.1.23-preview"
}
}

Просмотреть файл

@ -1,2 +1,2 @@
m_EditorVersion: 2019.1.10f1
m_EditorVersionWithRevision: 2019.1.10f1 (f007ed779b7a)
m_EditorVersion: 2019.2.9f1
m_EditorVersionWithRevision: 2019.2.9f1 (ebce4d76e6e8)

Просмотреть файл

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworks>net35;net471</TargetFrameworks>
<TargetFramework>net471</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>

Двоичные данные
lib/com.unity.editor.tasks.1.2.17.nupkg Normal file

Двоичный файл не отображается.

Двоичные данные
lib/com.unity.editor.tasks.1.2.17.snupkg Normal file

Двоичный файл не отображается.

Двоичные данные
lib/com.unity.process-server.client.0.1.23-preview.nupkg Normal file

Двоичный файл не отображается.

Двоичные данные
lib/com.unity.process-server.client.0.1.25-preview.nupkg Normal file

Двоичный файл не отображается.

Двоичные данные
lib/com.unity.process-server.client.0.1.26-preview.nupkg Normal file

Двоичный файл не отображается.

Двоичные данные
lib/com.unity.process-server.interfaces.0.1.23-preview.nupkg Normal file

Двоичный файл не отображается.

Двоичные данные
lib/com.unity.process-server.interfaces.0.1.25-preview.nupkg Normal file

Двоичный файл не отображается.

Двоичные данные
lib/com.unity.process-server.interfaces.0.1.26-preview.nupkg Normal file

Двоичный файл не отображается.

Двоичные данные
lib/com.unity.process-server.server.0.1.23-preview.nupkg Normal file

Двоичный файл не отображается.

Двоичные данные
lib/com.unity.process-server.server.0.1.25-preview.nupkg Normal file

Двоичный файл не отображается.

Двоичные данные
lib/com.unity.process-server.server.0.1.26-preview.nupkg Normal file

Двоичный файл не отображается.

Двоичные данные
lib/com.unity.rpc.1.0.11-preview.nupkg Normal file

Двоичный файл не отображается.

Двоичные данные
lib/com.unity.rpc.hosted.1.0.11-preview.nupkg Normal file

Двоичный файл не отображается.

Двоичные данные
lib/com.unity.rpc.interfaces.1.0.11-preview.nupkg Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -12,6 +12,7 @@
<AssemblyName>Unity.VersionControl.Git.Localization</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<OutputPath>..\com.unity.git.api\Localization\</OutputPath>
<RuntimeIdentifiers>win</RuntimeIdentifiers>
</PropertyGroup>
<Import Project="$(SolutionDir)\common\properties.props" />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">

Просмотреть файл

@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<TargetFrameworks>net35;net471</TargetFrameworks>
<SolutionDir Condition=" '$(SolutionDir)' == '' ">..\..\..\</SolutionDir>
<ProjectGuid>{B389ADAF-62CC-486E-85B4-2D8B078DF76B}</ProjectGuid>
<AssemblyName>Unity.VersionControl.Git</AssemblyName>
<RootNamespace>Unity.VersionControl.Git</RootNamespace>
<LangVersion>7.3</LangVersion>
</PropertyGroup>
<Import Project="$(SolutionDir)\common\properties.props" />
@ -27,6 +27,7 @@
<HintPath>..\sfw\sfw.net.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net35' ">
@ -43,6 +44,54 @@
<EmbeddedResource Include="Resources\*" Exclude="Resources\*.meta" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Application\ApiClient.cs" />
<Compile Remove="Application\IApiClient.cs" />
<Compile Remove="Application\LoginResult.cs" />
<Compile Remove="Application\Organization.cs" />
<Compile Remove="Authentication\AuthenticationResult.cs" />
<Compile Remove="Authentication\AuthenticationResultExtensions.cs" />
<Compile Remove="Authentication\Credential.cs" />
<Compile Remove="Authentication\ICredentialManager.cs" />
<Compile Remove="Authentication\IKeychain.cs" />
<Compile Remove="Authentication\ILoginManager.cs" />
<Compile Remove="Authentication\Keychain.cs" />
<Compile Remove="Authentication\KeychainAdapter.cs" />
<Compile Remove="Authentication\LoginManager.cs" />
<Compile Remove="Authentication\OAuthCallbackManager.cs" />
<Compile Remove="Git\GitCredentialManager.cs" />
<Compile Remove="Helpers\Progress.cs" />
<Compile Remove="Installer\OctorunInstaller.cs" />
<Compile Remove="Metrics\IMetricsService.cs" />
<Compile Remove="Metrics\IUsageTracker.cs" />
<Compile Remove="Metrics\UsageModel.cs" />
<Compile Remove="Metrics\UsageTracker.cs" />
<Compile Remove="OutputProcessors\LinuxDiskUsageOutputProcessor.cs" />
<Compile Remove="OutputProcessors\WindowsDiskUsageOutputProcessor.cs" />
<Compile Remove="Platform\LinuxDiskUsageTask.cs" />
<Compile Remove="Platform\WindowsDiskUsageTask.cs" />
<Compile Remove="Primitives\UriString.cs" />
<Compile Remove="Process\IProcessEnvironment.cs" />
<Compile Remove="Process\IProcessManager.cs" />
<Compile Remove="Process\ProcessManager.cs" />
<Compile Remove="Tasks\ActionTask.cs" />
<Compile Remove="Tasks\BaseOutputProcessor.cs" />
<Compile Remove="Tasks\ConcurrentExclusiveInterleave.cs" />
<Compile Remove="Tasks\Downloader.cs" />
<Compile Remove="Tasks\DownloadTask.cs" />
<Compile Remove="Tasks\ITaskManager.cs" />
<Compile Remove="Tasks\OctorunTask.cs" />
<Compile Remove="Tasks\ProcessTask.cs" />
<Compile Remove="Tasks\TaskBase.cs" />
<Compile Remove="Tasks\TaskCanceledExceptions.cs" />
<Compile Remove="Tasks\TaskExtensions.cs" />
<Compile Remove="Tasks\TaskManager.cs" />
<Compile Remove="Threading\IAwaitable.cs" />
<Compile Remove="Threading\IAwaiter.cs" />
<Compile Remove="Threading\IMainThreadSynchronizationContext.cs" />
<Compile Remove="Threading\ThreadingHelper.cs" />
</ItemGroup>
<ItemGroup>
<Compile Condition=" '$(Buildtype)' == 'Internal'" Include="$(SolutionDir)\script\src\ApplicationInfo_Local.cs">
<Link>Properties\ApplicationInfo_Local.cs</Link>
@ -53,6 +102,51 @@
<None Include="$(SolutionDir)\common\ApplicationInfo_Local.cs-example">
<Link>Properties\ApplicationInfo_Local.cs-example</Link>
</None>
<None Include="Application\ApiClient.cs" />
<None Include="Application\IApiClient.cs" />
<None Include="Application\LoginResult.cs" />
<None Include="Application\Organization.cs" />
<None Include="Authentication\AuthenticationResult.cs" />
<None Include="Authentication\AuthenticationResultExtensions.cs" />
<None Include="Authentication\Credential.cs" />
<None Include="Authentication\ICredentialManager.cs" />
<None Include="Authentication\IKeychain.cs" />
<None Include="Authentication\ILoginManager.cs" />
<None Include="Authentication\Keychain.cs" />
<None Include="Authentication\KeychainAdapter.cs" />
<None Include="Authentication\LoginManager.cs" />
<None Include="Authentication\OAuthCallbackManager.cs" />
<None Include="Git\GitCredentialManager.cs" />
<None Include="Helpers\Progress.cs" />
<None Include="Installer\OctorunInstaller.cs" />
<None Include="Metrics\IMetricsService.cs" />
<None Include="Metrics\IUsageTracker.cs" />
<None Include="Metrics\UsageModel.cs" />
<None Include="Metrics\UsageTracker.cs" />
<None Include="OutputProcessors\LinuxDiskUsageOutputProcessor.cs" />
<None Include="OutputProcessors\WindowsDiskUsageOutputProcessor.cs" />
<None Include="Platform\LinuxDiskUsageTask.cs" />
<None Include="Platform\WindowsDiskUsageTask.cs" />
<None Include="Primitives\UriString.cs" />
<None Include="Process\IProcessEnvironment.cs" />
<None Include="Process\IProcessManager.cs" />
<None Include="Process\ProcessManager.cs" />
<None Include="Tasks\ActionTask.cs" />
<None Include="Tasks\BaseOutputProcessor.cs" />
<None Include="Tasks\ConcurrentExclusiveInterleave.cs" />
<None Include="Tasks\Downloader.cs" />
<None Include="Tasks\DownloadTask.cs" />
<None Include="Tasks\ITaskManager.cs" />
<None Include="Tasks\OctorunTask.cs" />
<None Include="Tasks\ProcessTask.cs" />
<None Include="Tasks\TaskBase.cs" />
<None Include="Tasks\TaskCanceledExceptions.cs" />
<None Include="Tasks\TaskExtensions.cs" />
<None Include="Tasks\TaskManager.cs" />
<None Include="Threading\IAwaitable.cs" />
<None Include="Threading\IAwaiter.cs" />
<None Include="Threading\IMainThreadSynchronizationContext.cs" />
<None Include="Threading\ThreadingHelper.cs" />
</ItemGroup>
<!-- copy source files to packman package folder -->
@ -68,6 +162,12 @@
<Project>Logging</Project>
</VersionFiles>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net471'">
<PackageReference Include="com.unity.editor.tasks" Version="1.2.17" />
<PackageReference Include="com.unity.process-server.client" Version="0.1.26-preview" />
<PackageReference Include="com.unity.process-server.server" Version="0.1.26-preview" />
<PackageReference Include="com.unity.rpc" Version="1.0.11-preview" />
</ItemGroup>
<Import Project="$(SolutionDir)\common\packaging.targets" Condition=" '$(TargetFramework)' == 'net471' " />
</Project>

Просмотреть файл

@ -1,2 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp70</s:String></wpf:ResourceDictionary>
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp73</s:String></wpf:ResourceDictionary>

Просмотреть файл

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using Unity.VersionControl.Git;
@ -7,6 +8,7 @@ using System.Runtime.Serialization;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Unity.Editor.Tasks;
using Unity.VersionControl.Git.Json;
namespace Unity.VersionControl.Git
@ -92,8 +94,7 @@ namespace Unity.VersionControl.Git
var adapter = EnsureKeychainAdapter();
var octorunTask = new OctorunTask(taskManager.Token, environment, command.ToString(), adapter.Credential.Token)
.Configure(processManager);
var octorunTask = new OctorunTask(taskManager.Token, environment, command.ToString(), adapter.Credential.Token).Configure((ProcessStartInfo)processManager);
var ret = octorunTask.RunSynchronously();
if (ret.IsSuccess && ret.Output.Length == 2)
@ -125,8 +126,7 @@ namespace Unity.VersionControl.Git
Guard.ArgumentNotNull(onSuccess, nameof(onSuccess));
new FuncTask<GitHubHostMeta>(taskManager.Token, () =>
{
var octorunTask = new OctorunTask(taskManager.Token, environment, "meta -h " + HostAddress.ApiUri.Host)
.Configure(processManager);
var octorunTask = new OctorunTask(taskManager.Token, environment, "meta -h " + HostAddress.ApiUri.Host).Configure((ProcessStartInfo)processManager);
var ret = octorunTask.RunSynchronously();
if (ret.IsSuccess)
@ -198,8 +198,7 @@ namespace Unity.VersionControl.Git
var command = HostAddress.IsGitHubDotCom() ? "organizations" : "organizations -h " + HostAddress.ApiUri.Host;
var octorunTask = new OctorunTask(taskManager.Token, environment,
command, adapter.Credential.Token)
.Configure(processManager);
command, adapter.Credential.Token).Configure((ProcessStartInfo)processManager);
var ret = octorunTask.RunSynchronously();
if (ret.IsSuccess)
@ -280,8 +279,7 @@ namespace Unity.VersionControl.Git
public void CreateOAuthToken(string code, Action<bool, string> result)
{
var command = "token -h " + HostAddress.WebUri.Host;
var octorunTask = new OctorunTask(taskManager.Token, environment, command, code)
.Configure(processManager);
var octorunTask = new OctorunTask(taskManager.Token, environment, command, code).Configure((ProcessStartInfo)processManager);
octorunTask
.Then((b, octorunResult) =>
@ -433,8 +431,7 @@ namespace Unity.VersionControl.Git
var adapter = EnsureKeychainAdapter();
var command = HostAddress.IsGitHubDotCom() ? "validate" : "validate -h " + HostAddress.ApiUri.Host;
var octorunTask = new OctorunTask(taskManager.Token, environment, command, adapter.Credential.Token)
.Configure(processManager);
var octorunTask = new OctorunTask(taskManager.Token, environment, command, adapter.Credential.Token).Configure((ProcessStartInfo)processManager);
var ret = octorunTask.RunSynchronously();
if (ret.IsSuccess)

Просмотреть файл

@ -1,8 +1,10 @@
#pragma warning disable 436
using Unity.VersionControl.Git;
using Unity.VersionControl.Git.IO;
namespace Unity.VersionControl.Git
{
public static partial class ApplicationInfo
{
#if GFU_DEBUG_BUILD
@ -54,7 +56,7 @@ internal static partial class ThisAssembly {
var attr = System.Attribute.GetCustomAttribute(typeof(ThisAssembly).Assembly, typeof(System.Reflection.AssemblyInformationalVersionAttribute)) as System.Reflection.AssemblyInformationalVersionAttribute;
if (attr != null)
return attr.InformationalVersion;
var basePath = Platform.Instance?.Environment.ExtensionInstallPath ?? NPath.Default;
var basePath = Platform.Instance?.Environment.ExtensionInstallPath ?? SPath.Default;
if (!basePath.IsInitialized)
return "0";
var version = basePath.Parent.Combine("version.json").ReadAllText().FromJson<VersionJson>(true);

Просмотреть файл

@ -2,10 +2,13 @@
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using Unity.Editor.Tasks;
using static Unity.VersionControl.Git.GitInstaller;
namespace Unity.VersionControl.Git
{
using IO;
public class ApplicationManagerBase : IApplicationManager
{
protected static ILogging Logger { get; } = LogHelper.GetLogger<IApplicationManager>();
@ -25,13 +28,13 @@ namespace Unity.VersionControl.Git
remove { progressReporter.OnProgress -= value; }
}
public ApplicationManagerBase(SynchronizationContext synchronizationContext, IEnvironment environment)
public ApplicationManagerBase(SynchronizationContext synchronizationContext, IGitEnvironment environment)
{
Environment = environment;
TaskManager = new TaskManager().Initialize(synchronizationContext);
Platform = new Platform(Environment);
ProcessManager = new ProcessManager(Environment, Platform.GitEnvironment, TaskManager.Token);
GitClient = new GitClient(Environment, ProcessManager, TaskManager.Token);
ProcessManager = new ProcessManager(Environment);
Platform = new Platform(TaskManager, Environment, ProcessManager);
GitClient = new GitClient(Platform);
}
protected void Initialize()
@ -39,17 +42,8 @@ namespace Unity.VersionControl.Git
LogHelper.TracingEnabled = UserSettings.Get(Constants.TraceLoggingKey, false);
ApplicationConfiguration.WebTimeout = UserSettings.Get(Constants.WebTimeoutKey, ApplicationConfiguration.WebTimeout);
ApplicationConfiguration.GitTimeout = UserSettings.Get(Constants.GitTimeoutKey, ApplicationConfiguration.GitTimeout);
Platform.Initialize(ProcessManager, TaskManager);
Platform.Initialize();
progress.OnProgress += progressReporter.UpdateProgress;
UsageTracker = new UsageTracker(TaskManager, GitClient, ProcessManager, UserSettings, Environment, Platform.Keychain, InstanceId.ToString());
#if ENABLE_METRICS
var metricsService = new MetricsService(ProcessManager,
TaskManager,
Platform.Keychain,
Environment);
UsageTracker.MetricsService = metricsService;
#endif
}
public void Run()
@ -57,21 +51,15 @@ namespace Unity.VersionControl.Git
isBusy = true;
progress.UpdateProgress(0, 100, "Initializing...");
if (firstRun)
{
UsageTracker.IncrementNumberOfStartups();
}
var thread = new Thread(() =>
{
var thread = new Thread(() => {
GitInstallationState state = new GitInstallationState();
try
{
if (Environment.IsMac)
{
var getEnvPath = new SimpleProcessTask(TaskManager.Token, "bash".ToNPath(), "-c \"/usr/libexec/path_helper\"")
.Configure(ProcessManager, dontSetupGit: true)
.Catch(e => true); // make sure this doesn't throw if the task fails
var getEnvPath = new NativeProcessTask<string>(TaskManager, ProcessManager, "bash".ToSPath(),
"-c \"/usr/libexec/path_helper\"", new StringOutputProcessor())
.Catch(e => true); // make sure this doesn't throw if the task fails
var path = getEnvPath.RunSynchronously();
if (getEnvPath.Successful)
{
@ -80,18 +68,13 @@ namespace Unity.VersionControl.Git
}
}
progress.UpdateProgress(20, 100, "Setting up octorun...");
Environment.OctorunScriptPath = new OctorunInstaller(Environment, TaskManager)
.SetupOctorunIfNeeded();
progress.UpdateProgress(50, 100, "Setting up git...");
state = Environment.GitInstallationState;
if (!state.GitIsValid && !state.GitLfsIsValid && FirstRun)
{
// importing old settings
NPath gitExecutablePath = Environment.SystemSettings.Get(Constants.GitInstallPathKey, NPath.Default);
SPath gitExecutablePath = Environment.SystemSettings.Get(Constants.GitInstallPathKey, SPath.Default);
if (gitExecutablePath.IsInitialized)
{
Environment.SystemSettings.Unset(Constants.GitInstallPathKey);
@ -101,8 +84,7 @@ namespace Unity.VersionControl.Git
}
}
var installer = new GitInstaller(Environment, ProcessManager, TaskManager.Token);
var installer = new GitInstaller(TaskManager, Environment, ProcessManager, Platform.ProcessEnvironment);
installer.Progress(progressReporter.UpdateProgress);
if (state.GitIsValid && state.GitLfsIsValid)
{
@ -138,17 +120,14 @@ namespace Unity.VersionControl.Git
progress.UpdateProgress(90, 100, "Initialization failed");
}
new ActionTask<bool>(TaskManager.Token, (s, gitIsValid) =>
{
InitializationComplete();
if (gitIsValid)
{
InitializeUI();
}
},
() => state.GitIsValid && state.GitLfsIsValid)
{ Affinity = TaskAffinity.UI }
.Start();
TaskManager.WithUI(gitIsValid => {
InitializationComplete();
if (gitIsValid)
{
InitializeUI();
}
}, state.GitIsValid && state.GitLfsIsValid)
.Start();
});
thread.Start();
}
@ -227,7 +206,7 @@ namespace Unity.VersionControl.Git
var success = true;
try
{
var targetPath = NPath.CurrentDirectory;
var targetPath = SPath.CurrentDirectory;
var gitignore = targetPath.Combine(".gitignore");
var gitAttrs = targetPath.Combine(".gitattributes");
@ -265,7 +244,6 @@ namespace Unity.VersionControl.Git
progress.UpdateProgress(90, 100, "Initializing...");
RestartRepository();
TaskManager.RunInUI(InitializeUI);
UsageTracker.IncrementProjectsInitialized();
progress.UpdateProgress(100, 100, "Initialized");
}
isBusy = false;
@ -276,7 +254,7 @@ namespace Unity.VersionControl.Git
private void ConfigureMergeSettings(string keyName = null)
{
var unityYamlMergeExec =
Environment.UnityApplicationContents.Combine("Tools", "UnityYAMLMerge" + Environment.ExecutableExtension);
Environment.UnityApplicationContents.ToSPath().Combine("Tools", "UnityYAMLMerge" + Environment.ExecutableExtension);
var yamlMergeCommand = $"'{unityYamlMergeExec}' merge -h -p --force %O %B %A %A";
@ -344,7 +322,6 @@ namespace Unity.VersionControl.Git
protected virtual void InitializationComplete() {}
private bool disposed = false;
private IOAuthCallbackManager oAuthCallbackManager;
protected virtual void Dispose(bool disposing)
{
@ -374,7 +351,7 @@ namespace Unity.VersionControl.Git
Dispose(true);
}
public IEnvironment Environment { get; private set; }
public IGitEnvironment Environment { get; private set; }
public IPlatform Platform { get; protected set; }
public virtual IProcessEnvironment GitEnvironment { get; set; }
public IProcessManager ProcessManager { get; protected set; }
@ -383,21 +360,6 @@ namespace Unity.VersionControl.Git
public ISettings LocalSettings { get { return Environment.LocalSettings; } }
public ISettings SystemSettings { get { return Environment.SystemSettings; } }
public ISettings UserSettings { get { return Environment.UserSettings; } }
public IUsageTracker UsageTracker { get; protected set; }
public IOAuthCallbackManager OAuthCallbackManager
{
get
{
if (oAuthCallbackManager == null)
{
oAuthCallbackManager = new OAuthCallbackManager();
}
return oAuthCallbackManager;
}
}
public bool IsBusy { get { return isBusy; } }
protected TaskScheduler UIScheduler { get; private set; }
protected IRepositoryManager RepositoryManager { get { return repositoryManager; } }

Просмотреть файл

@ -1,12 +1,13 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git
{
public interface IApplicationManager : IDisposable
{
IEnvironment Environment { get; }
IGitEnvironment Environment { get; }
IPlatform Platform { get; }
IProcessEnvironment GitEnvironment { get; }
IProcessManager ProcessManager { get; }
@ -15,8 +16,6 @@ namespace Unity.VersionControl.Git
ISettings UserSettings { get; }
ITaskManager TaskManager { get; }
IGitClient GitClient { get; }
IUsageTracker UsageTracker { get; }
IOAuthCallbackManager OAuthCallbackManager { get; }
bool IsBusy { get; }
void Run();
void InitializeRepository();

Просмотреть файл

@ -6,12 +6,13 @@ using Unity.VersionControl.Git;
namespace Unity.VersionControl.Git
{
using IO;
[Serializable]
public class Connection
{
public string Host { get; set; }
public string Username { get; set; }
[NonSerialized] internal GitHubUser User;
// for json serialization
public Connection()
@ -73,7 +74,7 @@ namespace Unity.VersionControl.Git
private readonly ILogging logger = LogHelper.GetLogger<Keychain>();
private readonly ICredentialManager credentialManager;
private readonly NPath cachePath;
private readonly SPath cachePath;
// cached credentials loaded from git to pass to GitHub/ApiClient
private readonly Dictionary<UriString, KeychainAdapter> keychainAdapters = new Dictionary<UriString, KeychainAdapter>();

Просмотреть файл

@ -1,6 +1,7 @@
using System;
using System.Text;
using Unity.VersionControl.Git;
using ITask = Unity.Editor.Tasks.ITask;
namespace Unity.VersionControl.Git
{

Просмотреть файл

@ -4,10 +4,11 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using sfw.net;
using Unity.VersionControl.Git;
namespace Unity.VersionControl.Git
{
using IO;
public interface IRepositoryWatcher : IDisposable
{
void Start();
@ -27,7 +28,7 @@ namespace Unity.VersionControl.Git
{
private readonly RepositoryPathConfiguration paths;
private readonly CancellationToken cancellationToken;
private readonly NPath[] ignoredPaths;
private readonly SPath[] ignoredPaths;
private readonly ManualResetEventSlim pauseEvent;
private NativeInterface nativeInterface;
private NativeInterface worktreeNativeInterface;
@ -50,8 +51,8 @@ namespace Unity.VersionControl.Git
this.cancellationToken = cancellationToken;
ignoredPaths = new[] {
platform.Environment.UnityProjectPath.Combine("Library"),
platform.Environment.UnityProjectPath.Combine("Temp")
platform.Environment.UnityProjectPath.ToSPath().Combine("Library"),
platform.Environment.UnityProjectPath.ToSPath().Combine("Temp")
};
pauseEvent = new ManualResetEventSlim();
@ -181,7 +182,7 @@ namespace Unity.VersionControl.Git
break;
}
var eventDirectory = new NPath(fileEvent.Directory);
var eventDirectory = new SPath(fileEvent.Directory);
var fileA = eventDirectory.Combine(fileEvent.FileA);
// handling events in .git/*

Просмотреть файл

@ -2,17 +2,20 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git
{
using IO;
public static class EnvironmentExtensions
{
public static NPath GetRepositoryPath(this IEnvironment environment, NPath path)
public static SPath GetRepositoryPath(this IGitEnvironment environment, SPath path)
{
Guard.ArgumentNotNull(path, nameof(path));
NPath projectPath = environment.UnityProjectPath;
NPath repositoryPath = environment.RepositoryPath;
SPath projectPath = environment.UnityProjectPath.ToSPath();
SPath repositoryPath = environment.RepositoryPath;
if (projectPath == repositoryPath)
{
return path;
@ -26,12 +29,12 @@ namespace Unity.VersionControl.Git
return projectPath.RelativeTo(repositoryPath).Combine(path);
}
public static NPath GetAssetPath(this IEnvironment environment, NPath path)
public static SPath GetAssetPath(this IGitEnvironment environment, SPath path)
{
Guard.ArgumentNotNull(path, nameof(path));
NPath projectPath = environment.UnityProjectPath;
NPath repositoryPath = environment.RepositoryPath;
SPath projectPath = environment.UnityProjectPath.ToSPath();
SPath repositoryPath = environment.RepositoryPath;
if (projectPath == repositoryPath)
{
return path;
@ -45,14 +48,14 @@ namespace Unity.VersionControl.Git
return repositoryPath.Combine(path).MakeAbsolute().RelativeTo(projectPath);
}
public static IEnumerable<NPath> ToNPathList(this string envPath, IEnvironment environment)
public static IEnumerable<SPath> ToSPathList(this string envPath, IEnvironment environment)
{
return envPath
.Split(Path.PathSeparator)
.Where(x => x != null)
.Where(x => !string.IsNullOrEmpty(x))
.Select(x => environment.ExpandEnvironmentVariables(x.Trim('"', '\'')))
.Where(x => !String.IsNullOrEmpty(x))
.Select(x => x.ToNPath());
.Where(x => !string.IsNullOrEmpty(x))
.Select(x => x.ToSPath());
}
}
}

Просмотреть файл

@ -2,11 +2,13 @@ using sfw.net;
namespace Unity.VersionControl.Git
{
using IO;
static class FileEventExtensions
{
internal static string Describe(this Event fileEvent)
{
var directory = fileEvent.Directory.ToNPath();
var directory = fileEvent.Directory.ToSPath();
var fileA = directory.Combine(fileEvent.FileA);
@ -19,4 +21,4 @@ namespace Unity.VersionControl.Git
return $"{{FileEvent: {fileEvent.Type} \"{fileA}\"->\"{fileB}\"}}";
}
}
}
}

Просмотреть файл

@ -6,6 +6,8 @@ using System.Text;
namespace Unity.VersionControl.Git
{
using IO;
static class FileSystemExtensions
{
public static string CalculateFileMD5(this IFileSystem fileSystem, string file)
@ -54,4 +56,4 @@ namespace Unity.VersionControl.Git
}
}
}
}
}

Просмотреть файл

@ -1,12 +1,14 @@
using Unity.VersionControl.Git;
using System;
using System;
using System.Collections.Generic;
using System.Threading;
using Unity.Editor.Tasks;
using Unity.VersionControl.Git.Tasks;
using static Unity.VersionControl.Git.GitInstaller;
namespace Unity.VersionControl.Git
{
using IO;
/// <summary>
/// Client that provides access to git functionality
/// </summary>
@ -17,14 +19,14 @@ namespace Unity.VersionControl.Git
/// </summary>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> Init(IOutputProcessor<string> processor = null);
ITask<string> Init();
/// <summary>
/// Executes `git lfs install` to install LFS hooks.
/// </summary>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> LfsInstall(IOutputProcessor<string> processor = null);
ITask<string> LfsInstall();
/// <summary>
/// Executes `git rev-list` to determine the ahead/behind status between two refs.
@ -33,14 +35,14 @@ namespace Unity.VersionControl.Git
/// <param name="otherRef">Ref to compare against</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns><see cref="GitAheadBehindStatus"/> output</returns>
ITask<GitAheadBehindStatus> AheadBehindStatus(string gitRef, string otherRef, IOutputProcessor<GitAheadBehindStatus> processor = null);
ITask<GitAheadBehindStatus> AheadBehindStatus(string gitRef, string otherRef);
/// <summary>
/// Executes `git status` to determine the working directory status.
/// </summary>
/// <param name="processor">A custom output processor instance</param>
/// <returns><see cref="GitStatus"/> output</returns>
ITask<GitStatus> Status(IOutputProcessor<GitStatus> processor = null);
ITask<GitStatus> Status();
/// <summary>
/// Executes `git config get` to get a configuration value.
@ -49,7 +51,7 @@ namespace Unity.VersionControl.Git
/// <param name="configSource">The config source (unspecified, local,user,global) to use</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> GetConfig(string key, GitConfigSource configSource, IOutputProcessor<string> processor = null);
ITask<string> GetConfig(string key, GitConfigSource configSource);
/// <summary>
/// Executes `git config set` to set a configuration value.
@ -59,7 +61,7 @@ namespace Unity.VersionControl.Git
/// <param name="configSource">The config source (unspecified, local,user,global) to use</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> SetConfig(string key, string value, GitConfigSource configSource, IOutputProcessor<string> processor = null);
ITask<string> SetConfig(string key, string value, GitConfigSource configSource);
/// <summary>
/// Executes `git config --unset` to remove a configuration value.
@ -68,7 +70,7 @@ namespace Unity.VersionControl.Git
/// <param name="configSource">The config source (unspecified, local,user,global) to use</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> UnSetConfig(string key, GitConfigSource configSource, IOutputProcessor<string> processor = null);
ITask<string> UnSetConfig(string key, GitConfigSource configSource);
/// <summary>
/// Executes two `git config get` commands to get the git user and email.
@ -82,7 +84,7 @@ namespace Unity.VersionControl.Git
/// <param name="local"></param>
/// <param name="processor">A custom output processor instance</param>
/// <returns><see cref="List&lt;T&gt;"/> of <see cref="GitLock"/> output</returns>
ITask<List<GitLock>> ListLocks(bool local, BaseOutputListProcessor<GitLock> processor = null);
ITask<List<GitLock>> ListLocks(bool local);
/// <summary>
/// Executes `git pull` to perform a pull operation.
@ -91,7 +93,7 @@ namespace Unity.VersionControl.Git
/// <param name="branch">The branch to pull</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> Pull(string remote, string branch, IOutputProcessor<string> processor = null);
ITask<string> Pull(string remote, string branch);
/// <summary>
/// Executes `git push` to perform a push operation.
@ -100,7 +102,7 @@ namespace Unity.VersionControl.Git
/// <param name="branch">The branch to push</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> Push(string remote, string branch, IOutputProcessor<string> processor = null);
ITask<string> Push(string remote, string branch);
/// <summary>
/// Executes `git revert` to perform a revert operation.
@ -108,7 +110,7 @@ namespace Unity.VersionControl.Git
/// <param name="changeset">The changeset to revert</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> Revert(string changeset, IOutputProcessor<string> processor = null);
ITask<string> Revert(string changeset);
/// <summary>
/// Executes `git reset` to perform a reset operation.
@ -117,7 +119,7 @@ namespace Unity.VersionControl.Git
/// <param name="resetMode">Mode with which to reset with</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of the git command</returns>
ITask<string> Reset(string changeset, GitResetMode resetMode = GitResetMode.NonSpecified, IOutputProcessor<string> processor = null);
ITask<string> Reset(string changeset, GitResetMode resetMode = GitResetMode.NonSpecified);
/// <summary>
/// Executes `git fetch` to perform a fetch operation.
@ -125,7 +127,7 @@ namespace Unity.VersionControl.Git
/// <param name="remote">The remote to fetch from</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> Fetch(string remote, IOutputProcessor<string> processor = null);
ITask<string> Fetch(string remote);
/// <summary>
/// Executes `git checkout` to switch branches.
@ -133,7 +135,7 @@ namespace Unity.VersionControl.Git
/// <param name="branch">The branch to checkout</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> SwitchBranch(string branch, IOutputProcessor<string> processor = null);
ITask<string> SwitchBranch(string branch);
/// <summary>
/// Executes `git branch -d` to delete a branch.
@ -142,7 +144,7 @@ namespace Unity.VersionControl.Git
/// <param name="deleteUnmerged">The flag to indicate the branch should be deleted even if not merged</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> DeleteBranch(string branch, bool deleteUnmerged = false, IOutputProcessor<string> processor = null);
ITask<string> DeleteBranch(string branch, bool deleteUnmerged = false);
/// <summary>
/// Executes `git branch` to create a branch.
@ -151,7 +153,7 @@ namespace Unity.VersionControl.Git
/// <param name="baseBranch">The name of branch to create from</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> CreateBranch(string branch, string baseBranch, IOutputProcessor<string> processor = null);
ITask<string> CreateBranch(string branch, string baseBranch);
/// <summary>
/// Executes `git remote add` to add a git remote.
@ -160,7 +162,7 @@ namespace Unity.VersionControl.Git
/// <param name="url">The url of the remote</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> RemoteAdd(string remote, string url, IOutputProcessor<string> processor = null);
ITask<string> RemoteAdd(string remote, string url);
/// <summary>
/// Executes `git remote rm` to remove a git remote.
@ -168,7 +170,7 @@ namespace Unity.VersionControl.Git
/// <param name="remote">The remote to remove</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> RemoteRemove(string remote, IOutputProcessor<string> processor = null);
ITask<string> RemoteRemove(string remote);
/// <summary>
/// Executes `git remote set-url` to change the url of a git remote.
@ -177,7 +179,7 @@ namespace Unity.VersionControl.Git
/// <param name="url">The url to change to</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> RemoteChange(string remote, string url, IOutputProcessor<string> processor = null);
ITask<string> RemoteChange(string remote, string url);
/// <summary>
/// Executes `git commit` to perform a commit operation.
@ -186,7 +188,7 @@ namespace Unity.VersionControl.Git
/// <param name="body">The commit message body</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> Commit(string message, string body, IOutputProcessor<string> processor = null);
ITask<string> Commit(string message, string body);
/// <summary>
/// Executes at least one `git add` command to add the list of files to the git index.
@ -194,14 +196,14 @@ namespace Unity.VersionControl.Git
/// <param name="files">The file to add</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> Add(IList<string> files, IOutputProcessor<string> processor = null);
ITask<string> Add(IList<string> files);
/// <summary>
/// Executes `git add -A` to add all files to the git index.
/// </summary>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> AddAll(IOutputProcessor<string> processor = null);
ITask<string> AddAll();
/// <summary>
/// Executes at least one `git checkout` command to discard changes to the list of files.
@ -209,14 +211,14 @@ namespace Unity.VersionControl.Git
/// <param name="files">The files to discard</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> Discard(IList<string> files, IOutputProcessor<string> processor = null);
ITask<string> Discard(IList<string> files);
/// <summary>
/// Executes `git checkout -- .` to discard all changes in the working directory.
/// </summary>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> DiscardAll(IOutputProcessor<string> processor = null);
ITask<string> DiscardAll();
/// <summary>
/// Executes at least one `git clean` command to discard changes to the list of untracked files.
@ -224,14 +226,14 @@ namespace Unity.VersionControl.Git
/// <param name="files">The files to clean</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> Clean(IList<string> files, IOutputProcessor<string> processor = null);
ITask<string> Clean(IList<string> files);
/// <summary>
/// Executes `git clean` command to discard changes to all untracked files.
/// </summary>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> CleanAll(IOutputProcessor<string> processor = null);
ITask<string> CleanAll();
/// <summary>
/// Executes at least one `git checkout` command to checkout files at the given changeset
@ -240,7 +242,7 @@ namespace Unity.VersionControl.Git
/// <param name="files">The files to check out</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> CheckoutVersion(string changeset, IList<string> files, IOutputProcessor<string> processor = null);
ITask<string> CheckoutVersion(string changeset, IList<string> files);
/// <summary>
/// Executes at least one `git reset HEAD` command to remove files from the git index.
@ -248,7 +250,7 @@ namespace Unity.VersionControl.Git
/// <param name="files">The files to remove</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> Remove(IList<string> files, IOutputProcessor<string> processor = null);
ITask<string> Remove(IList<string> files);
/// <summary>
/// Executes at least one `git add` command to add the list of files to the git index. Followed by a `git commit` command to commit the changes.
@ -258,7 +260,7 @@ namespace Unity.VersionControl.Git
/// <param name="body">The commit message body</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> AddAndCommit(IList<string> files, string message, string body, IOutputProcessor<string> processor = null);
ITask<string> AddAndCommit(IList<string> files, string message, string body);
/// <summary>
/// Executes `git lfs lock` to lock a file.
@ -266,7 +268,7 @@ namespace Unity.VersionControl.Git
/// <param name="file">The file to lock</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> Lock(NPath file, IOutputProcessor<string> processor = null);
ITask<string> Lock(SPath file);
/// <summary>
/// Executes `git lfs unlock` to unlock a file.
@ -275,14 +277,14 @@ namespace Unity.VersionControl.Git
/// <param name="force">If force should be used</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> Unlock(NPath file, bool force, IOutputProcessor<string> processor = null);
ITask<string> Unlock(SPath file, bool force);
/// <summary>
/// Executes `git log` to get the history of the current branch.
/// </summary>
/// <param name="processor">A custom output processor instance</param>
/// <returns><see cref="List&lt;T&gt;"/> of <see cref="GitLogEntry"/> output</returns>
ITask<List<GitLogEntry>> Log(BaseOutputListProcessor<GitLogEntry> processor = null);
ITask<List<GitLogEntry>> Log();
/// <summary>
/// Executes `git log -- <file>` to get the history of a specific file.
@ -290,28 +292,28 @@ namespace Unity.VersionControl.Git
/// <param name="file"></param>
/// <param name="processor">A custom output processor instance</param>
/// <returns><see cref="List&lt;T&gt;"/> of <see cref="GitLogEntry"/> output</returns>
ITask<List<GitLogEntry>> LogFile(string file, BaseOutputListProcessor<GitLogEntry> processor = null);
ITask<List<GitLogEntry>> LogFile(string file);
/// <summary>
/// Executes `git --version` to get the git version.
/// </summary>
/// <param name="processor">A custom output processor instance</param>
/// <returns><see cref="TheVersion"/> output</returns>
ITask<TheVersion> Version(IOutputProcessor<TheVersion> processor = null);
ITask<TheVersion> Version();
/// <summary>
/// Executes `git lfs version` to get the git lfs version.
/// </summary>
/// <param name="processor">A custom output processor instance</param>
/// <returns><see cref="TheVersion"/> output</returns>
ITask<TheVersion> LfsVersion(IOutputProcessor<TheVersion> processor = null);
ITask<TheVersion> LfsVersion();
/// <summary>
/// Executes `git count-objects` to get the size of the git repo in kilobytes.
/// </summary>
/// <param name="processor">A custom output processor instance</param>
/// <returns><see cref="int"/> output</returns>
ITask<int> CountObjects(IOutputProcessor<int> processor = null);
ITask<int> CountObjects();
/// <summary>
/// Executes two `git set config` commands to set the git name and email.
@ -327,7 +329,7 @@ namespace Unity.VersionControl.Git
/// </summary>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> GetHead(IOutputProcessor<string> processor = null);
ITask<string> GetHead();
}
public class GitClient : IGitClient
@ -335,111 +337,126 @@ namespace Unity.VersionControl.Git
private const string UserNameConfigKey = "user.name";
private const string UserEmailConfigKey = "user.email";
private const int SpoolLength = 5000;
private readonly IEnvironment environment;
private readonly ITaskManager taskManager;
private readonly IGitEnvironment environment;
private readonly IProcessManager processManager;
private readonly CancellationToken cancellationToken;
private readonly IProcessEnvironment processEnvironment;
private readonly CancellationTokenSource cts;
private CancellationToken Token => cts.Token;
public GitClient(IEnvironment environment, IProcessManager processManager, CancellationToken cancellationToken)
public GitClient(ITaskManager taskManager, IProcessManager processManager, IProcessEnvironment gitProcessEnvironment, IGitEnvironment environment, CancellationToken cancellationToken = default)
{
this.taskManager = taskManager;
this.environment = environment;
this.processManager = processManager;
this.cancellationToken = cancellationToken;
this.processEnvironment = gitProcessEnvironment;
cts = CancellationTokenSource.CreateLinkedTokenSource(taskManager.Token, cancellationToken);
}
public GitClient(IPlatform platform, CancellationToken cancellationToken = default)
{
this.taskManager = platform.TaskManager;
this.environment = platform.Environment;
this.processManager = platform.ProcessManager;
this.processEnvironment = platform.ProcessEnvironment;
cts = CancellationTokenSource.CreateLinkedTokenSource(taskManager.Token, cancellationToken);
}
///<inheritdoc/>
public ITask<string> Init(IOutputProcessor<string> processor = null)
public ITask<string> Init()
{
return new GitInitTask(cancellationToken, processor)
return new GitInitTask(taskManager, processEnvironment, environment, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> LfsInstall(IOutputProcessor<string> processor = null)
public ITask<string> LfsInstall()
{
return new GitLfsInstallTask(cancellationToken, processor)
return new GitLfsInstallTask(taskManager, processEnvironment, environment, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<GitStatus> Status(IOutputProcessor<GitStatus> processor = null)
public ITask<GitStatus> Status()
{
return new GitStatusTask(new GitObjectFactory(environment), cancellationToken, processor)
return new GitStatusTask(taskManager, processEnvironment, environment, new GitObjectFactory(environment), Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<GitAheadBehindStatus> AheadBehindStatus(string gitRef, string otherRef, IOutputProcessor<GitAheadBehindStatus> processor = null)
public ITask<GitAheadBehindStatus> AheadBehindStatus(string gitRef, string otherRef)
{
return new GitAheadBehindStatusTask(gitRef, otherRef, cancellationToken, processor)
return new GitAheadBehindStatusTask(taskManager, processEnvironment, environment, gitRef, otherRef, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<List<GitLogEntry>> Log(BaseOutputListProcessor<GitLogEntry> processor = null)
public ITask<List<GitLogEntry>> Log()
{
return new GitLogTask(new GitObjectFactory(environment), cancellationToken, processor)
return new GitLogTask(taskManager, processEnvironment, environment, new GitObjectFactory(environment), token: Token)
.Configure(processManager)
.Catch(exception => exception is ProcessException &&
exception.Message.StartsWith("fatal: your current branch") &&
exception.Message.EndsWith("does not have any commits yet"))
.Then((success, list) => success ? list : new List<GitLogEntry>());
.Then((success, _, list) => success ? list : new List<GitLogEntry>());
}
///<inheritdoc/>
public ITask<List<GitLogEntry>> LogFile(string file, BaseOutputListProcessor<GitLogEntry> processor = null)
public ITask<List<GitLogEntry>> LogFile(string file)
{
if (file == NPath.Default)
if (file == SPath.Default)
{
return new FuncTask<List<GitLogEntry>>(cancellationToken, () => new List<GitLogEntry>(0));
return taskManager.With(() => new List<GitLogEntry>(0));
}
return new GitLogTask(file, new GitObjectFactory(environment), cancellationToken, processor)
return new GitLogTask(taskManager, processEnvironment, environment, new GitObjectFactory(environment), file, token: Token)
.Configure(processManager)
.Catch(exception => exception is ProcessException &&
exception.Message.StartsWith("fatal: your current branch") &&
exception.Message.EndsWith("does not have any commits yet"))
.Then((success, list) => success ? list : new List<GitLogEntry>());
.Then((success, _, list) => success ? list : new List<GitLogEntry>());
}
///<inheritdoc/>
public ITask<TheVersion> Version(IOutputProcessor<TheVersion> processor = null)
public ITask<TheVersion> Version()
{
return new GitVersionTask(cancellationToken, processor)
return new GitVersionTask(taskManager, processEnvironment, environment, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<TheVersion> LfsVersion(IOutputProcessor<TheVersion> processor = null)
public ITask<TheVersion> LfsVersion()
{
return new GitLfsVersionTask(cancellationToken, processor)
return new GitLfsVersionTask(taskManager, processEnvironment, environment, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<int> CountObjects(IOutputProcessor<int> processor = null)
public ITask<int> CountObjects()
{
return new GitCountObjectsTask(cancellationToken, processor)
return new GitCountObjectsTask(taskManager, processEnvironment, environment, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> GetConfig(string key, GitConfigSource configSource, IOutputProcessor<string> processor = null)
public ITask<string> GetConfig(string key, GitConfigSource configSource)
{
return new GitConfigGetTask(key, configSource, cancellationToken, processor)
return new GitConfigGetTask(taskManager, processEnvironment, environment, key, configSource, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> SetConfig(string key, string value, GitConfigSource configSource, IOutputProcessor<string> processor = null)
public ITask<string> SetConfig(string key, string value, GitConfigSource configSource)
{
return new GitConfigSetTask(key, value, configSource, cancellationToken, processor)
return new GitConfigSetTask(taskManager, processEnvironment, environment, key, value, configSource, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> UnSetConfig(string key, GitConfigSource configSource, IOutputProcessor<string> processor = null)
public ITask<string> UnSetConfig(string key, GitConfigSource configSource)
{
return new GitConfigUnSetTask(key, configSource, cancellationToken, processor)
return new GitConfigUnSetTask(taskManager, processEnvironment, environment, key, configSource, Token)
.Configure(processManager);
}
@ -450,21 +467,20 @@ namespace Unity.VersionControl.Git
string email = null;
return GetConfig(UserNameConfigKey, GitConfigSource.User)
.Then((success, value) => {
.Then((success, _, value) => {
if (success)
{
username = value;
}
})
.Then(GetConfig(UserEmailConfigKey, GitConfigSource.User)
.Then((success, value) => {
.Then((success, _, value) => {
if (success)
{
email = value;
}
})).Then(success => {
return new GitUser(username, email);
});
}))
.Then(() => new GitUser(username, email));
}
///<inheritdoc/>
@ -476,119 +492,110 @@ namespace Unity.VersionControl.Git
}
///<inheritdoc/>
public ITask<List<GitLock>> ListLocks(bool local, BaseOutputListProcessor<GitLock> processor = null)
public ITask<List<GitLock>> ListLocks(bool local)
{
return new GitListLocksTask(local, cancellationToken, processor)
return new GitListLocksTask(taskManager, processEnvironment, environment, local, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> Pull(string remote, string branch, IOutputProcessor<string> processor = null)
public ITask<string> Pull(string remote, string branch)
{
return new GitPullTask(remote, branch, cancellationToken, processor)
return new GitPullTask(taskManager, processEnvironment, environment, remote, branch, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> Push(string remote, string branch,
IOutputProcessor<string> processor = null)
public ITask<string> Push(string remote, string branch)
{
return new GitPushTask(remote, branch, true, cancellationToken, processor)
return new GitPushTask(taskManager, processEnvironment, environment, remote, branch, true, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> Revert(string changeset, IOutputProcessor<string> processor = null)
public ITask<string> Revert(string changeset)
{
return new GitRevertTask(changeset, cancellationToken, processor)
return new GitRevertTask(taskManager, processEnvironment, environment, changeset, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> Reset(string changeset, GitResetMode resetMode = GitResetMode.NonSpecified, IOutputProcessor<string> processor = null)
public ITask<string> Reset(string changeset, GitResetMode resetMode = GitResetMode.NonSpecified)
{
return new GitResetTask(changeset, resetMode, cancellationToken, processor)
return new GitResetTask(taskManager, processEnvironment, environment, changeset, resetMode, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> Fetch(string remote,
IOutputProcessor<string> processor = null)
public ITask<string> Fetch(string remote)
{
return new GitFetchTask(remote, cancellationToken, processor: processor)
return new GitFetchTask(taskManager, processEnvironment, environment, remote, token: Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> SwitchBranch(string branch, IOutputProcessor<string> processor = null)
public ITask<string> SwitchBranch(string branch)
{
return new GitSwitchBranchesTask(branch, cancellationToken, processor)
return new GitSwitchBranchesTask(taskManager, processEnvironment, environment, branch, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> DeleteBranch(string branch, bool deleteUnmerged = false,
IOutputProcessor<string> processor = null)
public ITask<string> DeleteBranch(string branch, bool deleteUnmerged = false)
{
return new GitBranchDeleteTask(branch, deleteUnmerged, cancellationToken, processor)
return new GitBranchDeleteTask(taskManager, processEnvironment, environment, branch, deleteUnmerged, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> CreateBranch(string branch, string baseBranch,
IOutputProcessor<string> processor = null)
public ITask<string> CreateBranch(string branch, string baseBranch)
{
return new GitBranchCreateTask(branch, baseBranch, cancellationToken, processor)
return new GitBranchCreateTask(taskManager, processEnvironment, environment, branch, baseBranch, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> RemoteAdd(string remote, string url,
IOutputProcessor<string> processor = null)
public ITask<string> RemoteAdd(string remote, string url)
{
return new GitRemoteAddTask(remote, url, cancellationToken, processor)
return new GitRemoteAddTask(taskManager, processEnvironment, environment, remote, url, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> RemoteRemove(string remote,
IOutputProcessor<string> processor = null)
public ITask<string> RemoteRemove(string remote)
{
return new GitRemoteRemoveTask(remote, cancellationToken, processor)
return new GitRemoteRemoveTask(taskManager, processEnvironment, environment, remote, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> RemoteChange(string remote, string url,
IOutputProcessor<string> processor = null)
public ITask<string> RemoteChange(string remote, string url)
{
return new GitRemoteChangeTask(remote, url, cancellationToken, processor)
return new GitRemoteChangeTask(taskManager, processEnvironment, environment, remote, url, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> Commit(string message, string body,
IOutputProcessor<string> processor = null)
public ITask<string> Commit(string message, string body)
{
return new GitCommitTask(message, body, cancellationToken, processor)
return new GitCommitTask(taskManager, processEnvironment, environment, message, body, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> AddAll(IOutputProcessor<string> processor = null)
public ITask<string> AddAll()
{
return new GitAddTask(cancellationToken, processor)
return new GitAddTask(taskManager, processEnvironment, environment, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> Add(IList<string> files,
IOutputProcessor<string> processor = null)
public ITask<string> Add(IList<string> files)
{
GitAddTask last = null;
foreach (var batch in files.Spool(SpoolLength))
{
var current = new GitAddTask(batch, cancellationToken, processor).Configure(processManager);
var current = new GitAddTask(taskManager, processEnvironment, environment, batch, Token).Configure(processManager);
if (last == null)
{
last = current;
@ -604,13 +611,12 @@ namespace Unity.VersionControl.Git
}
///<inheritdoc/>
public ITask<string> Discard(IList<string> files,
IOutputProcessor<string> processor = null)
public ITask<string> Discard(IList<string> files)
{
GitCheckoutTask last = null;
foreach (var batch in files.Spool(SpoolLength))
{
var current = new GitCheckoutTask(batch, cancellationToken, processor).Configure(processManager);
var current = new GitCheckoutTask(taskManager, processEnvironment, environment, batch, Token).Configure(processManager);
if (last == null)
{
last = current;
@ -626,19 +632,19 @@ namespace Unity.VersionControl.Git
}
///<inheritdoc/>
public ITask<string> DiscardAll(IOutputProcessor<string> processor = null)
public ITask<string> DiscardAll()
{
return new GitCheckoutTask(cancellationToken, processor)
return new GitCheckoutTask(taskManager, processEnvironment, environment, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> Clean(IList<string> files, IOutputProcessor<string> processor = null)
public ITask<string> Clean(IList<string> files)
{
GitCleanTask last = null;
foreach (var batch in files.Spool(SpoolLength))
{
var current = new GitCleanTask(batch, cancellationToken, processor).Configure(processManager);
var current = new GitCleanTask(taskManager, processEnvironment, environment, batch, Token).Configure(processManager);
if (last == null)
{
last = current;
@ -654,27 +660,26 @@ namespace Unity.VersionControl.Git
}
///<inheritdoc/>
public ITask<string> CleanAll(IOutputProcessor<string> processor = null)
public ITask<string> CleanAll()
{
return new GitCleanTask(cancellationToken, processor)
return new GitCleanTask(taskManager, processEnvironment, environment, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> CheckoutVersion(string changeset, IList<string> files, IOutputProcessor<string> processor = null)
public ITask<string> CheckoutVersion(string changeset, IList<string> files)
{
return new GitCheckoutTask(changeset, files, cancellationToken, processor)
return new GitCheckoutTask(taskManager, processEnvironment, environment, changeset, files, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> Remove(IList<string> files,
IOutputProcessor<string> processor = null)
public ITask<string> Remove(IList<string> files)
{
GitRemoveFromIndexTask last = null;
foreach (var batch in files.Spool(SpoolLength))
{
var current = new GitRemoveFromIndexTask(batch, cancellationToken, processor).Configure(processManager);
var current = new GitRemoveFromIndexTask(taskManager, processEnvironment, environment, batch, Token).Configure(processManager);
if (last == null)
{
last = current;
@ -690,39 +695,42 @@ namespace Unity.VersionControl.Git
}
///<inheritdoc/>
public ITask<string> AddAndCommit(IList<string> files, string message, string body,
IOutputProcessor<string> processor = null)
public ITask<string> AddAndCommit(IList<string> files, string message, string body)
{
return Add(files)
.Then(new GitCommitTask(message, body, cancellationToken)
.Then(new GitCommitTask(taskManager, processEnvironment, environment, message, body, Token)
.Configure(processManager));
}
///<inheritdoc/>
public ITask<string> Lock(NPath file,
IOutputProcessor<string> processor = null)
public ITask<string> Lock(SPath file)
{
return new GitLockTask(file, cancellationToken, processor)
return new GitLockTask(taskManager, processEnvironment, environment, file, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> Unlock(NPath file, bool force,
IOutputProcessor<string> processor = null)
public ITask<string> Unlock(SPath file, bool force)
{
return new GitUnlockTask(file, force, cancellationToken, processor)
return new GitUnlockTask(taskManager, processEnvironment, environment, file, force, Token)
.Configure(processManager);
}
///<inheritdoc/>
public ITask<string> GetHead(IOutputProcessor<string> processor = null)
public ITask<string> GetHead()
{
return new FirstNonNullLineProcessTask(cancellationToken, "rev-parse --short HEAD") { Name = "Getting current head..." }
.Configure(processManager)
.Catch(exception => exception is ProcessException &&
exception.Message.StartsWith("fatal: your current branch") &&
exception.Message.EndsWith("does not have any commits yet"))
.Then((success, head) => success ? head : null);
return new NativeProcessTask<string>(taskManager, processEnvironment, environment.GitExecutablePath, "rev-parse --short HEAD",
new FirstNonNullOutputProcessor<string>(), Token) { Name = "Getting current head..." }
.Configure(processManager)
.Catch(exception =>
exception is ProcessException &&
exception.Message.StartsWith(
"fatal: your current branch") &&
exception.Message.EndsWith(
"does not have any commits yet"))
.Then((success, _, head) =>
success ? head : null);
}
protected static ILogging Logger { get; } = LogHelper.GetLogger<GitClient>();

Просмотреть файл

@ -6,6 +6,8 @@ using System.Text.RegularExpressions;
namespace Unity.VersionControl.Git
{
using IO;
[Serializable]
public struct ConfigRemote
{
@ -176,7 +178,7 @@ namespace Unity.VersionControl.Git
public GitConfig(string filePath)
{
manager = new ConfigFileManager(filePath.ToNPath());
manager = new ConfigFileManager(filePath.ToSPath());
Reset();
}
@ -467,7 +469,7 @@ namespace Unity.VersionControl.Git
{
private static readonly string[] emptyContents = new string[0];
public ConfigFileManager(NPath filePath)
public ConfigFileManager(SPath filePath)
{
FilePath = filePath;
}
@ -508,7 +510,7 @@ namespace Unity.VersionControl.Git
return WriteAllText(contents);
}
public NPath FilePath { get; private set; }
public SPath FilePath { get; private set; }
public string[] Lines { get; private set; }
}
}

Просмотреть файл

@ -2,10 +2,13 @@ using Unity.VersionControl.Git;
using System;
using System.Collections.Generic;
using System.Linq;
using Unity.Editor.Tasks;
using Unity.VersionControl.Git.Tasks;
namespace Unity.VersionControl.Git
{
using IO;
public class GitCredentialManager : ICredentialManager
{
private static ILogging Logger { get; } = LogHelper.GetLogger<GitCredentialManager>();
@ -143,7 +146,7 @@ namespace Unity.VersionControl.Git
if (credHelper.StartsWith('!'))
{
// it's a separate app, run it as such
task = new SimpleProcessTask(taskManager.Token, credHelper.Substring(1).ToNPath(), action);
task = new SimpleProcessTask(taskManager.Token, credHelper.Substring(1).ToSPath(), action);
}
else
{

Просмотреть файл

@ -4,6 +4,8 @@ using Unity.VersionControl.Git;
namespace Unity.VersionControl.Git
{
using IO;
[Serializable]
public struct GitLock
{
@ -33,11 +35,11 @@ namespace Unity.VersionControl.Git
}
}
[NotSerialized] public string ID => id ?? String.Empty;
[NotSerialized] public NPath Path => path?.ToNPath() ?? NPath.Default;
[NotSerialized] public SPath Path => path?.ToSPath() ?? SPath.Default;
[NotSerialized] public GitUser Owner => owner;
[NotSerialized] public DateTimeOffset LockedAt => locked_at;
public GitLock(string id, NPath path, GitUser owner, DateTimeOffset locked_at)
public GitLock(string id, SPath path, GitUser owner, DateTimeOffset locked_at)
{
this.id = id;
this.path = path.IsInitialized ? path.ToString() : null;

Просмотреть файл

@ -3,22 +3,24 @@ using Unity.VersionControl.Git;
namespace Unity.VersionControl.Git
{
using IO;
public class GitObjectFactory : IGitObjectFactory
{
private readonly IEnvironment environment;
private readonly IGitEnvironment environment;
public GitObjectFactory(IEnvironment environment)
public GitObjectFactory(IGitEnvironment environment)
{
this.environment = environment;
}
public GitStatusEntry CreateGitStatusEntry(string path, GitFileStatus indexStatus, GitFileStatus workTreeStatus = GitFileStatus.None, string originalPath = null)
{
var absolutePath = new NPath(path).MakeAbsolute();
var absolutePath = new SPath(path).MakeAbsolute();
var relativePath = absolutePath.RelativeTo(environment.RepositoryPath);
var projectPath = absolutePath.RelativeTo(environment.UnityProjectPath);
var projectPath = absolutePath.RelativeTo(environment.UnityProjectPath.ToSPath());
return new GitStatusEntry(relativePath, absolutePath, projectPath, indexStatus, workTreeStatus, originalPath?.ToNPath());
return new GitStatusEntry(relativePath, absolutePath, projectPath, indexStatus, workTreeStatus, originalPath?.ToSPath());
}
}
}

Просмотреть файл

@ -1,8 +1,12 @@
using System;
using System.Collections.Generic;
using Unity.Editor.Tasks;
using Unity.Editor.Tasks.Helpers;
namespace Unity.VersionControl.Git
{
using IO;
/// <summary>
/// Represents a repository, either local or retrieved via the GitHub API.
/// </summary>
@ -18,8 +22,8 @@ namespace Unity.VersionControl.Git
ITask Push();
ITask Fetch();
ITask Revert(string changeset);
ITask RequestLock(NPath file);
ITask ReleaseLock(NPath file, bool force);
ITask RequestLock(SPath file);
ITask ReleaseLock(SPath file, bool force);
ITask DiscardChanges(GitStatusEntry[] discardEntries);
ITask CheckoutVersion(string changeset, IList<string> files);
@ -41,7 +45,7 @@ namespace Unity.VersionControl.Git
/// <summary>
/// Gets the local path of the repository.
/// </summary>
NPath LocalPath { get; }
SPath LocalPath { get; }
bool IsGitHub { get; }
/// <summary>
/// Gets the current remote of the repository.

Просмотреть файл

@ -1,12 +1,15 @@
using Unity.VersionControl.Git;
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using Unity.Editor.Tasks;
using Unity.Editor.Tasks.Helpers;
namespace Unity.VersionControl.Git
{
using IO;
public interface IBackedByCache
{
void CheckAndRaiseEventsIfCacheNewer(CacheType cacheType, CacheUpdateEvent cacheUpdateEvent);
@ -49,7 +52,7 @@ namespace Unity.VersionControl.Git
/// </summary>
/// <param name="localPath"></param>
/// <param name="container"></param>
public Repository(NPath localPath, ICacheContainer container)
public Repository(SPath localPath, ICacheContainer container)
{
Guard.ArgumentNotNull(localPath, nameof(localPath));
@ -142,8 +145,8 @@ namespace Unity.VersionControl.Git
public ITask Push() => repositoryManager.Push(CurrentRemote.Value.Name, CurrentBranch?.Name);
public ITask Fetch() => repositoryManager.Fetch(CurrentRemote.Value.Name);
public ITask Revert(string changeset) => repositoryManager.Revert(changeset);
public ITask RequestLock(NPath file) => repositoryManager.LockFile(file);
public ITask ReleaseLock(NPath file, bool force) => repositoryManager.UnlockFile(file, force);
public ITask RequestLock(SPath file) => repositoryManager.LockFile(file);
public ITask ReleaseLock(SPath file, bool force) => repositoryManager.UnlockFile(file, force);
public ITask DiscardChanges(GitStatusEntry[] gitStatusEntry) => repositoryManager.DiscardChanges(gitStatusEntry);
public ITask CheckoutVersion(string changeset, IList<string> files) => repositoryManager.CheckoutVersion(changeset, files);
public ITask RemoteAdd(string remote, string url) => repositoryManager.RemoteAdd(remote, url);
@ -427,7 +430,7 @@ namespace Unity.VersionControl.Git
private set { name = value; }
}
public NPath LocalPath { get; private set; }
public SPath LocalPath { get; private set; }
public string Owner => CloneUrl?.Owner ?? null;
public bool IsGitHub => HostAddress.IsGitHubDotCom(CloneUrl);
public bool IsBusy => repositoryManager?.IsBusy ?? false;
@ -481,18 +484,16 @@ namespace Unity.VersionControl.Git
public void SetNameAndEmail(string name, string email)
{
gitClient.SetConfigNameAndEmail(name, email)
.ThenInUI((success, value) => {
if (success)
{
Name = value.Name;
Email = value.Email;
}
}).Start();
.ThenInUI(value => {
Name = value.Name;
Email = value.Email;
})
.Start();
}
public override string ToString()
{
return String.Format("Name: {0} Email: {1}", Name, Email);
return string.Format("Name: {0} Email: {1}", Name, Email);
}
private void CacheHasBeenUpdated(DateTimeOffset timeOffset)
@ -520,13 +521,10 @@ namespace Unity.VersionControl.Git
gitClient.GetConfigUserAndEmail()
.Catch(InvalidationFailed)
.ThenInUI((success, value) =>
.ThenInUI(value =>
{
if (success)
{
Name = value.Name;
Email = value.Email;
}
Name = value.Name;
Email = value.Email;
}).Start();
}

Просмотреть файл

@ -2,10 +2,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Unity.VersionControl.Git;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git
{
using IO;
public interface IRepositoryManager : IDisposable
{
event Action<bool> IsBusyChanged;
@ -35,8 +37,8 @@ namespace Unity.VersionControl.Git
ITask SwitchBranch(string branch);
ITask DeleteBranch(string branch, bool deleteUnmerged = false);
ITask CreateBranch(string branch, string baseBranch);
ITask LockFile(NPath file);
ITask UnlockFile(NPath file, bool force);
ITask LockFile(SPath file);
ITask UnlockFile(SPath file, bool force);
ITask DiscardChanges(GitStatusEntry[] gitStatusEntries);
ITask CheckoutVersion(string changeset, IList<string> files);
ITask UpdateGitLog();
@ -57,37 +59,37 @@ namespace Unity.VersionControl.Git
public interface IRepositoryPathConfiguration
{
NPath RepositoryPath { get; }
NPath DotGitPath { get; }
NPath BranchesPath { get; }
NPath RemotesPath { get; }
NPath DotGitIndex { get; }
NPath DotGitHead { get; }
NPath DotGitConfig { get; }
NPath WorktreeDotGitPath { get; }
SPath RepositoryPath { get; }
SPath DotGitPath { get; }
SPath BranchesPath { get; }
SPath RemotesPath { get; }
SPath DotGitIndex { get; }
SPath DotGitHead { get; }
SPath DotGitConfig { get; }
SPath WorktreeDotGitPath { get; }
bool IsWorktree { get; }
}
public class RepositoryPathConfiguration : IRepositoryPathConfiguration
{
public RepositoryPathConfiguration(NPath repositoryPath)
public RepositoryPathConfiguration(SPath repositoryPath)
{
RepositoryPath = repositoryPath;
WorktreeDotGitPath = NPath.Default;
WorktreeDotGitPath = SPath.Default;
DotGitPath = repositoryPath.Combine(".git");
NPath commonPath;
SPath commonPath;
if (DotGitPath.FileExists())
{
DotGitPath =
DotGitPath.ReadAllLines()
.Where(x => x.StartsWith("gitdir:"))
.Select(x => x.Substring(7).Trim().ToNPath())
.Select(x => x.Substring(7).Trim().ToSPath())
.First();
if (DotGitPath.Combine("commondir").FileExists())
{
commonPath = DotGitPath.Combine("commondir").ReadAllLines()
.Select(x => x.Trim().ToNPath())
.Select(x => x.Trim().ToSPath())
.First();
commonPath = DotGitPath.Combine(commonPath);
@ -113,15 +115,15 @@ namespace Unity.VersionControl.Git
}
public bool IsWorktree { get; }
public NPath RepositoryPath { get; }
public NPath WorktreeDotGitPath { get; }
public NPath DotGitPath { get; }
public NPath BranchesPath { get; }
public NPath RemotesPath { get; }
public NPath DotGitIndex { get; }
public NPath DotGitHead { get; }
public NPath DotGitConfig { get; }
public NPath DotGitCommitEditMsg { get; }
public SPath RepositoryPath { get; }
public SPath WorktreeDotGitPath { get; }
public SPath DotGitPath { get; }
public SPath BranchesPath { get; }
public SPath RemotesPath { get; }
public SPath DotGitIndex { get; }
public SPath DotGitHead { get; }
public SPath DotGitConfig { get; }
public SPath DotGitCommitEditMsg { get; }
}
public class RepositoryManager : IRepositoryManager
@ -129,8 +131,9 @@ namespace Unity.VersionControl.Git
private readonly IGitConfig config;
private readonly IGitClient gitClient;
private readonly IRepositoryPathConfiguration repositoryPaths;
private readonly CancellationToken token;
private readonly IRepositoryWatcher watcher;
private readonly CancellationTokenSource cts;
private readonly ITaskManager taskManager;
private bool isBusy;
@ -146,14 +149,15 @@ namespace Unity.VersionControl.Git
public event Action<CacheType> DataNeedsRefreshing;
public RepositoryManager(IGitConfig gitConfig,
public RepositoryManager(ITaskManager taskManager,
IGitConfig gitConfig,
IRepositoryWatcher repositoryWatcher,
IGitClient gitClient,
CancellationToken token,
IRepositoryPathConfiguration repositoryPaths)
{
this.taskManager = taskManager;
cts = CancellationTokenSource.CreateLinkedTokenSource(taskManager.Token);
this.repositoryPaths = repositoryPaths;
this.token = token;
this.gitClient = gitClient;
this.watcher = repositoryWatcher;
this.config = gitConfig;
@ -168,7 +172,7 @@ namespace Unity.VersionControl.Git
}
public static RepositoryManager CreateInstance(IPlatform platform, ITaskManager taskManager, IGitClient gitClient,
NPath repositoryRoot)
SPath repositoryRoot)
{
var repositoryPathConfiguration = new RepositoryPathConfiguration(repositoryRoot);
string filePath = repositoryPathConfiguration.DotGitConfig;
@ -176,9 +180,8 @@ namespace Unity.VersionControl.Git
var repositoryWatcher = new RepositoryWatcher(platform, repositoryPathConfiguration, taskManager.Token);
return new RepositoryManager(gitConfig, repositoryWatcher,
gitClient,
taskManager.Token, repositoryPathConfiguration);
return new RepositoryManager(taskManager, gitConfig, repositoryWatcher,
gitClient, repositoryPathConfiguration);
}
public void Initialize()
@ -291,14 +294,14 @@ namespace Unity.VersionControl.Git
return HookupHandlers(task, false);
}
public ITask LockFile(NPath file)
public ITask LockFile(SPath file)
{
var task = GitClient.Lock(file)
.Then(() => DataNeedsRefreshing?.Invoke(CacheType.GitLocks));
return HookupHandlers(task, false);
}
public ITask UnlockFile(NPath file, bool force)
public ITask UnlockFile(SPath file, bool force)
{
var task = GitClient.Unlock(file, force)
.Then(() => DataNeedsRefreshing?.Invoke(CacheType.GitLocks));
@ -310,16 +313,16 @@ namespace Unity.VersionControl.Git
Guard.ArgumentNotNullOrEmpty(gitStatusEntries, "gitStatusEntries");
ActionTask<GitStatusEntry[]> task = null;
task = new ActionTask<GitStatusEntry[]>(token, (_, entries) =>
task = new ActionTask<GitStatusEntry[]>(taskManager, entries =>
{
var itemsToDelete = new List<NPath>();
var itemsToDelete = new List<SPath>();
var itemsToRevert = new List<string>();
foreach (var gitStatusEntry in gitStatusEntries)
{
if (gitStatusEntry.WorkTreeStatus == GitFileStatus.Added || gitStatusEntry.WorkTreeStatus == GitFileStatus.Untracked)
{
itemsToDelete.Add(gitStatusEntry.path.ToNPath().MakeAbsolute());
itemsToDelete.Add(gitStatusEntry.path.ToSPath().MakeAbsolute());
}
else
{
@ -356,12 +359,9 @@ namespace Unity.VersionControl.Git
public ITask UpdateGitLog()
{
var task = GitClient.Log()
.Then((success, logEntries) =>
.Then(logEntries =>
{
if (success)
{
GitLogUpdated?.Invoke(logEntries);
}
GitLogUpdated?.Invoke(logEntries);
});
return HookupHandlers(task, false);
}
@ -369,13 +369,10 @@ namespace Unity.VersionControl.Git
public ITask UpdateFileLog(string path)
{
var task = GitClient.LogFile(path)
.Then((success, logEntries) =>
.Then(logEntries =>
{
if (success)
{
var gitFileLog = new GitFileLog(path, logEntries);
GitFileLogUpdated?.Invoke(gitFileLog);
}
var gitFileLog = new GitFileLog(path, logEntries);
GitFileLogUpdated?.Invoke(gitFileLog);
});
return HookupHandlers(task, false);
}
@ -383,12 +380,9 @@ namespace Unity.VersionControl.Git
public ITask UpdateGitStatus()
{
var task = GitClient.Status()
.Then((success, status) =>
.Then(status =>
{
if (success)
{
GitStatusUpdated?.Invoke(status);
}
GitStatusUpdated?.Invoke(status);
});
return HookupHandlers(task, false);
}
@ -399,12 +393,9 @@ namespace Unity.VersionControl.Git
ConfigRemote? configRemote;
GetCurrentBranchAndRemote(out configBranch, out configRemote);
var updateTask = new ActionTask<GitAheadBehindStatus>(token, (success, status) =>
var updateTask = new ActionTask<GitAheadBehindStatus>(taskManager, status =>
{
if (success)
{
GitAheadBehindStatusUpdated?.Invoke(status);
}
GitAheadBehindStatusUpdated?.Invoke(status);
});
if (configBranch.HasValue && configBranch.Value.Remote.HasValue)
{
@ -425,12 +416,9 @@ namespace Unity.VersionControl.Git
public ITask UpdateLocks()
{
var task = GitClient.ListLocks(false)
.Then((success, locks) =>
.Then(locks =>
{
if (success)
{
GitLocksUpdated?.Invoke(locks);
}
GitLocksUpdated?.Invoke(locks);
});
return HookupHandlers(task, false);
@ -438,7 +426,7 @@ namespace Unity.VersionControl.Git
public ITask UpdateBranches()
{
var task = new ActionTask(token, () =>
var task = new ActionTask(taskManager, () =>
{
UpdateLocalBranches();
UpdateRemoteBranches();
@ -449,7 +437,7 @@ namespace Unity.VersionControl.Git
public ITask UpdateRepositoryInfo()
{
var task = new ActionTask(token, () =>
var task = new ActionTask(taskManager, () =>
{
ConfigBranch? branch;
ConfigRemote? remote;
@ -610,7 +598,7 @@ namespace Unity.VersionControl.Git
LocalBranchesUpdated?.Invoke(branches);
}
private void UpdateLocalBranches(Dictionary<string, ConfigBranch> branches, NPath path, IEnumerable<ConfigBranch> configBranches, string prefix)
private void UpdateLocalBranches(Dictionary<string, ConfigBranch> branches, SPath path, IEnumerable<ConfigBranch> configBranches, string prefix)
{
foreach (var file in path.Files())
{

Просмотреть файл

@ -1,15 +1,22 @@
using System.Collections.Generic;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitAddTask : ProcessTask<string>
using IO;
public class GitAddTask : NativeProcessTask<string>
{
private const string TaskName = "git add";
private readonly string arguments;
public GitAddTask(IEnumerable<string> files, CancellationToken token,
IOutputProcessor<string> processor = null) : base(token, processor ?? new SimpleOutputProcessor())
public GitAddTask(ITaskManager taskManager,
IProcessEnvironment processEnvironment,
IGitEnvironment environment,
IEnumerable<string> files,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Guard.ArgumentNotNull(files, "files");
Name = TaskName;
@ -19,12 +26,14 @@ namespace Unity.VersionControl.Git.Tasks
foreach (var file in files)
{
arguments += " \"" + file.ToNPath().ToString(SlashMode.Forward) + "\"";
arguments += " \"" + file.ToSPath().ToString(SlashMode.Forward) + "\"";
}
}
public GitAddTask(CancellationToken token,
IOutputProcessor<string> processor = null) : base(token, processor ?? new SimpleOutputProcessor())
public GitAddTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
arguments = "add -A";
}

Просмотреть файл

@ -1,15 +1,18 @@
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitAheadBehindStatusTask : ProcessTask<GitAheadBehindStatus>
public class GitAheadBehindStatusTask : NativeProcessTask<GitAheadBehindStatus>
{
private const string TaskName = "git rev-list";
private readonly string arguments;
public GitAheadBehindStatusTask(string gitRef, string otherRef,
CancellationToken token, IOutputProcessor<GitAheadBehindStatus> processor = null)
: base(token, processor ?? new GitAheadBehindStatusOutputProcessor())
public GitAheadBehindStatusTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string gitRef, string otherRef,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new GitAheadBehindStatusOutputProcessor(), token: token)
{
Name = TaskName;
arguments = $"rev-list --left-right --count {gitRef}...{otherRef}";

Просмотреть файл

@ -1,16 +1,20 @@
using System;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitBranchCreateTask : ProcessTask<string>
public class GitBranchCreateTask : NativeProcessTask<string>
{
private const string TaskName = "git branch";
private readonly string arguments;
public GitBranchCreateTask(string newBranch, string baseBranch,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitBranchCreateTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string newBranch, string baseBranch,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Guard.ArgumentNotNullOrWhiteSpace(newBranch, "newBranch");
Guard.ArgumentNotNullOrWhiteSpace(baseBranch, "baseBranch");

Просмотреть файл

@ -1,15 +1,18 @@
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitBranchDeleteTask : ProcessTask<string>
public class GitBranchDeleteTask : NativeProcessTask<string>
{
private const string TaskName = "git branch -d";
private readonly string arguments;
public GitBranchDeleteTask(string branch, bool deleteUnmerged,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitBranchDeleteTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string branch, bool deleteUnmerged,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Guard.ArgumentNotNullOrWhiteSpace(branch, "branch");
Name = TaskName;

Просмотреть файл

@ -1,15 +1,21 @@
using System.Collections.Generic;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitCheckoutTask : ProcessTask<string>
using IO;
public class GitCheckoutTask : NativeProcessTask<string>
{
private const string TaskName = "git checkout";
private readonly string arguments;
public GitCheckoutTask(IEnumerable<string> files, CancellationToken token,
IOutputProcessor<string> processor = null) : base(token, processor ?? new SimpleOutputProcessor())
public GitCheckoutTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
IEnumerable<string> files,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Guard.ArgumentNotNull(files, "files");
Name = TaskName;
@ -19,21 +25,25 @@ namespace Unity.VersionControl.Git.Tasks
foreach (var file in files)
{
arguments += " \"" + file.ToNPath().ToString(SlashMode.Forward) + "\"";
arguments += " \"" + file.ToSPath().ToString(SlashMode.Forward) + "\"";
}
}
public GitCheckoutTask(CancellationToken token,
IOutputProcessor<string> processor = null) : base(token, processor ?? new SimpleOutputProcessor())
public GitCheckoutTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
arguments = "checkout -- .";
}
public GitCheckoutTask(
ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string changeset,
IEnumerable<string> files,
CancellationToken token,
IOutputProcessor<string> processor = null) : base(token, processor ?? new SimpleOutputProcessor())
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Guard.ArgumentNotNull(files, "files");
Name = TaskName;
@ -44,10 +54,10 @@ namespace Unity.VersionControl.Git.Tasks
foreach (var file in files)
{
arguments += " \"" + file.ToNPath().ToString(SlashMode.Forward) + "\"";
arguments += " \"" + file.ToSPath().ToString(SlashMode.Forward) + "\"";
}
Message = "Checking out files at rev " + changeset.Substring(0, 7);
Message = "Checking out files at rev " + changeset.Substring(0, 7);
}
public override string ProcessArguments { get { return arguments; } }

Просмотреть файл

@ -1,15 +1,21 @@
using System.Collections.Generic;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitCleanTask : ProcessTask<string>
using IO;
public class GitCleanTask : NativeProcessTask<string>
{
private const string TaskName = "git clean";
private readonly string arguments;
public GitCleanTask(IEnumerable<string> files, CancellationToken token,
IOutputProcessor<string> processor = null) : base(token, processor ?? new SimpleOutputProcessor())
public GitCleanTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
IEnumerable<string> files,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Guard.ArgumentNotNull(files, "files");
Name = TaskName;
@ -20,12 +26,14 @@ namespace Unity.VersionControl.Git.Tasks
foreach (var file in files)
{
arguments += " \"" + file.ToNPath().ToString(SlashMode.Forward) + "\"";
arguments += " \"" + file.ToSPath().ToString(SlashMode.Forward) + "\"";
}
}
public GitCleanTask(CancellationToken token,
IOutputProcessor<string> processor = null) : base(token, processor ?? new SimpleOutputProcessor())
public GitCleanTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
arguments = "clean ";
arguments += "-f";

Просмотреть файл

@ -1,9 +1,12 @@
using System;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitCommitTask : ProcessTask<string>
using IO;
public class GitCommitTask : NativeProcessTask<string>
{
private const string TaskName = "git commit";
@ -11,11 +14,13 @@ namespace Unity.VersionControl.Git.Tasks
private readonly string body;
private readonly string arguments;
private NPath tempFile;
private SPath tempFile;
public GitCommitTask(string message, string body,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitCommitTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string message, string body,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Guard.ArgumentNotNullOrWhiteSpace(message, "message");
@ -23,7 +28,7 @@ namespace Unity.VersionControl.Git.Tasks
this.body = body ?? string.Empty;
Name = TaskName;
tempFile = NPath.GetTempFilename("GitCommitTask");
tempFile = SPath.GetTempFilename("GitCommitTask");
arguments = $"-c i18n.commitencoding=utf8 commit --file \"{tempFile}\"";
}

Просмотреть файл

@ -1,16 +1,20 @@
using System;
using System.Collections.Generic;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitConfigGetAllTask : ProcessTaskWithListOutput<string>
public class GitConfigGetAllTask : NativeProcessListTask<string>
{
private const string TaskName = "git config get";
private readonly string arguments;
public GitConfigGetAllTask(string key, GitConfigSource configSource,
CancellationToken token, BaseOutputListProcessor<string> processor = null)
: base(token, processor ?? new SimpleListOutputProcessor())
public GitConfigGetAllTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string key, GitConfigSource configSource,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringListOutputProcessor(), token: token)
{
Guard.ArgumentNotNullOrWhiteSpace(key, nameof(key));
Name = TaskName;
@ -27,14 +31,16 @@ namespace Unity.VersionControl.Git.Tasks
public override TaskAffinity Affinity { get { return TaskAffinity.Concurrent; } }
}
class GitConfigGetTask : ProcessTask<string>
class GitConfigGetTask : NativeProcessTask<string>
{
private const string TaskName = "git config get";
private readonly string arguments;
public GitConfigGetTask(string key, GitConfigSource configSource,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new FirstNonNullLineOutputProcessor())
public GitConfigGetTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string key, GitConfigSource configSource,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new FirstNonNullOutputProcessor<string>(), token: token)
{
Name = TaskName;
var source = "";

Просмотреть файл

@ -1,16 +1,20 @@
using System;
using System.Collections.Generic;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitConfigListTask : ProcessTaskWithListOutput<KeyValuePair<string, string>>
public class GitConfigListTask : NativeProcessListTask<KeyValuePair<string, string>>
{
private const string TaskName = "git config list";
private readonly string arguments;
public GitConfigListTask(GitConfigSource configSource, CancellationToken token, BaseOutputListProcessor<KeyValuePair<string, string>> processor = null)
: base(token, processor ?? new ConfigOutputProcessor())
public GitConfigListTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
GitConfigSource configSource,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new ConfigOutputProcessor(), token: token)
{
Name = TaskName;
var source = "";

Просмотреть файл

@ -1,15 +1,18 @@
using System;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitConfigSetTask : ProcessTask<string>
public class GitConfigSetTask : NativeProcessTask<string>
{
private readonly string arguments;
public GitConfigSetTask(string key, string value, GitConfigSource configSource,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitConfigSetTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string key, string value, GitConfigSource configSource,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
var source = "";
source +=

Просмотреть файл

@ -1,15 +1,18 @@
using System;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitConfigUnSetTask : ProcessTask<string>
public class GitConfigUnSetTask : NativeProcessTask<string>
{
private readonly string arguments;
public GitConfigUnSetTask(string key, GitConfigSource configSource,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitConfigUnSetTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string key, GitConfigSource configSource,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
var source = "";
source +=

Просмотреть файл

@ -1,13 +1,16 @@
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitCountObjectsTask : ProcessTask<int>
public class GitCountObjectsTask : NativeProcessTask<int>
{
private const string TaskName = "git count-objects";
public GitCountObjectsTask(CancellationToken token, IOutputProcessor<int> processor = null)
: base(token, processor ?? new GitCountObjectsProcessor())
public GitCountObjectsTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new GitCountObjectsProcessor(), token: token)
{
Name = TaskName;
}

Просмотреть файл

@ -1,17 +1,20 @@
using System;
using System.Collections.Generic;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitFetchTask : ProcessTask<string>
public class GitFetchTask : NativeProcessTask<string>
{
private const string TaskName = "git fetch";
private readonly string arguments;
public GitFetchTask(string remote,
CancellationToken token, bool prune = true, bool tags = true, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitFetchTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string remote, bool prune = true, bool tags = true,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Name = TaskName;
var args = new List<string> { "fetch" };

Просмотреть файл

@ -1,19 +1,21 @@
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitInitTask : ProcessTask<string>
public class GitInitTask : NativeProcessTask<string>
{
private const string TaskName = "git init";
public GitInitTask(CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitInitTask(ITaskManager taskManager, IProcessEnvironment gitEnvironment,
IGitEnvironment environment,
CancellationToken token = default)
: base(taskManager, gitEnvironment, environment.GitExecutablePath, "init", outputProcessor: new StringOutputProcessor(), token: token)
{
Name = TaskName;
Affinity = TaskAffinity.Exclusive;
}
public override string ProcessArguments { get { return "init"; } }
public override TaskAffinity Affinity { get { return TaskAffinity.Exclusive; } }
public override string Message { get; set; } = "Initializing...";
}
}

Просмотреть файл

@ -1,13 +1,16 @@
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitLfsInstallTask : ProcessTask<string>
public class GitLfsInstallTask : NativeProcessTask<string>
{
private const string TaskName = "git lsf install";
public GitLfsInstallTask(CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitLfsInstallTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Name = TaskName;
}

Просмотреть файл

@ -1,13 +1,16 @@
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitLfsVersionTask : ProcessTask<TheVersion>
public class GitLfsVersionTask : NativeProcessTask<TheVersion>
{
private const string TaskName = "git lfs version";
public GitLfsVersionTask(CancellationToken token, IOutputProcessor<TheVersion> processor = null)
: base(token, processor ?? new LfsVersionOutputProcessor())
public GitLfsVersionTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new LfsVersionOutputProcessor(), token: token)
{
Name = TaskName;
}

Просмотреть файл

@ -1,14 +1,17 @@
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitListLocalBranchesTask : ProcessTaskWithListOutput<GitBranch>
public class GitListLocalBranchesTask : NativeProcessListTask<GitBranch>
{
private const string TaskName = "git list local branches";
private const string Arguments = "branch -vv";
public GitListLocalBranchesTask(CancellationToken token, BaseOutputListProcessor<GitBranch> processor = null)
: base(token, processor ?? new BranchListOutputProcessor())
public GitListLocalBranchesTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new BranchListOutputProcessor(), token: token)
{
Name = TaskName;
}
@ -23,8 +26,10 @@ namespace Unity.VersionControl.Git.Tasks
private const string TaskName = "git list remote branches";
private const string Arguments = "branch -vvr";
public GitListRemoteBranchesTask(CancellationToken token)
: base(token, new BranchListOutputProcessor())
public GitListRemoteBranchesTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new BranchListOutputProcessor(), token: token)
{
Name = TaskName;
}

Просмотреть файл

@ -1,16 +1,19 @@
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitListLocksTask : ProcessTaskWithListOutput<GitLock>
public class GitListLocksTask : NativeProcessListTask<GitLock>
{
private const string TaskName = "git lfs locks";
private readonly string args;
public GitListLocksTask(bool local,
CancellationToken token, BaseOutputListProcessor<GitLock> processor = null)
: base(token, processor ?? new LocksOutputProcessor())
public GitListLocksTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
bool local,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new LocksOutputProcessor(), token: token)
{
Name = TaskName;
args = "lfs locks --json";

Просмотреть файл

@ -1,21 +1,24 @@
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitLockTask : ProcessTask<string>
public class GitLockTask : NativeProcessTask<string>
{
private const string TaskName = "git lfs lock";
public GitLockTask(string path,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitLockTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string path,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Name = TaskName;
Guard.ArgumentNotNullOrWhiteSpace(path, "path");
ProcessArguments = $"lfs lock \"{path}\"";
}
public override string ProcessArguments { get; }
public override string ProcessArguments { get; protected set; }
public override TaskAffinity Affinity => TaskAffinity.Exclusive;
public override string Message { get; set; } = "Locking file...";
}

Просмотреть файл

@ -1,55 +1,49 @@
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitLogTask : ProcessTaskWithListOutput<GitLogEntry>
public class GitLogTask : NativeProcessListTask<GitLogEntry>
{
private const string TaskName = "git log";
private const string baseArguments = @"-c i18n.logoutputencoding=utf8 -c core.quotepath=false log --pretty=format:""%H%n%P%n%aN%n%aE%n%aI%n%cN%n%cE%n%cI%n%B---GHUBODYEND---"" --name-status";
private readonly string arguments;
public GitLogTask(IGitObjectFactory gitObjectFactory,
CancellationToken token,
BaseOutputListProcessor<GitLogEntry> processor = null)
: this(0, gitObjectFactory, token, processor)
{
}
public GitLogTask(string file,
public GitLogTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
IGitObjectFactory gitObjectFactory,
CancellationToken token, BaseOutputListProcessor<GitLogEntry> processor = null)
: this(file, 0, gitObjectFactory, token, processor)
{
}
int numberOfCommits,
CancellationToken token = default)
: this(taskManager, processEnvironment, environment, gitObjectFactory, null, numberOfCommits, token)
{}
public GitLogTask(int numberOfCommits, IGitObjectFactory gitObjectFactory,
CancellationToken token,
BaseOutputListProcessor<GitLogEntry> processor = null)
: base(token, processor ?? new LogEntryOutputProcessor(gitObjectFactory))
public GitLogTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
IGitObjectFactory gitObjectFactory,
string file,
CancellationToken token = default)
: this(taskManager, processEnvironment, environment, gitObjectFactory, file, 0, token)
{}
public GitLogTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
IGitObjectFactory gitObjectFactory,
string file = null, int numberOfCommits = 0,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new LogEntryOutputProcessor(gitObjectFactory), token: token)
{
Name = TaskName;
arguments = baseArguments;
if (numberOfCommits > 0)
arguments += " -n " + numberOfCommits;
}
public GitLogTask(string file, int numberOfCommits,
IGitObjectFactory gitObjectFactory,
CancellationToken token, BaseOutputListProcessor<GitLogEntry> processor = null)
: base(token, processor ?? new LogEntryOutputProcessor(gitObjectFactory))
{
Name = TaskName;
arguments = baseArguments;
if (numberOfCommits > 0)
arguments += " -n " + numberOfCommits;
arguments += " -- ";
arguments += " \"" + file + "\"";
}
public override string ProcessArguments
{
get { return arguments; }
if (file != null)
{
arguments += " -- ";
arguments += " \"" + file + "\"";
}
}
public override string ProcessArguments => arguments;
public override string Message { get; set; } = "Loading the history...";
}
}

Просмотреть файл

@ -1,17 +1,20 @@
using System;
using System.Text;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitPullTask : ProcessTask<string>
public class GitPullTask : NativeProcessTask<string>
{
private const string TaskName = "git pull";
private readonly string arguments;
public GitPullTask(string remote, string branch,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitPullTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string remote, string branch,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Name = TaskName;
var stringBuilder = new StringBuilder();

Просмотреть файл

@ -1,23 +1,28 @@
using System;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitPushTask : ProcessTask<string>
public class GitPushTask : NativeProcessTask<string>
{
private const string TaskName = "git push";
private readonly string arguments;
public GitPushTask(CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitPushTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Name = TaskName;
arguments = "push";
}
public GitPushTask(string remote, string branch, bool setUpstream,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitPushTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string remote, string branch, bool setUpstream,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Guard.ArgumentNotNullOrWhiteSpace(remote, "remote");
Guard.ArgumentNotNullOrWhiteSpace(branch, "branch");

Просмотреть файл

@ -1,16 +1,19 @@
using System;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitRemoteAddTask : ProcessTask<string>
public class GitRemoteAddTask : NativeProcessTask<string>
{
private const string TaskName = "git remote add";
private readonly string arguments;
public GitRemoteAddTask(string remote, string url,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitRemoteAddTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string remote, string url,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Guard.ArgumentNotNullOrWhiteSpace(remote, "remote");
Guard.ArgumentNotNullOrWhiteSpace(url, "url");

Просмотреть файл

@ -1,16 +1,19 @@
using System;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitRemoteBranchDeleteTask : ProcessTask<string>
public class GitRemoteBranchDeleteTask : NativeProcessTask<string>
{
private const string TaskName = "git push --delete";
private readonly string arguments;
public GitRemoteBranchDeleteTask(string remote, string branch,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitRemoteBranchDeleteTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string remote, string branch,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Guard.ArgumentNotNullOrWhiteSpace(remote, "remote");
Guard.ArgumentNotNullOrWhiteSpace(branch, "branch");

Просмотреть файл

@ -1,16 +1,19 @@
using System;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitRemoteChangeTask : ProcessTask<string>
public class GitRemoteChangeTask : NativeProcessTask<string>
{
private const string TaskName = "git remote set-url";
private readonly string arguments;
public GitRemoteChangeTask(string remote, string url,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitRemoteChangeTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string remote, string url,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Guard.ArgumentNotNullOrWhiteSpace(remote, "remote");
Guard.ArgumentNotNullOrWhiteSpace(url, "url");

Просмотреть файл

@ -1,13 +1,16 @@
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitRemoteListTask : ProcessTaskWithListOutput<GitRemote>
public class GitRemoteListTask : NativeProcessListTask<GitRemote>
{
private const string TaskName = "git remote";
public GitRemoteListTask(CancellationToken token, BaseOutputListProcessor<GitRemote> processor = null)
: base(token, processor ?? new RemoteListOutputProcessor())
public GitRemoteListTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new RemoteListOutputProcessor(), token: token)
{
Name = TaskName;
}

Просмотреть файл

@ -1,16 +1,19 @@
using System;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitRemoteRemoveTask : ProcessTask<string>
public class GitRemoteRemoveTask : NativeProcessTask<string>
{
private const string TaskName = "git remote rm";
private readonly string arguments;
public GitRemoteRemoveTask(string remote,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitRemoteRemoveTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string remote,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Guard.ArgumentNotNullOrWhiteSpace(remote, "remote");
Name = TaskName;

Просмотреть файл

@ -1,16 +1,21 @@
using System.Collections.Generic;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitRemoveFromIndexTask : ProcessTask<string>
using IO;
public class GitRemoveFromIndexTask : NativeProcessTask<string>
{
private const string TaskName = "git reset HEAD";
private readonly string arguments;
public GitRemoveFromIndexTask(IEnumerable<string> files,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitRemoveFromIndexTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
IEnumerable<string> files,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Guard.ArgumentNotNull(files, "files");
@ -20,7 +25,7 @@ namespace Unity.VersionControl.Git.Tasks
foreach (var file in files)
{
arguments += " \"" + file.ToNPath().ToString(SlashMode.Forward) + "\"";
arguments += " \"" + file.ToSPath().ToString(SlashMode.Forward) + "\"";
}
}

Просмотреть файл

@ -1,16 +1,19 @@
using System;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitResetTask : ProcessTask<string>
public class GitResetTask : NativeProcessTask<string>
{
private const string TaskName = "git reset";
private readonly string arguments;
public GitResetTask(string changeset, GitResetMode resetMode,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitResetTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string changeset, GitResetMode resetMode,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Name = TaskName;
arguments = $"reset {GetModeString(resetMode)} {changeset}";

Просмотреть файл

@ -1,15 +1,18 @@
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitRevertTask : ProcessTask<string>
public class GitRevertTask : NativeProcessTask<string>
{
private const string TaskName = "git revert";
private readonly string arguments;
public GitRevertTask(string changeset,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitRevertTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string changeset,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Guard.ArgumentNotNull(changeset, "changeset");
Name = TaskName;

Просмотреть файл

@ -1,14 +1,18 @@
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitStatusTask : ProcessTask<GitStatus>
public class GitStatusTask : NativeProcessTask<GitStatus>
{
private const string TaskName = "git status";
public GitStatusTask(IGitObjectFactory gitObjectFactory,
CancellationToken token, IOutputProcessor<GitStatus> processor = null)
: base(token, processor ?? new GitStatusOutputProcessor(gitObjectFactory))
public GitStatusTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
IGitObjectFactory gitObjectFactory,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new GitStatusOutputProcessor(gitObjectFactory), token: token)
{
Name = TaskName;
}

Просмотреть файл

@ -1,16 +1,19 @@
using System;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitSwitchBranchesTask : ProcessTask<string>
public class GitSwitchBranchesTask : NativeProcessTask<string>
{
private const string TaskName = "git checkout";
private readonly string arguments;
public GitSwitchBranchesTask(string branch,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitSwitchBranchesTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
string branch,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Guard.ArgumentNotNullOrWhiteSpace(branch, "branch");
Name = TaskName;

Просмотреть файл

@ -1,15 +1,20 @@
using System.Text;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitUnlockTask : ProcessTask<string>
using IO;
public class GitUnlockTask : NativeProcessTask<string>
{
private const string TaskName = "git lfs unlock";
public GitUnlockTask(NPath path, bool force,
CancellationToken token, IOutputProcessor<string> processor = null)
: base(token, processor ?? new SimpleOutputProcessor())
public GitUnlockTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
SPath path, bool force,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new StringOutputProcessor(), token: token)
{
Guard.ArgumentNotNullOrWhiteSpace(path, "path");
@ -28,7 +33,7 @@ namespace Unity.VersionControl.Git.Tasks
ProcessArguments = stringBuilder.ToString();
}
public override string ProcessArguments { get; }
public override string ProcessArguments { get; protected set; }
public override TaskAffinity Affinity => TaskAffinity.Exclusive;
public override string Message { get; set; } = "Unlocking file...";

Просмотреть файл

@ -1,13 +1,16 @@
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git.Tasks
{
public class GitVersionTask : ProcessTask<TheVersion>
public class GitVersionTask : NativeProcessTask<TheVersion>
{
private const string TaskName = "git --version";
public GitVersionTask(CancellationToken token, IOutputProcessor<TheVersion> processor = null)
: base(token, processor ?? new VersionOutputProcessor())
public GitVersionTask(ITaskManager taskManager, IProcessEnvironment processEnvironment,
IGitEnvironment environment,
CancellationToken token = default)
: base(taskManager, processEnvironment, environment.GitExecutablePath, null, outputProcessor: new VersionOutputProcessor(), token: token)
{
Name = TaskName;
}

Двоичные данные
src/com.unity.git.api/Api/GlobalSuppressions.cs

Двоичный файл не отображается.

Просмотреть файл

@ -1,10 +1,11 @@
using System;
using System.IO;
using System.Net.NetworkInformation;
using System.IO;
using System.Reflection;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git
{
using IO;
public enum ResourceType
{
Icon,
@ -40,7 +41,7 @@ namespace Unity.VersionControl.Git
return asm.GetManifestResourceStream($"Unity.VersionControl.Git.{type}{(!string.IsNullOrEmpty(os) ? "." + os : os)}.{resource}");
}
private static Stream TryGetStream(ResourceType resourceType, string resource, IEnvironment environment)
private static Stream TryGetStream(ResourceType resourceType, string resource, IGitEnvironment environment)
{
/*
This function attempts to get files embedded in the callers assembly.
@ -62,7 +63,7 @@ namespace Unity.VersionControl.Git
if (stream != null)
return stream;
NPath possiblePath = environment.ExtensionInstallPath.Combine(type, os, resource);
SPath possiblePath = environment.ExtensionInstallPath.Combine(type, os, resource);
if (possiblePath.FileExists())
{
return new MemoryStream(possiblePath.ReadAllBytes());
@ -78,7 +79,7 @@ namespace Unity.VersionControl.Git
return null;
}
private static NPath TryGetFile(ResourceType resourceType, string resource, IEnvironment environment)
private static SPath TryGetFile(ResourceType resourceType, string resource, IGitEnvironment environment)
{
/*
This function attempts to get files embedded in the callers assembly.
@ -99,11 +100,11 @@ namespace Unity.VersionControl.Git
var stream = TryGetResource(resourceType, type, os, resource);
if (stream != null)
{
var target = NPath.GetTempFilename();
var target = SPath.GetTempFilename();
return target.WriteAllBytes(stream.ToByteArray());
}
NPath possiblePath = environment.ExtensionInstallPath.Combine(type, os, resource);
SPath possiblePath = environment.ExtensionInstallPath.Combine(type, os, resource);
if (possiblePath.FileExists())
{
return possiblePath;
@ -116,11 +117,11 @@ namespace Unity.VersionControl.Git
return possiblePath;
}
return NPath.Default;
return SPath.Default;
}
public static NPath ToFile(ResourceType resourceType, string resource, NPath destinationPath, IEnvironment environment)
public static SPath ToFile(ResourceType resourceType, string resource, SPath destinationPath, IGitEnvironment environment)
{
var target = destinationPath.Combine(resource);
var source = TryGetFile(resourceType, resource, environment);
@ -129,10 +130,10 @@ namespace Unity.VersionControl.Git
target.DeleteIfExists();
return source.Copy(target);
}
return NPath.Default;
return SPath.Default;
}
public static Stream ToStream(ResourceType resourceType, string resource, IEnvironment environment)
public static Stream ToStream(ResourceType resourceType, string resource, IGitEnvironment environment)
{
return TryGetStream(resourceType, resource, environment);
}

Просмотреть файл

@ -68,6 +68,8 @@ using System.Runtime.Serialization;
using System.Text;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Unity.Editor.Tasks.Helpers;
using Unity.VersionControl.Git.IO;
using Unity.VersionControl.Git.Json;
// ReSharper disable LoopCanBeConvertedToQuery
@ -1356,8 +1358,8 @@ namespace Unity.VersionControl.Git.Json
{
if (str.Length != 0) // We know it can't be null now.
{
if (type == typeof(NPath) || (ReflectionUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type) == typeof(NPath)))
return new NPath(str);
if (type == typeof(SPath) || (ReflectionUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type) == typeof(SPath)))
return new SPath(str);
if (type == typeof(DateTime) || (ReflectionUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type) == typeof(DateTime)))
return DateTime.ParseExact(str, Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
if (type == typeof(DateTimeOffset) || (ReflectionUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type) == typeof(DateTimeOffset)))
@ -1491,7 +1493,7 @@ namespace Unity.VersionControl.Git.Json
protected virtual bool TrySerializeKnownTypes(object input, out object output)
{
bool returnValue = true;
if (input is NPath || input is UriString)
if (input is SPath || input is UriString)
output = input.ToString();
else if (input is DateTime)
output = ((DateTime)input).ToUniversalTime().ToString(Iso8601Format[0], CultureInfo.InvariantCulture);
@ -2157,7 +2159,7 @@ namespace Unity.VersionControl.Git.Json
namespace Unity.VersionControl.Git
{
using Json;
[System.AttributeUsage(System.AttributeTargets.Property |
System.AttributeTargets.Field)]
public sealed class NotSerializedAttribute : Attribute

Просмотреть файл

@ -1,298 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Unity.VersionControl.Git
{
public interface IFileSystem
{
string ChangeExtension(string path, string extension);
string Combine(string path1, string path2);
string Combine(string path1, string path2, string path3);
void DirectoryCreate(string path);
void DirectoryDelete(string path, bool recursive);
bool DirectoryExists(string path);
void DirectoryMove(string toString, string s);
bool ExistingPathIsDirectory(string path);
void FileCopy(string sourceFileName, string destFileName, bool overwrite);
void FileDelete(string path);
bool FileExists(string path);
void FileMove(string sourceFileName, string s);
string GetCurrentDirectory();
IEnumerable<string> GetDirectories(string path);
IEnumerable<string> GetDirectories(string path, string pattern);
IEnumerable<string> GetDirectories(string path, string pattern, SearchOption searchOption);
string GetFileNameWithoutExtension(string fileName);
IEnumerable<string> GetFiles(string path);
IEnumerable<string> GetFiles(string path, string pattern);
IEnumerable<string> GetFiles(string path, string pattern, SearchOption searchOption);
string GetFullPath(string path);
string GetRandomFileName();
string GetTempPath();
Stream OpenRead(string path);
Stream OpenWrite(string path, FileMode mode);
byte[] ReadAllBytes(string path);
string[] ReadAllLines(string path);
string ReadAllText(string path);
string ReadAllText(string path, Encoding encoding);
void SetCurrentDirectory(string currentDirectory);
void WriteAllBytes(string path, byte[] bytes);
void WriteAllLines(string path, string[] contents);
void WriteAllText(string path, string contents);
void WriteAllText(string path, string contents, Encoding encoding);
void WriteLines(string path, string[] contents);
char DirectorySeparatorChar { get; }
string GetProcessDirectory();
}
public class FileSystem : IFileSystem
{
private string currentDirectory;
public FileSystem()
{ }
/// <summary>
/// Initialize the filesystem object with the path passed in set as the current directory
/// </summary>
/// <param name="directory">Current directory</param>
public FileSystem(string directory)
{
currentDirectory = directory;
}
public void SetCurrentDirectory(string directory)
{
if (!Path.IsPathRooted(directory))
throw new ArgumentException("SetCurrentDirectory requires a rooted path", "directory");
currentDirectory = directory;
}
public bool FileExists(string filename)
{
return File.Exists(filename);
}
public IEnumerable<string> GetDirectories(string path)
{
return Directory.GetDirectories(path);
}
public string GetTempPath()
{
return Path.GetTempPath();
}
public string Combine(string path1, string path2)
{
return Path.Combine(path1, path2);
}
public string Combine(string path1, string path2, string path3)
{
return Path.Combine(Path.Combine(path1, path2), path3);
}
public string GetFullPath(string path)
{
return Path.GetFullPath(path);
}
public bool DirectoryExists(string path)
{
return Directory.Exists(path);
}
public bool ExistingPathIsDirectory(string path)
{
var attr = File.GetAttributes(path);
return (attr & FileAttributes.Directory) == FileAttributes.Directory;
}
public IEnumerable<string> GetDirectories(string path, string pattern)
{
return Directory.GetDirectories(path, pattern);
}
public IEnumerable<string> GetDirectories(string path, string pattern, SearchOption searchOption)
{
return Directory.GetDirectories(path, pattern, searchOption);
}
public string ChangeExtension(string path, string extension)
{
return Path.ChangeExtension(path, extension);
}
public string GetFileNameWithoutExtension(string fileName)
{
return Path.GetFileNameWithoutExtension(fileName);
}
public IEnumerable<string> GetFiles(string path)
{
return GetFiles(path, "*");
}
public IEnumerable<string> GetFiles(string path, string pattern)
{
return Directory.GetFiles(path, pattern);
}
public IEnumerable<string> GetFiles(string path, string pattern, SearchOption searchOption)
{
foreach (var file in GetFiles(path, pattern))
yield return file;
if (searchOption != SearchOption.AllDirectories)
yield break;
#if ENABLE_MONO
if (NPath.IsUnix)
{
try
{
path = Mono.Unix.UnixPath.GetCompleteRealPath(path);
}
catch
{}
}
#endif
foreach (var dir in GetDirectories(path))
{
var realdir = dir;
#if ENABLE_MONO
if (NPath.IsUnix)
{
try
{
realdir = Mono.Unix.UnixPath.GetCompleteRealPath(dir);
}
catch
{}
}
#endif
if (path != realdir)
{
foreach (var file in GetFiles(dir, pattern, searchOption))
yield return file;
}
}
}
public byte[] ReadAllBytes(string path)
{
return File.ReadAllBytes(path);
}
public void WriteAllBytes(string path, byte[] bytes)
{
File.WriteAllBytes(path, bytes);
}
public void DirectoryCreate(string toString)
{
Directory.CreateDirectory(toString);
}
public void FileCopy(string sourceFileName, string destFileName, bool overwrite)
{
File.Copy(sourceFileName, destFileName, overwrite);
}
public void FileDelete(string path)
{
File.Delete(path);
}
public void DirectoryDelete(string path, bool recursive)
{
Directory.Delete(path, recursive);
}
public void FileMove(string sourceFileName, string destFileName)
{
File.Move(sourceFileName, destFileName);
}
public void DirectoryMove(string toString, string s)
{
Directory.Move(toString, s);
}
public string GetCurrentDirectory()
{
if (currentDirectory != null)
return currentDirectory;
return Directory.GetCurrentDirectory();
}
public string GetProcessDirectory()
{
return Directory.GetCurrentDirectory();
}
public void WriteAllText(string path, string contents)
{
File.WriteAllText(path, contents);
}
public void WriteAllText(string path, string contents, Encoding encoding)
{
File.WriteAllText(path, contents, encoding);
}
public string ReadAllText(string path)
{
return File.ReadAllText(path);
}
public string ReadAllText(string path, Encoding encoding)
{
return File.ReadAllText(path, encoding);
}
public void WriteAllLines(string path, string[] contents)
{
File.WriteAllLines(path, contents);
}
public string[] ReadAllLines(string path)
{
return File.ReadAllLines(path);
}
public void WriteLines(string path, string[] contents)
{
using (var fs = File.AppendText(path))
{
foreach (var line in contents)
fs.WriteLine(line);
}
}
public string GetRandomFileName()
{
return Path.GetRandomFileName();
}
public Stream OpenRead(string path)
{
return File.OpenRead(path);
}
public Stream OpenWrite(string path, FileMode mode)
{
return new FileStream(path, mode);
}
public char DirectorySeparatorChar
{
get { return Path.DirectorySeparatorChar; }
}
}
}

Просмотреть файл

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 88bac531a79f5264b99acbc5972bbf11
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -4,6 +4,8 @@ using System.IO;
namespace Unity.VersionControl.Git
{
using IO;
public static class Utils
{
public static bool Copy(Stream source, Stream destination,
@ -78,7 +80,7 @@ namespace Unity.VersionControl.Git
destination.Flush();
return success;
}
public static bool VerifyFileIntegrity(NPath file, string hash)
public static bool VerifyFileIntegrity(SPath file, string hash)
{
if (!file.IsInitialized || !file.FileExists())
return false;
@ -90,12 +92,12 @@ namespace Unity.VersionControl.Git
return hash.Equals(actual, StringComparison.InvariantCultureIgnoreCase);
}
private static string ToMD5(this NPath path)
private static string ToMD5(this SPath path)
{
byte[] computeHash;
using (var hash = System.Security.Cryptography.MD5.Create())
{
using (var stream = NPath.FileSystem.OpenRead(path))
using (var stream = SPath.FileSystem.OpenRead(path))
{
computeHash = hash.ComputeHash(stream);
}
@ -104,12 +106,12 @@ namespace Unity.VersionControl.Git
return BitConverter.ToString(computeHash).Replace("-", string.Empty).ToLower();
}
private static string ToSha256(this NPath path)
private static string ToSha256(this SPath path)
{
byte[] computeHash;
using (var hash = System.Security.Cryptography.SHA256.Create())
{
using (var stream = NPath.FileSystem.OpenRead(path))
using (var stream = SPath.FileSystem.OpenRead(path))
{
computeHash = hash.ComputeHash(stream);
}

Просмотреть файл

@ -6,14 +6,16 @@ using Unity.VersionControl.Git;
namespace Unity.VersionControl.Git
{
using IO;
public static class CopyHelper
{
private static readonly ILogging Logger = LogHelper.GetLogger(typeof(CopyHelper));
public static void Copy(NPath fromPath, NPath toPath)
public static void Copy(SPath fromPath, SPath toPath)
{
Logger.Trace("Copying from {0} to {1}", fromPath, toPath);
try
{
CopyFolder(fromPath, toPath);
@ -37,7 +39,7 @@ namespace Unity.VersionControl.Git
fromPath.DeleteIfExists();
}
}
public static void CopyFolder(NPath fromPath, NPath toPath)
public static void CopyFolder(SPath fromPath, SPath toPath)
{
Logger.Trace("CopyFolder from {0} to {1}", fromPath, toPath);
toPath.DeleteIfExists();
@ -45,7 +47,7 @@ namespace Unity.VersionControl.Git
fromPath.Move(toPath);
}
public static void CopyFolderContents(NPath fromPath, NPath toPath)
public static void CopyFolderContents(SPath fromPath, SPath toPath)
{
Logger.Trace("CopyFolderContents from {0} to {1}", fromPath, toPath);
toPath.DeleteContents();

Просмотреть файл

@ -3,10 +3,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Unity.Editor.Tasks;
using Unity.Editor.Tasks.Helpers;
namespace Unity.VersionControl.Git
{
using Json;
using IO;
public class DugiteReleaseManifest
{
@ -55,14 +58,14 @@ namespace Unity.VersionControl.Git
assets.FirstOrDefault(x => x.Name.EndsWith(name + ".sha256")));
}
public static DugiteReleaseManifest Load(NPath path, IEnvironment environment)
public static DugiteReleaseManifest Load(ITaskManager taskManager, SPath path, IGitEnvironment environment)
{
var manifest = path.ReadAllText().FromJson<DugiteReleaseManifest>(true, false);
var (zipAsset, shaAsset) = manifest.GetAsset(environment);
var shaAssetPath = environment.UserCachePath.Combine("downloads", shaAsset.Name);
if (!shaAssetPath.FileExists())
{
var downloader = new Downloader();
var downloader = new Downloader(taskManager);
downloader.QueueDownload(shaAsset.Url, shaAssetPath.Parent, shaAssetPath.FileName);
downloader.RunSynchronously();
}
@ -71,7 +74,7 @@ namespace Unity.VersionControl.Git
return manifest;
}
public static DugiteReleaseManifest Load(NPath localCacheFile, UriString packageFeed, IEnvironment environment,
public static DugiteReleaseManifest Load(ITaskManager taskManager, SPath localCacheFile, UriString packageFeed, IGitEnvironment environment,
bool alwaysDownload = false)
{
DugiteReleaseManifest package = null;
@ -83,13 +86,14 @@ namespace Unity.VersionControl.Git
if (!localCacheFile.FileExists() ||
(alwaysDownload || now.Date > environment.UserSettings.Get<DateTimeOffset>(key).Date))
{
localCacheFile = new DownloadTask(TaskManager.Instance.Token, environment.FileSystem, packageFeed,
localCacheFile.Parent, filename).Catch(ex => {
var result = new DownloadTask(taskManager, packageFeed,
localCacheFile.Parent, filename)
.Catch(ex => {
LogHelper.Warning(@"Error downloading package feed:{0} ""{1}"" Message:""{2}""", packageFeed,
ex.GetType().ToString(), ex.GetExceptionMessageShort());
return true;
}).RunSynchronously();
localCacheFile = result.ToSPath();
if (localCacheFile.IsInitialized && !alwaysDownload)
environment.UserSettings.Set<DateTimeOffset>(key, now);
}
@ -104,7 +108,7 @@ namespace Unity.VersionControl.Git
{
try
{
package = Load(localCacheFile, environment);
package = Load(taskManager, localCacheFile, environment);
}
catch (Exception ex)
{

Просмотреть файл

@ -2,16 +2,25 @@
using System.Collections.Generic;
using System.Resources;
using System.Threading;
using Unity.Editor.Tasks.Helpers;
using Downloader = Unity.Editor.Tasks.Downloader;
using IEnvironment = Unity.Editor.Tasks.IEnvironment;
using IProcessManager = Unity.Editor.Tasks.IProcessManager;
using ProgressReporter = Unity.Editor.Tasks.ProgressReporter;
using TaskData = Unity.Editor.Tasks.TaskData;
namespace Unity.VersionControl.Git
{
using Tasks;
using IO;
using Unity.Editor.Tasks;
public class GitInstaller : TaskBase<GitInstaller.GitInstallationState>
public class GitInstaller : Editor.Tasks.TaskBase<GitInstaller.GitInstallationState>
{
private readonly CancellationToken cancellationToken;
private readonly IEnvironment environment;
private readonly IGitEnvironment environment;
private readonly IProcessManager processManager;
private readonly IProcessEnvironment processEnvironment;
private readonly GitInstallDetails installDetails;
private readonly IZipHelper sharpZipLibHelper;
private readonly Dictionary<string, TaskData> tasks = new Dictionary<string, TaskData>();
@ -19,14 +28,18 @@ namespace Unity.VersionControl.Git
private GitInstallationState currentState;
public GitInstaller(IEnvironment environment, IProcessManager processManager,
CancellationToken token,
public GitInstaller(ITaskManager taskManager,
IGitEnvironment environment,
IProcessManager processManager,
IProcessEnvironment processEnvironment,
GitInstallationState state = null,
GitInstallDetails installDetails = null)
: base(token)
GitInstallDetails installDetails = null,
CancellationToken token = default)
: base(taskManager, token)
{
this.environment = environment;
this.processManager = processManager;
this.processEnvironment = processEnvironment;
this.currentState = state;
this.sharpZipLibHelper = ZipHelper.Instance;
this.cancellationToken = token;
@ -44,7 +57,7 @@ namespace Unity.VersionControl.Git
catch (Exception ex)
{
if (!RaiseFaultHandlers(ex))
ThrownException.Rethrow();
Exception.Rethrow();
}
return ret;
}
@ -152,8 +165,8 @@ namespace Unity.VersionControl.Git
{
if (!state.GitIsValid)
{
var gitPath = new FindExecTask("git", cancellationToken)
.Configure(processManager, dontSetupGit: true)
var gitPath = new FindExecTask(TaskManager, environment, "git", cancellationToken)
.Configure(processManager)
.Progress(progressReporter.UpdateProgress)
.Catch(e => true)
.RunSynchronously();
@ -169,8 +182,8 @@ namespace Unity.VersionControl.Git
{
if (!state.GitLfsIsValid)
{
var gitLfsPath = new FindExecTask("git-lfs", cancellationToken)
.Configure(processManager, dontSetupGit: true)
var gitLfsPath = new FindExecTask(TaskManager, environment, "git-lfs", cancellationToken)
.Configure(processManager)
.Progress(progressReporter.UpdateProgress)
.Catch(e => true)
.RunSynchronously();
@ -199,11 +212,13 @@ namespace Unity.VersionControl.Git
state.GitIsValid = false;
return state;
}
var version = new GitVersionTask(cancellationToken)
.Configure(processManager, state.GitExecutablePath, dontSetupGit: true)
.Progress(progressReporter.UpdateProgress)
.Catch(e => true)
.RunSynchronously();
var version = new NativeProcessTask<TheVersion>(TaskManager, processManager,
state.GitExecutablePath, "--version",
new VersionOutputProcessor())
.Progress(progressReporter.UpdateProgress)
.Catch(e => true)
.RunSynchronously();
state.GitIsValid = version >= Constants.MinimumGitVersion;
state.GitVersion = version;
return state;
@ -216,8 +231,9 @@ namespace Unity.VersionControl.Git
state.GitLfsIsValid = false;
return state;
}
var version = new ProcessTask<TheVersion>(cancellationToken, "version", new LfsVersionOutputProcessor())
.Configure(processManager, state.GitLfsExecutablePath, dontSetupGit: true)
var version = new NativeProcessTask<TheVersion>(TaskManager, processManager,
state.GitLfsExecutablePath, "version",
new LfsVersionOutputProcessor())
.Progress(progressReporter.UpdateProgress)
.Catch(e => true)
.RunSynchronously();
@ -234,7 +250,7 @@ namespace Unity.VersionControl.Git
if (state.GitInstallationPath != installDetails.GitInstallationPath)
return state;
state.GitPackage = DugiteReleaseManifest.Load(installDetails.GitManifest, GitInstallDetails.GitPackageFeed, environment);
state.GitPackage = DugiteReleaseManifest.Load(TaskManager, installDetails.GitManifest, GitInstallDetails.GitPackageFeed, environment);
if (state.GitPackage == null)
return state;
@ -277,7 +293,7 @@ namespace Unity.VersionControl.Git
return state;
var asset = state.GitPackage.DugitePackage;
var downloader = new Downloader(environment.FileSystem);
var downloader = new Downloader(TaskManager);
downloader.QueueDownload(asset.Url, installDetails.ZipPath, asset.Name);
downloader
@ -297,12 +313,12 @@ namespace Unity.VersionControl.Git
private GitInstallationState ExtractGit(GitInstallationState state)
{
var tempZipExtractPath = NPath.CreateTempDirectory("ghu_extract_git");
var tempZipExtractPath = SPath.CreateTempDirectory("ghu_extract_git");
if (state.GitZipExists && !state.GitIsValid)
{
var gitExtractPath = tempZipExtractPath.Combine("git").CreateDirectory();
var unzipTask = new UnzipTask(cancellationToken, state.GitZipPath,
var unzipTask = new UnzipTask(TaskManager, state.GitZipPath,
gitExtractPath, sharpZipLibHelper,
environment.FileSystem)
.Progress(progressReporter.UpdateProgress)
@ -346,11 +362,11 @@ namespace Unity.VersionControl.Git
public bool GitIsValid { get => TryGetField<bool>(nameof(GitIsValid)); set => fields[nameof(GitIsValid)] = value; }
public bool GitLfsIsValid { get => TryGetField<bool>(nameof(GitLfsIsValid)); set => fields[nameof(GitLfsIsValid)] = value; }
public bool GitZipExists { get => TryGetField<bool>(nameof(GitZipExists)); set => fields[nameof(GitZipExists)] = value; }
public NPath GitZipPath { get => TryGetField<NPath>(nameof(GitZipPath)); set => fields[nameof(GitZipPath)] = value; }
public NPath GitInstallationPath { get => TryGetField<NPath>(nameof(GitInstallationPath)); set => fields[nameof(GitInstallationPath)] = value; }
public NPath GitExecutablePath { get => TryGetField<NPath>(nameof(GitExecutablePath)); set => fields[nameof(GitExecutablePath)] = value; }
public NPath GitLfsInstallationPath { get => TryGetField<NPath>(nameof(GitLfsInstallationPath)); set => fields[nameof(GitLfsInstallationPath)] = value; }
public NPath GitLfsExecutablePath { get => TryGetField<NPath>(nameof(GitLfsExecutablePath)); set => fields[nameof(GitLfsExecutablePath)] = value; }
public SPath GitZipPath { get => TryGetField<SPath>(nameof(GitZipPath)); set => fields[nameof(GitZipPath)] = value; }
public SPath GitInstallationPath { get => TryGetField<SPath>(nameof(GitInstallationPath)); set => fields[nameof(GitInstallationPath)] = value; }
public SPath GitExecutablePath { get => TryGetField<SPath>(nameof(GitExecutablePath)); set => fields[nameof(GitExecutablePath)] = value; }
public SPath GitLfsInstallationPath { get => TryGetField<SPath>(nameof(GitLfsInstallationPath)); set => fields[nameof(GitLfsInstallationPath)] = value; }
public SPath GitLfsExecutablePath { get => TryGetField<SPath>(nameof(GitLfsExecutablePath)); set => fields[nameof(GitLfsExecutablePath)] = value; }
public DugiteReleaseManifest GitPackage { get => TryGetField<DugiteReleaseManifest>(nameof(GitPackage)); set => fields[nameof(GitPackage)] = value; }
public DateTimeOffset GitLastCheckTime { get; set; }
public bool IsCustomGitPath { get => TryGetField<bool>(nameof(IsCustomGitPath)); set => fields[nameof(IsCustomGitPath)] = value; }
@ -360,7 +376,7 @@ namespace Unity.VersionControl.Git
public GitInstallationState()
{
GitIsValid = GitLfsIsValid = GitZipExists = IsCustomGitPath = default(bool);
GitZipPath = GitInstallationPath = GitExecutablePath = GitLfsInstallationPath = GitLfsExecutablePath = default(NPath);
GitZipPath = GitInstallationPath = GitExecutablePath = GitLfsInstallationPath = GitLfsExecutablePath = default(SPath);
GitPackage = default(DugiteReleaseManifest);
GitVersion = GitLfsVersion = default(TheVersion);
}
@ -416,19 +432,19 @@ namespace Unity.VersionControl.Git
public const string GitDirectory = "git";
public GitInstallDetails(NPath baseDataPath, IEnvironment environment)
public GitInstallDetails(SPath baseDataPath, IGitEnvironment environment)
{
ZipPath = baseDataPath.Combine("downloads");
ZipPath.EnsureDirectoryExists();
GitInstallationPath = baseDataPath.Combine(GitDirectory);
GitExecutablePath = GitInstallationPath.Combine(environment.IsWindows ? "cmd" : "bin", "git" + DefaultEnvironment.ExecutableExt);
GitExecutablePath = GitInstallationPath.Combine(environment.IsWindows ? "cmd" : "bin", "git" + environment.ExecutableExtension);
GitLfsInstallationPath = GitLfsExecutablePath = GitInstallationPath;
if (environment.IsWindows)
GitLfsExecutablePath = GitLfsInstallationPath.Combine(environment.Is32Bit ? "mingw32" : "mingw64");
GitLfsExecutablePath = GitLfsExecutablePath.Combine("libexec", "git-core");
GitLfsExecutablePath = GitLfsExecutablePath.Combine("git-lfs" + DefaultEnvironment.ExecutableExt);
GitLfsExecutablePath = GitLfsExecutablePath.Combine("git-lfs" + environment.ExecutableExtension);
GitManifest = baseDataPath.Combine(GitPackageName);
}
@ -442,13 +458,13 @@ namespace Unity.VersionControl.Git
};
}
public NPath ZipPath { get; }
public NPath GitInstallationPath { get; }
public NPath GitLfsInstallationPath { get; }
public NPath GitExecutablePath { get; }
public NPath GitLfsExecutablePath { get; }
public SPath ZipPath { get; }
public SPath GitInstallationPath { get; }
public SPath GitLfsInstallationPath { get; }
public SPath GitExecutablePath { get; }
public SPath GitLfsExecutablePath { get; }
public static UriString GitPackageFeed { get; set; } = packageFeed;
public NPath GitManifest { get; set; }
public SPath GitManifest { get; set; }
}
}
}

Просмотреть файл

@ -1,9 +1,10 @@
using System;
using System.Threading;
using Unity.VersionControl.Git;
namespace Unity.VersionControl.Git
{
using IO;
class OctorunInstaller
{
private static readonly ILogging Logger = LogHelper.GetLogger<OctorunInstaller>();
@ -24,16 +25,16 @@ namespace Unity.VersionControl.Git
this.taskManager = taskManager;
}
public NPath SetupOctorunIfNeeded()
public SPath SetupOctorunIfNeeded()
{
NPath path = NPath.Default;
SPath path = SPath.Default;
var isOctorunExtracted = IsOctorunExtracted();
if (isOctorunExtracted)
return installDetails.ExecutablePath;
GrabZipFromResources();
var extractPath = NPath.CreateTempDirectory("octorun_extract_archive_path");
var extractPath = SPath.CreateTempDirectory("octorun_extract_archive_path");
var unzipTask = new UnzipTask(taskManager.Token, installDetails.ZipFile,
extractPath, sharpZipLibHelper,
fileSystem)
@ -45,12 +46,12 @@ namespace Unity.VersionControl.Git
return path;
}
private NPath GrabZipFromResources()
private SPath GrabZipFromResources()
{
return AssemblyResources.ToFile(ResourceType.Generic, "octorun.zip", installDetails.BaseZipPath, environment);
}
private NPath MoveOctorun(NPath fromPath)
private SPath MoveOctorun(SPath fromPath)
{
var toPath = installDetails.InstallationPath;
@ -91,7 +92,7 @@ namespace Unity.VersionControl.Git
private const string PackageName = "octorun";
private const string zipFile = "octorun.zip";
public OctorunInstallDetails(NPath baseDataPath)
public OctorunInstallDetails(SPath baseDataPath)
{
BaseZipPath = baseDataPath.Combine("downloads");
BaseZipPath.EnsureDirectoryExists();
@ -104,14 +105,14 @@ namespace Unity.VersionControl.Git
ExecutablePath = installPath.Combine("src", "bin", Executable);
}
public NPath BaseZipPath { get; }
public NPath ZipFile { get; }
public NPath InstallationPath { get; }
public SPath BaseZipPath { get; }
public SPath ZipFile { get; }
public SPath InstallationPath { get; }
public string Executable { get; }
public NPath ExecutablePath { get; }
public SPath ExecutablePath { get; }
public UriString ZipMd5Url { get; set; } = DefaultZipMd5Url;
public UriString ZipUrl { get; set; } = DefaultZipUrl;
public NPath VersionFile => InstallationPath.Combine("version");
public SPath VersionFile => InstallationPath.Combine("version");
}
}
}

Просмотреть файл

@ -1,25 +1,27 @@
using System;
using System.Collections.Generic;
using System.Threading;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git
{
public class UnzipTask : TaskBase<NPath>
using IO;
public class UnzipTask : TaskBase<SPath>
{
private readonly string archiveFilePath;
private readonly NPath extractedPath;
private readonly SPath extractedPath;
private readonly IZipHelper zipHelper;
private readonly IFileSystem fileSystem;
private ProgressReporter progressReporter = new ProgressReporter();
private Dictionary<string, TaskData> tasks = new Dictionary<string, TaskData>();
public UnzipTask(NPath archiveFilePath, NPath extractedPath)
: this(TaskManager.Instance.Token, archiveFilePath, extractedPath, null, NPath.FileSystem)
public UnzipTask(ITaskManager taskManager, SPath archiveFilePath, SPath extractedPath)
: this(taskManager, archiveFilePath, extractedPath, null, SPath.FileSystem)
{}
public UnzipTask(CancellationToken token, NPath archiveFilePath, NPath extractedPath,
public UnzipTask(ITaskManager taskManager, SPath archiveFilePath, SPath extractedPath,
IZipHelper zipHelper, IFileSystem fileSystem)
: base(token)
: base(taskManager)
{
this.archiveFilePath = archiveFilePath;
this.extractedPath = extractedPath;
@ -32,12 +34,12 @@ namespace Unity.VersionControl.Git
};
}
protected NPath BaseRun(bool success)
protected SPath BaseRun(bool success)
{
return base.RunWithReturn(success);
}
protected override NPath RunWithReturn(bool success)
protected override SPath RunWithReturn(bool success)
{
var ret = BaseRun(success);
try
@ -47,12 +49,12 @@ namespace Unity.VersionControl.Git
catch (Exception ex)
{
if (!RaiseFaultHandlers(ex))
ThrownException.Rethrow();
Exception.Rethrow();
}
return ret;
}
protected virtual NPath RunUnzip(bool success)
protected virtual SPath RunUnzip(bool success)
{
Logger.Trace("Unzip File: {0} to Path: {1}", archiveFilePath, extractedPath);

Просмотреть файл

@ -9,6 +9,7 @@ namespace Unity.VersionControl.Git
using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.Tar;
using ICSharpCode.SharpZipLib.Zip;
using IO;
public interface IZipHelper
{
@ -36,18 +37,18 @@ namespace Unity.VersionControl.Git
Action<string, long> onStart, Func<long, long, string, bool> onProgress, Func<string, bool> onFilter = null)
{
var destDir = outFolder.ToNPath();
var destDir = outFolder.ToSPath();
destDir.EnsureDirectoryExists();
if (archive.EndsWith(".tar.gz") || archive.EndsWith(".tgz"))
{
var gzipFile = archive.ToNPath();
var tempDir = NPath.CreateTempDirectory("unzip");
var gzipFile = archive.ToSPath();
var tempDir = SPath.CreateTempDirectory("unzip");
string outFilename = gzipFile.FileNameWithoutExtension;
if (archive.EndsWith(".tgz"))
outFilename += ".tar";
archive = tempDir.Combine(outFilename);
using (var instream = NPath.FileSystem.OpenRead(gzipFile))
using (var outstream = NPath.FileSystem.OpenWrite(archive, FileMode.CreateNew))
using (var instream = SPath.FileSystem.OpenRead(gzipFile))
using (var outstream = SPath.FileSystem.OpenWrite(archive, FileMode.CreateNew))
{
GZip.Decompress(instream, outstream, false);
}
@ -58,14 +59,14 @@ namespace Unity.VersionControl.Git
return ExtractTar(archive, destDir, cancellationToken, onStart, onProgress, onFilter);
}
private bool ExtractZip(string archive, NPath outFolder, CancellationToken cancellationToken,
private bool ExtractZip(string archive, SPath outFolder, CancellationToken cancellationToken,
Action<string, long> onStart, Func<long, long, string, bool> onProgress, Func<string, bool> onFilter = null)
{
ZipFile zf = null;
try
{
var fs = NPath.FileSystem.OpenRead(archive);
var fs = SPath.FileSystem.OpenRead(archive);
zf = new ZipFile(fs);
List<IArchiveEntry> entries = PreprocessEntries(outFolder, zf, onStart, onFilter);
return ExtractArchive(archive, outFolder, cancellationToken, zf, entries, onStart, onProgress, onFilter);
@ -81,7 +82,7 @@ namespace Unity.VersionControl.Git
}
}
private bool ExtractTar(string archive, NPath outFolder, CancellationToken cancellationToken,
private bool ExtractTar(string archive, SPath outFolder, CancellationToken cancellationToken,
Action<string, long> onStart, Func<long, long, string, bool> onProgress, Func<string, bool> onFilter = null)
{
TarArchive zf = null;
@ -89,11 +90,11 @@ namespace Unity.VersionControl.Git
try
{
List<IArchiveEntry> entries;
using (var read = TarArchive.CreateInputTarArchive(NPath.FileSystem.OpenRead(archive)))
using (var read = TarArchive.CreateInputTarArchive(SPath.FileSystem.OpenRead(archive)))
{
entries = PreprocessEntries(outFolder, read, onStart, onFilter);
}
zf = TarArchive.CreateInputTarArchive(NPath.FileSystem.OpenRead(archive));
zf = TarArchive.CreateInputTarArchive(SPath.FileSystem.OpenRead(archive));
return ExtractArchive(archive, outFolder, cancellationToken, zf, entries, onStart, onProgress, onFilter);
}
catch (Exception ex)
@ -107,7 +108,7 @@ namespace Unity.VersionControl.Git
}
}
private static bool ExtractArchive(string archive, NPath outFolder, CancellationToken cancellationToken,
private static bool ExtractArchive(string archive, SPath outFolder, CancellationToken cancellationToken,
IArchive zf, List<IArchiveEntry> entries,
Action<string, long> onStart, Func<long, long, string, bool> onProgress, Func<string, bool> onFilter = null)
{
@ -137,7 +138,7 @@ namespace Unity.VersionControl.Git
return true;
}
private static List<IArchiveEntry> PreprocessEntries(NPath outFolder, IArchive zf, Action<string, long> onStart, Func<string, bool> onFilter)
private static List<IArchiveEntry> PreprocessEntries(SPath outFolder, IArchive zf, Action<string, long> onStart, Func<string, bool> onFilter)
{
var entries = new List<IArchiveEntry>();
@ -162,13 +163,13 @@ namespace Unity.VersionControl.Git
return entries;
}
private static NPath MaybeSetPermissions(NPath destDir, string entryFileName, int mode)
private static SPath MaybeSetPermissions(SPath destDir, string entryFileName, int mode)
{
var fullZipToPath = destDir.Combine(entryFileName);
fullZipToPath.EnsureParentDirectoryExists();
try
{
if (NPath.IsUnix)
if (SPath.IsUnix)
{
if (mode == -2115174400)
{

Просмотреть файл

@ -6,6 +6,8 @@ using Unity.VersionControl.Git;
namespace Unity.VersionControl.Git
{
using IO;
class UsageTrackerSync : IUsageTracker
{
@ -443,9 +445,9 @@ namespace Unity.VersionControl.Git
class UsageLoader : IUsageLoader
{
private readonly NPath path;
private readonly SPath path;
public UsageLoader(NPath path)
public UsageLoader(SPath path)
{
this.path = path;
}

Просмотреть файл

@ -1,6 +1,7 @@
using System;
using System.Security.AccessControl;
using System.Text.RegularExpressions;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git
{
@ -8,14 +9,16 @@ namespace Unity.VersionControl.Git
{
private static readonly Regex trackingBranchRegex = new Regex(@"\[[\w]+\/.*\]");
public override void LineReceived(string line)
protected override bool ProcessLine(string line, out GitBranch result)
{
base.ProcessLine(line, out result);
if (line == null)
return;
return false;
var proc = new LineParser(line);
if (proc.IsAtEnd)
return;
return false;
try
{
@ -46,13 +49,15 @@ namespace Unity.VersionControl.Git
}
}
var branch = new GitBranch(name, trackingName);
RaiseOnEntry(branch);
result = new GitBranch(name, trackingName);
return true;
}
catch(Exception ex)
{
Logger.Warning(ex, "Unexpected input when listing branches");
}
return false;
}
}
}

Просмотреть файл

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git
{
class ConfigOutputProcessor : BaseOutputListProcessor<KeyValuePair<string, string>>
{
protected override bool ProcessLine(string line, out KeyValuePair<string, string> result)
{
base.ProcessLine(line, out result);
if (string.IsNullOrEmpty(line))
return false;
var eqs = line.IndexOf("=");
if (eqs <= 0)
{
return false;
}
result = new KeyValuePair<string, string>(line.Substring(0, eqs), line.Substring(eqs + 1));
return true;
}
}
}

Просмотреть файл

@ -1,12 +1,16 @@
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git
{
class GitAheadBehindStatusOutputProcessor : BaseOutputProcessor<GitAheadBehindStatus>
{
public override void LineReceived(string line)
protected override bool ProcessLine(string line, out GitAheadBehindStatus result)
{
base.ProcessLine(line, out result);
if (line == null)
{
return;
return false;
}
var proc = new LineParser(line);
@ -14,7 +18,8 @@ namespace Unity.VersionControl.Git
var ahead = int.Parse(proc.ReadUntilWhitespace());
var behind = int.Parse(proc.ReadToEnd());
RaiseOnEntry(new GitAheadBehindStatus(ahead, behind));
result = new GitAheadBehindStatus(ahead, behind);
return true;
}
}
}
}

Просмотреть файл

@ -1,16 +1,14 @@
using Unity.Editor.Tasks;
namespace Unity.VersionControl.Git
{
public class GitCountObjectsProcessor : BaseOutputProcessor<int>
{
public override void LineReceived(string line)
protected override bool ProcessLine(string line, out int result)
{
if (line == null)
{
return;
}
//2488 objects, 4237 kilobytes
base.ProcessLine(line, out result);
//parses 2488 objects, 4237 kilobytes
try
{
var proc = new LineParser(line);
@ -18,10 +16,11 @@ namespace Unity.VersionControl.Git
proc.MoveToAfter(',');
var kilobytes = int.Parse(proc.ReadUntilWhitespaceTrim());
RaiseOnEntry(kilobytes);
result = kilobytes;
return true;
}
catch {}
return;
return false;
}
}
}

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше