Skip to content

Commit 8162b3a

Browse files
committed
(split from main repo) Add and use IExecutable and IProcess abstractions
This change introduces an interface for the use and substitution of executables and the processes they create. GitModule accepts an instance of IExecutable that represents git.exe, allowing injection of MockExecutable for testing purposes. See GitModuleTest. ExecutableExtensions provide convenient access to the most common operations required from executables. Notably all executions that read process output now do so using async/await, rather than spawning one-off threads to read output streams. This gives better utilisation of the thread pool. The lightweight type ArgumentString is used as a union type between string and ArgumentBuilder (and potential future types) for passing arguments. It has implicit conversions to string, and from both string and ArgumentBuilder. All process invocations are now tracked in CommandLog. CommandCache has been converted from a static class into an instance class so that it may be used for any execution that returns output, whether for git.exe or other processes. It has been changed to reuse the MruCache class that was recently added for in-memory avatar caching. GitCommandHelpers.VersionInUse has been moved to GitVersion.Current where it has a clearer relationship.
1 parent 1c9c499 commit 8162b3a

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

FormGerritDownload.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private bool RunCommand(IGitRemoteCommand command, string change)
148148
private static string FetchCommand(string remote, string remoteBranch)
149149
{
150150
var progressOption = "";
151-
if (GitCommandHelpers.VersionInUse.FetchCanAskForProgress)
151+
if (GitVersion.Current.FetchCanAskForProgress)
152152
{
153153
progressOption = "--progress ";
154154
}

FormGerritPublish.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,15 @@ private void PublishClick(object sender, EventArgs e)
4040
}
4141
}
4242

43-
private static string PushCmd(string remote, string toBranch)
43+
private static ArgumentString PushCmd(string remote, string toBranch)
4444
{
45-
var args = new ArgumentBuilder
45+
return new ArgumentBuilder
4646
{
4747
"push",
48-
{ GitCommandHelpers.VersionInUse.PushCanAskForProgress, "--progress" },
48+
{ GitVersion.Current.PushCanAskForProgress, "--progress" },
4949
remote.ToPosixPath().Trim().Quote(),
5050
$"HEAD:{GitRefName.GetFullBranchName(toBranch)?.Replace(" ", "")}"
5151
};
52-
53-
return args.ToString();
5452
}
5553

5654
private bool PublishChange(IWin32Window owner)

GerritUtil.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,9 @@ public static async Task<string> RunGerritCommandAsync([NotNull] IWin32Window ow
6060

6161
StartAgent(owner, module, remote);
6262

63-
var sshCmd = SshPathLocatorInstance.Find(AppSettings.GitBinDir);
64-
if (GitCommandHelpers.Plink())
65-
{
66-
sshCmd = AppSettings.Plink;
67-
}
63+
var sshCmd = GitCommandHelpers.Plink()
64+
? AppSettings.Plink
65+
: SshPathLocatorInstance.Find(AppSettings.GitBinDir);
6866

6967
if (string.IsNullOrEmpty(sshCmd))
7068
{
@@ -100,11 +98,8 @@ public static async Task<string> RunGerritCommandAsync([NotNull] IWin32Window ow
10098
sb.Append(command);
10199
sb.Append("\"");
102100

103-
return await module.RunCmdAsync(
104-
sshCmd,
105-
sb.ToString(),
106-
encoding: null,
107-
stdIn).ConfigureAwait(false);
101+
return await new Executable(sshCmd)
102+
.GetOutputAsync(sb.ToString(), stdIn).ConfigureAwait(false);
108103
}
109104

110105
public static void StartAgent([NotNull] IWin32Window owner, [NotNull] IGitModule module, [NotNull] string remote)

0 commit comments

Comments
 (0)