Skip to content

Commit

Permalink
Include process ID in command log
Browse files Browse the repository at this point in the history
Motivated by issue reported in gitextensions#4256. Relates to gitextensions#4753.
  • Loading branch information
drewnoakes committed Jul 25, 2018
1 parent 6e2fd0c commit ceca298
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions GitCommands/Git/GitCommandHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ internal static Process StartProcess(string fileName, string arguments, string w
var startInfo = CreateProcessStartInfo(fileName, arguments, workingDirectory, outputEncoding);
var process = Process.Start(startInfo);
process.EnableRaisingEvents = true;
operation.SetProcessId(process.Id);

void ProcessExited(object sender, EventArgs args)
{
Expand Down
7 changes: 4 additions & 3 deletions GitCommands/Git/GitModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,10 @@ private static Process StartProcess([NotNull] string fileName, [NotNull] string
}

var operation = CommandLog.LogProcessStart(fileName, arguments);
var startProcess = Process.Start(startInfo);
startProcess.Exited += (s, e) => operation.LogProcessEnd();
return startProcess;
var process = Process.Start(startInfo);
operation.SetProcessId(process.Id);
process.Exited += (s, e) => operation.LogProcessEnd();
return process;
}

[NotNull]
Expand Down
9 changes: 8 additions & 1 deletion GitCommands/Logging/CommandLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public void LogProcessEnd()
_entry.Duration = _stopwatch.Elapsed;
_raiseCommandsChanged();
}

public void SetProcessId(int processId)
{
_entry.ProcessId = processId;
_raiseCommandsChanged();
}
}

public sealed class CommandLogEntry
Expand All @@ -39,6 +45,7 @@ public sealed class CommandLogEntry
private DateTime StartedAt { get; }
public bool IsOnMainThread { get; }
public TimeSpan? Duration { get; internal set; }
public int? ProcessId { get; set; }

internal CommandLogEntry(string fileName, string arguments, DateTime startedAt, bool isOnMainThread)
{
Expand All @@ -61,7 +68,7 @@ public override string ToString()
fileName = "git";
}

return $"{StartedAt:HH:mm:ss.fff} {duration,7} {(IsOnMainThread ? "UI" : " ")} {fileName} {Arguments}";
return $"{StartedAt:HH:mm:ss.fff} {duration,7} {ProcessId?.ToString("#D,-5") ?? " "} {(IsOnMainThread ? "UI" : " ")} {fileName} {Arguments}";
}
}

Expand Down
12 changes: 6 additions & 6 deletions GitUI/Script/PowerShellHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ public static class PowerShellHelper
internal static void RunPowerShell(string command, string argument, string workingDir, bool runInBackground)
{
const string filename = "powershell.exe";
var psarguments = (runInBackground ? "" : "-NoExit") + " -ExecutionPolicy Unrestricted -Command \"" + command + " " + argument + "\"";
var arguments = (runInBackground ? "" : "-NoExit") + " -ExecutionPolicy Unrestricted -Command \"" + command + " " + argument + "\"";
EnvironmentConfiguration.SetEnvironmentVariables();

var startInfo = new ProcessStartInfo
{
FileName = filename,
Arguments = psarguments,
Arguments = arguments,
WorkingDirectory = workingDir,
UseShellExecute = false
};

var operation = CommandLog.LogProcessStart(filename, psarguments);
var startProcess = Process.Start(startInfo);

startProcess.Exited += (s, e) => operation.LogProcessEnd();
var operation = CommandLog.LogProcessStart(filename, arguments);
var process = Process.Start(startInfo);
operation.SetProcessId(process.Id);
process.Exited += (s, e) => operation.LogProcessEnd();
}
}
}
2 changes: 1 addition & 1 deletion GitUI/UserControls/EditboxBasedConsoleOutputControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public override void StartProcess(string command, string arguments, string workd

var operation = CommandLog.LogProcessStart(command, arguments);
process.Exited += (s, e) => operation.LogProcessEnd();

operation.SetProcessId(process.Id);
process.Start();
_process = process;
process.BeginOutputReadLine();
Expand Down

0 comments on commit ceca298

Please sign in to comment.