Skip to content

Commit 551cf8b

Browse files
Send GitCommitId over GetVersionHandler (#1965)
So the client can skip updates for daily and dev builds. Also clean up a little more, the commit ID was not actually being used in the rest of the codebase, and the `DisplayVersion` was dumb.
1 parent c6eb624 commit 551cf8b

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

src/PowerShellEditorServices/Services/PowerShell/Context/PowerShellVersionDetails.cs

+1-13
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ internal class PowerShellVersionDetails
2121
/// </summary>
2222
public Version Version { get; }
2323

24-
/// <summary>
25-
/// Gets the full version string, either the ToString of the Version
26-
/// property or the GitCommitId for open-source PowerShell releases.
27-
/// </summary>
28-
public string VersionString { get; }
29-
3024
/// <summary>
3125
/// Gets the PowerShell edition (generally Desktop or Core).
3226
/// </summary>
@@ -36,15 +30,12 @@ internal class PowerShellVersionDetails
3630
/// Creates an instance of the PowerShellVersionDetails class.
3731
/// </summary>
3832
/// <param name="version">The version of the PowerShell runtime.</param>
39-
/// <param name="versionString">A string representation of the PowerShell version.</param>
4033
/// <param name="editionString">The string representation of the PowerShell edition.</param>
4134
public PowerShellVersionDetails(
4235
Version version,
43-
string versionString,
4436
string editionString)
4537
{
4638
Version = version;
47-
VersionString = versionString;
4839
Edition = editionString;
4940
}
5041

@@ -59,7 +50,6 @@ public PowerShellVersionDetails(
5950
public static PowerShellVersionDetails GetVersionDetails(ILogger logger, PowerShell pwsh)
6051
{
6152
Version powerShellVersion = new(5, 0);
62-
string versionString = null;
6353
string powerShellEdition = "Desktop";
6454

6555
try
@@ -89,8 +79,6 @@ public static PowerShellVersionDetails GetVersionDetails(ILogger logger, PowerSh
8979
// Expected version string format is 6.0.0-alpha so build a simpler version from that
9080
powerShellVersion = new Version(version.ToString().Split('-')[0]);
9181
}
92-
93-
versionString = psVersionTable["GitCommitId"] is string gitCommitId ? gitCommitId : powerShellVersion.ToString();
9482
}
9583
}
9684
catch (Exception ex)
@@ -99,7 +87,7 @@ public static PowerShellVersionDetails GetVersionDetails(ILogger logger, PowerSh
9987
"Failed to look up PowerShell version, defaulting to version 5.\r\n\r\n" + ex.ToString());
10088
}
10189

102-
return new PowerShellVersionDetails(powerShellVersion, versionString, powerShellEdition);
90+
return new PowerShellVersionDetails(powerShellVersion, powerShellEdition);
10391
}
10492
}
10593
}

src/PowerShellEditorServices/Services/PowerShell/Handlers/GetVersionHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public async Task<PowerShellVersion> Handle(GetVersionParams request, Cancellati
1616
{
1717
Version = VersionUtils.PSVersionString,
1818
Edition = VersionUtils.PSEdition,
19-
DisplayVersion = VersionUtils.PSVersion.ToString(2),
19+
Commit = VersionUtils.GitCommitId,
2020
Architecture = VersionUtils.Architecture
2121
};
2222
}

src/PowerShellEditorServices/Services/PowerShell/Handlers/IGetVersionHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ internal class GetVersionParams : IRequest<PowerShellVersion> { }
1414
internal record PowerShellVersion
1515
{
1616
public string Version { get; init; }
17-
public string DisplayVersion { get; init; }
1817
public string Edition { get; init; }
18+
public string Commit { get; init; }
1919
public string Architecture { get; init; }
2020
}
2121
}

src/PowerShellEditorServices/Utility/VersionUtils.cs

+18-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ internal static class VersionUtils
2727
/// </summary>
2828
public static string PSEdition { get; } = PowerShellReflectionUtils.PSEdition;
2929

30+
/// <summary>
31+
/// Gets the GitCommitId of PowerShell being used.
32+
/// </summary>
33+
public static string GitCommitId { get; } = PowerShellReflectionUtils.GitCommitId;
34+
3035
/// <summary>
3136
/// Gets the string of the PSVersion including prerelease tags if it applies.
3237
/// </summary>
@@ -84,8 +89,12 @@ internal static class PowerShellReflectionUtils
8489
private static readonly PropertyInfo s_psEditionProperty = s_psVersionInfoType
8590
.GetProperty("PSEdition", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
8691

92+
// This property is a string, existing only in PowerShell Core.
93+
private static readonly FieldInfo s_psGitCommitIdProperty = s_psVersionInfoType
94+
.GetField("GitCommitId", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
95+
8796
/// <summary>
88-
/// Get's the Version of PowerShell being used. Note: this will get rid of the SemVer 2.0 suffix because apparently
97+
/// Gets the Version of PowerShell being used. NOTE: this will get rid of the SemVer 2.0 suffix because apparently
8998
/// that property is added as a note property and it is not there when we reflect.
9099
/// </summary>
91100
public static Version PSVersion { get; } = s_psVersionProperty.GetValue(null) as Version;
@@ -95,12 +104,19 @@ internal static class PowerShellReflectionUtils
95104
/// </summary>
96105
public static string PSEdition { get; } = s_psEditionProperty.GetValue(null) as string;
97106

107+
/// <summary>
108+
/// Gets the GitCommitId or at most x.y.z from the PSVersion, making Windows PowerShell conform to SemVer.
109+
/// </summary>
110+
public static string GitCommitId { get; } = s_psGitCommitIdProperty != null
111+
? s_psGitCommitIdProperty.GetValue(null).ToString()
112+
: PSVersion.ToString(3);
113+
98114
/// <summary>
99115
/// Gets the stringified version of PowerShell including prerelease tags if it applies.
100116
/// </summary>
101117
public static string PSVersionString { get; } = s_psCurrentVersionProperty != null
102118
? s_psCurrentVersionProperty.GetValue(null).ToString()
103-
: s_psVersionProperty.GetValue(null).ToString();
119+
: PSVersion.ToString(3);
104120

105121
public static string GetOSArchitecture()
106122
{

0 commit comments

Comments
 (0)