From 69c33ed0be29de36e9fbd3188b55d0cd165d578a Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Sat, 12 Jun 2021 16:20:35 -0600 Subject: [PATCH 01/13] Switch from PInvoke nuget dependency to CsWin32 Fixes #615 --- .../ManagedGit/FileHelpers.cs | 16 +++++++++------- src/NerdBank.GitVersioning/NativeMethods.json | 3 +++ src/NerdBank.GitVersioning/NativeMethods.txt | 2 ++ .../NerdBank.GitVersioning.csproj | 2 +- .../Nerdbank.GitVersioning.nuspec | 2 -- 5 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 src/NerdBank.GitVersioning/NativeMethods.json create mode 100644 src/NerdBank.GitVersioning/NativeMethods.txt diff --git a/src/NerdBank.GitVersioning/ManagedGit/FileHelpers.cs b/src/NerdBank.GitVersioning/ManagedGit/FileHelpers.cs index 623539a1..eb250db9 100644 --- a/src/NerdBank.GitVersioning/ManagedGit/FileHelpers.cs +++ b/src/NerdBank.GitVersioning/ManagedGit/FileHelpers.cs @@ -5,8 +5,7 @@ using System.IO; using System.Runtime.InteropServices; using Microsoft.Win32.SafeHandles; -using static PInvoke.Kernel32; -using FileShare = PInvoke.Kernel32.FileShare; +using Microsoft.Windows.Sdk; namespace Nerdbank.GitVersioning.ManagedGit { @@ -24,7 +23,7 @@ internal static bool TryOpen(string path, out FileStream? stream) { if (IsWindows) { - var handle = CreateFile(path, ACCESS_MASK.GenericRight.GENERIC_READ, FileShare.FILE_SHARE_READ, (SECURITY_ATTRIBUTES?)null, CreationDisposition.OPEN_EXISTING, CreateFileFlags.FILE_ATTRIBUTE_NORMAL, SafeObjectHandle.Null); + var handle = PInvoke.CreateFile(path, FILE_ACCESS_FLAGS.FILE_GENERIC_READ, FILE_SHARE_FLAGS.FILE_SHARE_READ, lpSecurityAttributes: null, FILE_CREATE_FLAGS.OPEN_EXISTING, FILE_FLAGS_AND_ATTRIBUTES.FILE_ATTRIBUTE_NORMAL, null); if (!handle.IsInvalid) { @@ -62,12 +61,15 @@ internal static unsafe bool TryOpen(ReadOnlySpan path, [NotNullWhen(true)] { if (IsWindows) { - var handle = CreateFile(path, ACCESS_MASK.GenericRight.GENERIC_READ, FileShare.FILE_SHARE_READ, null, CreationDisposition.OPEN_EXISTING, CreateFileFlags.FILE_ATTRIBUTE_NORMAL, SafeObjectHandle.Null); + HANDLE handle; + fixed (char* pPath = &path[0]) + { + handle = PInvoke.CreateFile(pPath, FILE_ACCESS_FLAGS.FILE_GENERIC_READ, FILE_SHARE_FLAGS.FILE_SHARE_READ, null, FILE_CREATE_FLAGS.OPEN_EXISTING, FILE_FLAGS_AND_ATTRIBUTES.FILE_ATTRIBUTE_NORMAL, default); + } - if (!handle.IsInvalid) + if (!handle.Equals(Constants.INVALID_HANDLE_VALUE)) { - var fileHandle = new SafeFileHandle(handle.DangerousGetHandle(), ownsHandle: true); - handle.SetHandleAsInvalid(); + var fileHandle = new SafeFileHandle(handle, ownsHandle: true); stream = new FileStream(fileHandle, System.IO.FileAccess.Read); return true; } diff --git a/src/NerdBank.GitVersioning/NativeMethods.json b/src/NerdBank.GitVersioning/NativeMethods.json new file mode 100644 index 00000000..69d2bcc5 --- /dev/null +++ b/src/NerdBank.GitVersioning/NativeMethods.json @@ -0,0 +1,3 @@ +{ + "$schema": "https://aka.ms/CsWin32.schema.json" +} \ No newline at end of file diff --git a/src/NerdBank.GitVersioning/NativeMethods.txt b/src/NerdBank.GitVersioning/NativeMethods.txt new file mode 100644 index 00000000..885be08e --- /dev/null +++ b/src/NerdBank.GitVersioning/NativeMethods.txt @@ -0,0 +1,2 @@ +CreateFile +INVALID_HANDLE_VALUE diff --git a/src/NerdBank.GitVersioning/NerdBank.GitVersioning.csproj b/src/NerdBank.GitVersioning/NerdBank.GitVersioning.csproj index afeb8233..b196afbc 100644 --- a/src/NerdBank.GitVersioning/NerdBank.GitVersioning.csproj +++ b/src/NerdBank.GitVersioning/NerdBank.GitVersioning.csproj @@ -12,12 +12,12 @@ + - diff --git a/src/Nerdbank.GitVersioning.Tasks/Nerdbank.GitVersioning.nuspec b/src/Nerdbank.GitVersioning.Tasks/Nerdbank.GitVersioning.nuspec index 30e035fc..48fc3455 100644 --- a/src/Nerdbank.GitVersioning.Tasks/Nerdbank.GitVersioning.nuspec +++ b/src/Nerdbank.GitVersioning.Tasks/Nerdbank.GitVersioning.nuspec @@ -23,7 +23,6 @@ IMPORTANT: The 3.x release may produce a different version height than prior maj - @@ -49,7 +48,6 @@ IMPORTANT: The 3.x release may produce a different version height than prior maj - From 546a678f93bd67af3589ae0e6a1d2c2ccadc488e Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Sun, 13 Jun 2021 02:56:04 -0600 Subject: [PATCH 02/13] Update CsWin32 to fix `dotnet build` --- azure-pipelines.yml | 18 +++++++++--------- .../ManagedGit/FileHelpers.cs | 8 +++++--- .../NerdBank.GitVersioning.csproj | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 10d8b58c..14753b51 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -58,13 +58,13 @@ stages: displayName: Configure git commit author for testing - task: UseDotNet@2 - displayName: Install .NET Core SDK 5.0.202 + displayName: Install .NET Core 5.0.202 SDK inputs: packageType: sdk version: 5.0.202 - task: UseDotNet@2 - displayName: Install .NET Core 3.1 + displayName: Install .NET Core 3.1 runtime inputs: packageType: runtime version: 3.1.x @@ -296,17 +296,17 @@ stages: vmImage: $(imageName) steps: - task: UseDotNet@2 - displayName: Install .NET Core SDK 2.1.811 + displayName: Install .NET Core 2.1 runtime inputs: - packageType: sdk - version: 2.1.811 + packageType: runtime + version: 2.1.x - task: UseDotNet@2 - displayName: Install .NET Core SDK 3.1.100 + displayName: Install .NET Core 3.1 runtime inputs: - packageType: sdk - version: 3.1.100 + packageType: runtime + version: 3.1.x - task: UseDotNet@2 - displayName: Install .NET Core SDK 5.0.202 + displayName: Install .NET Core 5.0.202 SDK inputs: packageType: sdk version: 5.0.202 diff --git a/src/NerdBank.GitVersioning/ManagedGit/FileHelpers.cs b/src/NerdBank.GitVersioning/ManagedGit/FileHelpers.cs index eb250db9..e1d9713b 100644 --- a/src/NerdBank.GitVersioning/ManagedGit/FileHelpers.cs +++ b/src/NerdBank.GitVersioning/ManagedGit/FileHelpers.cs @@ -5,7 +5,9 @@ using System.IO; using System.Runtime.InteropServices; using Microsoft.Win32.SafeHandles; -using Microsoft.Windows.Sdk; +using Windows.Win32; +using Windows.Win32.Storage.FileSystem; +using Windows.Win32.System.SystemServices; namespace Nerdbank.GitVersioning.ManagedGit { @@ -23,7 +25,7 @@ internal static bool TryOpen(string path, out FileStream? stream) { if (IsWindows) { - var handle = PInvoke.CreateFile(path, FILE_ACCESS_FLAGS.FILE_GENERIC_READ, FILE_SHARE_FLAGS.FILE_SHARE_READ, lpSecurityAttributes: null, FILE_CREATE_FLAGS.OPEN_EXISTING, FILE_FLAGS_AND_ATTRIBUTES.FILE_ATTRIBUTE_NORMAL, null); + var handle = PInvoke.CreateFile(path, FILE_ACCESS_FLAGS.FILE_GENERIC_READ, FILE_SHARE_MODE.FILE_SHARE_READ, lpSecurityAttributes: null, FILE_CREATION_DISPOSITION.OPEN_EXISTING, FILE_FLAGS_AND_ATTRIBUTES.FILE_ATTRIBUTE_NORMAL, null); if (!handle.IsInvalid) { @@ -64,7 +66,7 @@ internal static unsafe bool TryOpen(ReadOnlySpan path, [NotNullWhen(true)] HANDLE handle; fixed (char* pPath = &path[0]) { - handle = PInvoke.CreateFile(pPath, FILE_ACCESS_FLAGS.FILE_GENERIC_READ, FILE_SHARE_FLAGS.FILE_SHARE_READ, null, FILE_CREATE_FLAGS.OPEN_EXISTING, FILE_FLAGS_AND_ATTRIBUTES.FILE_ATTRIBUTE_NORMAL, default); + handle = PInvoke.CreateFile(pPath, FILE_ACCESS_FLAGS.FILE_GENERIC_READ, FILE_SHARE_MODE.FILE_SHARE_READ, null, FILE_CREATION_DISPOSITION.OPEN_EXISTING, FILE_FLAGS_AND_ATTRIBUTES.FILE_ATTRIBUTE_NORMAL, default); } if (!handle.Equals(Constants.INVALID_HANDLE_VALUE)) diff --git a/src/NerdBank.GitVersioning/NerdBank.GitVersioning.csproj b/src/NerdBank.GitVersioning/NerdBank.GitVersioning.csproj index b196afbc..d6dfbf49 100644 --- a/src/NerdBank.GitVersioning/NerdBank.GitVersioning.csproj +++ b/src/NerdBank.GitVersioning/NerdBank.GitVersioning.csproj @@ -12,7 +12,7 @@ - + From 8cfe442dbc59172078156bbde21fdd00bfdbcda8 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Sun, 13 Jun 2021 06:55:01 -0600 Subject: [PATCH 03/13] Remove dotnet/pinvoke from 3rd party licenses file --- 3rdPartyNotices.txt | 25 ------------------------- src/Nerdbank.GitVersioning.sln | 5 +++-- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/3rdPartyNotices.txt b/3rdPartyNotices.txt index f96a675c..3a888faa 100644 --- a/3rdPartyNotices.txt +++ b/3rdPartyNotices.txt @@ -127,31 +127,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -dotnet/PInvoke (https://github.com/dotnet/pinvoke) -============== - -MIT License - -Copyright (c) .NET Foundation and Contributors - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - Cake Contrib (https://github.com/cake-contrib/graphics) ============ diff --git a/src/Nerdbank.GitVersioning.sln b/src/Nerdbank.GitVersioning.sln index 66c96ce6..43ffb2c7 100644 --- a/src/Nerdbank.GitVersioning.sln +++ b/src/Nerdbank.GitVersioning.sln @@ -1,12 +1,13 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.28404.58 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31411.2 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4BD1A7CD-6F52-4F5A-825B-50E4D8C3ECFF}" ProjectSection(SolutionItems) = preProject ..\.editorconfig = ..\.editorconfig ..\.gitignore = ..\.gitignore + ..\3rdPartyNotices.txt = ..\3rdPartyNotices.txt ..\azure-pipelines.yml = ..\azure-pipelines.yml ..\build.ps1 = ..\build.ps1 Directory.Build.props = Directory.Build.props From 1f1cf8bbef88042cf14719b56d663dbcddcbacd5 Mon Sep 17 00:00:00 2001 From: rhodosaur Date: Sun, 20 Jun 2021 11:06:15 +0200 Subject: [PATCH 04/13] include 5E and DA values in zlib header check --- src/NerdBank.GitVersioning/ManagedGit/ZLibStream.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/NerdBank.GitVersioning/ManagedGit/ZLibStream.cs b/src/NerdBank.GitVersioning/ManagedGit/ZLibStream.cs index 31d11366..d21077f5 100644 --- a/src/NerdBank.GitVersioning/ManagedGit/ZLibStream.cs +++ b/src/NerdBank.GitVersioning/ManagedGit/ZLibStream.cs @@ -5,6 +5,7 @@ using System.Buffers; using System.IO; using System.IO.Compression; +using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -56,9 +57,9 @@ public ZLibStream(Stream stream, long length = -1) Span zlibHeader = stackalloc byte[2]; stream.ReadAll(zlibHeader); - if (zlibHeader[0] != 0x78 || (zlibHeader[1] != 0x01 && zlibHeader[1] != 0x9C)) + if (zlibHeader[0] != 0x78 || (zlibHeader[1] != 0x01 && zlibHeader[1] != 0x9C && zlibHeader[1] != 0x5E && zlibHeader[1] != 0xDA)) { - throw new GitException(); + throw new GitException($"Invalid zlib header {string.Join(" ", zlibHeader.ToArray().Select(b => $"{b:X2}"))}"); } } From 480626dc4bda26c47f12342dd3f1bbc7973324f8 Mon Sep 17 00:00:00 2001 From: rhodosaur Date: Sun, 20 Jun 2021 15:26:41 +0200 Subject: [PATCH 05/13] ditch linq for exception --- src/NerdBank.GitVersioning/ManagedGit/ZLibStream.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/NerdBank.GitVersioning/ManagedGit/ZLibStream.cs b/src/NerdBank.GitVersioning/ManagedGit/ZLibStream.cs index d21077f5..d4e68212 100644 --- a/src/NerdBank.GitVersioning/ManagedGit/ZLibStream.cs +++ b/src/NerdBank.GitVersioning/ManagedGit/ZLibStream.cs @@ -5,7 +5,6 @@ using System.Buffers; using System.IO; using System.IO.Compression; -using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -59,7 +58,7 @@ public ZLibStream(Stream stream, long length = -1) if (zlibHeader[0] != 0x78 || (zlibHeader[1] != 0x01 && zlibHeader[1] != 0x9C && zlibHeader[1] != 0x5E && zlibHeader[1] != 0xDA)) { - throw new GitException($"Invalid zlib header {string.Join(" ", zlibHeader.ToArray().Select(b => $"{b:X2}"))}"); + throw new GitException($"Invalid zlib header {zlibHeader[0]:X2} {zlibHeader[1]:X2}"); } } From 75791742ee3507c5d9ed86d64e40864094db7b32 Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Tue, 27 Jul 2021 12:50:47 +0200 Subject: [PATCH 06/13] Add new NuGet signing certificate See https://devblogs.microsoft.com/nuget/the-nuget-org-repository-signing-certificate-will-be-updated-as-soon-as-march-15th-2021/ for more details --- src/nuget.config | 1 + 1 file changed, 1 insertion(+) diff --git a/src/nuget.config b/src/nuget.config index 7ada9430..ede70863 100644 --- a/src/nuget.config +++ b/src/nuget.config @@ -13,6 +13,7 @@ Microsoft;aarnott;xunit;kzu;castleproject;patrickb8man;jamesnk;ethomson;AndreyAkinshin;MarcoRossignoli;cake-build;ericnewton76;0xd4d;manuel.roemer + From 7df66a372bac2ffeba50c923d0f7860b19bb5163 Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Tue, 27 Jul 2021 12:53:41 +0200 Subject: [PATCH 07/13] Bump libgit2sharp to 0.27.0-preview-0102 --- src/NerdBank.GitVersioning/NerdBank.GitVersioning.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NerdBank.GitVersioning/NerdBank.GitVersioning.csproj b/src/NerdBank.GitVersioning/NerdBank.GitVersioning.csproj index d6dfbf49..1119a781 100644 --- a/src/NerdBank.GitVersioning/NerdBank.GitVersioning.csproj +++ b/src/NerdBank.GitVersioning/NerdBank.GitVersioning.csproj @@ -10,7 +10,7 @@ - + From 4451779fd3fbd6867cbcca0b7cc77afe558bd1b5 Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Tue, 27 Jul 2021 11:26:46 +0200 Subject: [PATCH 08/13] Run 32-bit tests --- azure-pipelines.yml | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 14753b51..c03e99ab 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -43,6 +43,7 @@ stages: windows: imageName: 'windows-2019' testModifier: + dotnet32: "\"C:\\Program Files (x86)\\dotnet\\dotnet.exe\"" variables: - ${{ if eq(variables['System.TeamFoundationCollectionUri'], 'https://dev.azure.com/andrewarnott/') }}: - group: dotnetfoundation code signing @@ -69,6 +70,13 @@ stages: packageType: runtime version: 3.1.x + - pwsh: | + Invoke-WebRequest -Uri "https://dot.net/v1/dotnet-install.ps1" -OutFile dotnet-install.ps1 + & .\dotnet-install.ps1 -Architecture x86 -Version 5.0.202 -InstallDir "C:\Program Files (x86)\dotnet\" -NoPath -Verbose + & .\dotnet-install.ps1 -Architecture x86 -Channel 3.1 -InstallDir "C:\Program Files (x86)\dotnet\" -NoPath -Verbose + displayName: Install 32-bit .NET Core SDK 5.0.202, 3.1 + condition: ne(variables['dotnet32'], '') + - script: dotnet --info displayName: Show dotnet SDK info @@ -121,8 +129,22 @@ stages: --collect:"XPlat Code Coverage" -- RunConfiguration.DisableAppDomain=true - displayName: Run tests + displayName: Run x64 tests + workingDirectory: src + + - script: > + $(dotnet32) test NerdBank.GitVersioning.Tests + --no-build $(testModifier) + -c $(BuildConfiguration) + --filter "TestCategory!=FailsOnAzurePipelines" + --logger "trx;LogFileName=$(Build.ArtifactStagingDirectory)/TestLogs/TestResults.trx" + --results-directory $(Build.ArtifactStagingDirectory)/CodeCoverage/ + --collect:"XPlat Code Coverage" + -- + RunConfiguration.DisableAppDomain=true + displayName: Run x86 tests workingDirectory: src + condition: ne(variables['dotnet32'], '') - task: PublishCodeCoverageResults@1 displayName: Publish code coverage results From edc162175a43ce985c769f942ac063ea26a271ef Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Fri, 23 Jul 2021 16:37:10 +0200 Subject: [PATCH 09/13] GitPack: Don't use MemoryMappedFiles in 32-bit processes --- .../ManagedGit/GitPackTests.cs | 20 ++++++++++++-- .../ManagedGit/GitPack.cs | 27 ++++++++++++++----- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/NerdBank.GitVersioning.Tests/ManagedGit/GitPackTests.cs b/src/NerdBank.GitVersioning.Tests/ManagedGit/GitPackTests.cs index 94905c70..6a55fe77 100644 --- a/src/NerdBank.GitVersioning.Tests/ManagedGit/GitPackTests.cs +++ b/src/NerdBank.GitVersioning.Tests/ManagedGit/GitPackTests.cs @@ -63,7 +63,15 @@ public void GetPackedObject() // This commit is not deltafied. It is stored as a .gz-compressed stream in the pack file. var zlibStream = Assert.IsType(commitStream); var deflateStream = Assert.IsType(zlibStream.BaseStream); - var pooledStream = Assert.IsType(deflateStream.BaseStream); + + if (IntPtr.Size > 4) + { + var pooledStream = Assert.IsType(deflateStream.BaseStream); + } + else + { + var pooledStream = Assert.IsType(deflateStream.BaseStream); + } Assert.Equal(222, commitStream.Length); Assert.Equal("/zgldANj+jvgOwlecnOKylZDVQg=", Convert.ToBase64String(sha.ComputeHash(commitStream))); @@ -85,7 +93,15 @@ public void GetDeltafiedObject() var deltaStream = Assert.IsType(commitStream); var zlibStream = Assert.IsType(deltaStream.BaseStream); var deflateStream = Assert.IsType(zlibStream.BaseStream); - var pooledStream = Assert.IsType(deflateStream.BaseStream); + + if (IntPtr.Size > 4) + { + var pooledStream = Assert.IsType(deflateStream.BaseStream); + } + else + { + var directAccessStream = Assert.IsType(deflateStream.BaseStream); + } Assert.Equal(137, commitStream.Length); Assert.Equal("lZu/7nGb0n1UuO9SlPluFnSvj4o=", Convert.ToBase64String(sha.ComputeHash(commitStream))); diff --git a/src/NerdBank.GitVersioning/ManagedGit/GitPack.cs b/src/NerdBank.GitVersioning/ManagedGit/GitPack.cs index 27c45c69..eff2eaf8 100644 --- a/src/NerdBank.GitVersioning/ManagedGit/GitPack.cs +++ b/src/NerdBank.GitVersioning/ManagedGit/GitPack.cs @@ -31,8 +31,8 @@ public class GitPack : IDisposable private readonly Func packStream; private readonly Lazy indexStream; private readonly GitPackCache cache; - private MemoryMappedFile packFile; - private MemoryMappedViewAccessor accessor; + private MemoryMappedFile? packFile = null; + private MemoryMappedViewAccessor? accessor = null; // Maps GitObjectIds to offets in the git pack. private readonly Dictionary offsets = new Dictionary(); @@ -98,8 +98,11 @@ public GitPack(GetObjectFromRepositoryDelegate getObjectFromRepositoryDelegate, this.indexStream = indexStream ?? throw new ArgumentNullException(nameof(indexStream)); this.cache = cache ?? new GitPackMemoryCache(); - this.packFile = MemoryMappedFile.CreateFromFile(this.packStream(), mapName: null, 0, MemoryMappedFileAccess.Read, HandleInheritability.None, leaveOpen: false); - this.accessor = this.packFile.CreateViewAccessor(0, 0, MemoryMappedFileAccess.Read); + if (IntPtr.Size > 4) + { + this.packFile = MemoryMappedFile.CreateFromFile(this.packStream(), mapName: null, 0, MemoryMappedFileAccess.Read, HandleInheritability.None, leaveOpen: false); + this.accessor = this.packFile.CreateViewAccessor(0, 0, MemoryMappedFileAccess.Read); + } } /// @@ -240,8 +243,8 @@ public void Dispose() this.indexReader.Value.Dispose(); } - this.accessor.Dispose(); - this.packFile.Dispose(); + this.accessor?.Dispose(); + this.packFile?.Dispose(); this.cache.Dispose(); } @@ -265,7 +268,17 @@ public void Dispose() private Stream GetPackStream() { - return new MemoryMappedStream(this.accessor); + // On 64-bit processes, we can use Memory Mapped Streams (the address space + // will be large enough to map the entire packfile). On 32-bit processes, + // we directly access the underlying stream. + if (IntPtr.Size > 4) + { + return new MemoryMappedStream(this.accessor); + } + else + { + return this.packStream(); + } } private GitPackIndexReader OpenIndex() From c955e1ff28d19063f106f562c863e3918448df29 Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Fri, 23 Jul 2021 18:15:22 +0200 Subject: [PATCH 10/13] Make sure Streams are disposed of. --- .../ManagedGit/GitPackTests.cs | 26 +++++++++++++------ .../ManagedGit/GitPack.cs | 12 ++++++++- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/NerdBank.GitVersioning.Tests/ManagedGit/GitPackTests.cs b/src/NerdBank.GitVersioning.Tests/ManagedGit/GitPackTests.cs index 6a55fe77..0c14a314 100644 --- a/src/NerdBank.GitVersioning.Tests/ManagedGit/GitPackTests.cs +++ b/src/NerdBank.GitVersioning.Tests/ManagedGit/GitPackTests.cs @@ -136,14 +136,24 @@ public void TryGetObjectTest() using (SHA1 sha = SHA1.Create()) { Assert.True(gitPack.TryGetObject(GitObjectId.Parse("f5b401f40ad83f13030e946c9ea22cb54cb853cd"), "commit", out Stream commitStream)); - - // This commit is not deltafied. It is stored as a .gz-compressed stream in the pack file. - var zlibStream = Assert.IsType(commitStream); - var deflateStream = Assert.IsType(zlibStream.BaseStream); - var pooledStream = Assert.IsType(deflateStream.BaseStream); - - Assert.Equal(222, commitStream.Length); - Assert.Equal("/zgldANj+jvgOwlecnOKylZDVQg=", Convert.ToBase64String(sha.ComputeHash(commitStream))); + using (commitStream) + { + // This commit is not deltafied. It is stored as a .gz-compressed stream in the pack file. + var zlibStream = Assert.IsType(commitStream); + var deflateStream = Assert.IsType(zlibStream.BaseStream); + + if (IntPtr.Size > 4) + { + var pooledStream = Assert.IsType(deflateStream.BaseStream); + } + else + { + var directAccessStream = Assert.IsType(deflateStream.BaseStream); + } + + Assert.Equal(222, commitStream.Length); + Assert.Equal("/zgldANj+jvgOwlecnOKylZDVQg=", Convert.ToBase64String(sha.ComputeHash(commitStream))); + } } } diff --git a/src/NerdBank.GitVersioning/ManagedGit/GitPack.cs b/src/NerdBank.GitVersioning/ManagedGit/GitPack.cs index eff2eaf8..5d19128d 100644 --- a/src/NerdBank.GitVersioning/ManagedGit/GitPack.cs +++ b/src/NerdBank.GitVersioning/ManagedGit/GitPack.cs @@ -205,7 +205,17 @@ public Stream GetObject(long offset, string objectType) } var packStream = this.GetPackStream(); - Stream objectStream = GitPackReader.GetObject(this, packStream, offset, objectType, packObjectType); + Stream objectStream; + + try + { + objectStream = GitPackReader.GetObject(this, packStream, offset, objectType, packObjectType); + } + catch + { + packStream.Dispose(); + throw; + } return this.cache.Add(offset, objectStream); } From 357099c220379c6e8d99869e66f4f44625e0d3c4 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Wed, 28 Jul 2021 12:06:52 +0200 Subject: [PATCH 11/13] Fix bugs with > 2 GB pack files --- .../ManagedGit/GitPackIndexMappedReader.cs | 2 +- src/NerdBank.GitVersioning/ManagedGit/GitPackReader.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/NerdBank.GitVersioning/ManagedGit/GitPackIndexMappedReader.cs b/src/NerdBank.GitVersioning/ManagedGit/GitPackIndexMappedReader.cs index 8f895ac1..279f0403 100644 --- a/src/NerdBank.GitVersioning/ManagedGit/GitPackIndexMappedReader.cs +++ b/src/NerdBank.GitVersioning/ManagedGit/GitPackIndexMappedReader.cs @@ -128,7 +128,7 @@ public override (long?, GitObjectId?) GetOffset(Span objectName, bool ends { // If the first bit of the offset address is set, the offset is stored as a 64-bit value in the table of 8-byte offset entries, // which follows the table of 4-byte offset entries: "large offsets are encoded as an index into the next table with the msbit set." - offset = offset & 0x7FF; + offset = offset & 0x7FFFFFFF; offsetBuffer = this.Value.Slice(offsetTableStart + 4 * objectCount + 8 * (int)offset, 8); var offset64 = BinaryPrimitives.ReadInt64BigEndian(offsetBuffer); diff --git a/src/NerdBank.GitVersioning/ManagedGit/GitPackReader.cs b/src/NerdBank.GitVersioning/ManagedGit/GitPackReader.cs index 30d3bead..caebe49f 100644 --- a/src/NerdBank.GitVersioning/ManagedGit/GitPackReader.cs +++ b/src/NerdBank.GitVersioning/ManagedGit/GitPackReader.cs @@ -44,7 +44,7 @@ public static Stream GetObject(GitPack pack, Stream stream, long offset, string if (type == GitPackObjectType.OBJ_OFS_DELTA) { var baseObjectRelativeOffset = ReadVariableLengthInteger(stream); - var baseObjectOffset = (int)(offset - baseObjectRelativeOffset); + var baseObjectOffset = offset - baseObjectRelativeOffset; var deltaStream = new ZLibStream(stream, decompressedSize); var baseObjectStream = pack.GetObject(baseObjectOffset, objectType); @@ -98,9 +98,9 @@ private static (GitPackObjectType, long) ReadObjectHeader(Stream stream) return (type, length); } - private static int ReadVariableLengthInteger(Stream stream) + private static long ReadVariableLengthInteger(Stream stream) { - int offset = -1; + long offset = -1; int b; do From a7eaba90ef3c559bb81036d2b46e820b1b5bcfbd Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Wed, 28 Jul 2021 16:31:02 +0200 Subject: [PATCH 12/13] Apply suggestions from code review Co-authored-by: Andrew Arnott --- src/NerdBank.GitVersioning/ManagedGit/GitPackReader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NerdBank.GitVersioning/ManagedGit/GitPackReader.cs b/src/NerdBank.GitVersioning/ManagedGit/GitPackReader.cs index caebe49f..a1eba9ae 100644 --- a/src/NerdBank.GitVersioning/ManagedGit/GitPackReader.cs +++ b/src/NerdBank.GitVersioning/ManagedGit/GitPackReader.cs @@ -44,7 +44,7 @@ public static Stream GetObject(GitPack pack, Stream stream, long offset, string if (type == GitPackObjectType.OBJ_OFS_DELTA) { var baseObjectRelativeOffset = ReadVariableLengthInteger(stream); - var baseObjectOffset = offset - baseObjectRelativeOffset; + long baseObjectOffset = offset - baseObjectRelativeOffset; var deltaStream = new ZLibStream(stream, decompressedSize); var baseObjectStream = pack.GetObject(baseObjectOffset, objectType); From 9ead4781720fd277d41a16ea2ade0874e4282723 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Mon, 23 Aug 2021 16:06:41 -0600 Subject: [PATCH 13/13] Apply `is null` pattern and analyzer --- .editorconfig | 6 ++++++ src/Directory.Build.props | 6 +++++- .../BuildIntegrationTests.cs | 2 +- .../ManagedGit/DeltaStreamReaderTests.cs | 4 ++-- .../ReleaseManagerTests.cs | 4 ++-- src/NerdBank.GitVersioning.Tests/RepoTestBase.cs | 6 +++--- .../TestUtilities.cs | 2 +- .../VersionFileTests.cs | 2 +- .../AssemblyVersionOptionsConverter.cs | 2 +- .../CloudBuildServices/GitLab.cs | 4 ++-- .../CloudBuildServices/TeamCity.cs | 2 +- .../FilterPathJsonConverter.cs | 4 ++-- .../LibGit2/LibGit2GitExtensions.cs | 16 ++++++++-------- .../Managed/ManagedGitContext.cs | 6 +++--- .../Managed/ManagedGitExtensions.cs | 12 ++++++------ .../ManagedGit/GitCommitReader.cs | 2 +- .../ManagedGit/GitObjectId.cs | 2 +- src/NerdBank.GitVersioning/ManagedGit/GitPack.cs | 4 ++-- .../ManagedGit/GitPackDeltafiedStream.cs | 4 ++-- .../ManagedGit/GitPackIndexMappedReader.cs | 2 +- .../ManagedGit/GitPackReader.cs | 4 ++-- .../ManagedGit/GitRepository.cs | 10 +++++----- src/NerdBank.GitVersioning/ReleaseManager.cs | 8 ++++---- src/NerdBank.GitVersioning/SemanticVersion.cs | 4 ++-- .../SemanticVersionJsonConverter.cs | 2 +- src/NerdBank.GitVersioning/VersionOptions.cs | 8 +++----- src/NerdBank.GitVersioning/VersionOracle.cs | 2 +- .../ContextAwareTask.cs | 6 +++--- .../GetBuildVersion.cs | 8 ++++---- .../NativeVersionInfo.cs | 4 ++-- .../SetCloudBuildVariables.cs | 6 +++--- src/nbgv/Program.cs | 14 +++++++------- 32 files changed, 88 insertions(+), 80 deletions(-) diff --git a/.editorconfig b/.editorconfig index 98824c08..fb31b8c2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -79,3 +79,9 @@ csharp_new_line_before_catch = true csharp_new_line_before_finally = true csharp_new_line_before_members_in_object_initializers = true csharp_new_line_before_members_in_anonymous_types = true + +# CSIsNull001: Use `is null` for null checks +dotnet_diagnostic.CSIsNull001.severity = warning + +# CSIsNull002: Use `is object` for non-null checks +dotnet_diagnostic.CSIsNull002.severity = warning diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 7f82c288..94a570b3 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -24,9 +24,13 @@ 2.0.312 - + + + all + runtime; build; native; contentfiles; analyzers + diff --git a/src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs b/src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs index b2ab89f5..d931f2e2 100644 --- a/src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs +++ b/src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs @@ -219,7 +219,7 @@ public async Task GetBuildVersion_In_Git_But_Head_Lacks_VersionFile() var repo = new Repository(this.RepoPath); // do not assign Repo property to avoid commits being generated later repo.Commit("empty", this.Signer, this.Signer, new CommitOptions { AllowEmptyCommit = true }); this.WriteVersionFile("3.4"); - Assumes.True(repo.Index[VersionFile.JsonFileName] == null); + Assumes.True(repo.Index[VersionFile.JsonFileName] is null); var buildResult = await this.BuildAsync(); Assert.Equal("3.4.0." + this.GetVersion().Revision, buildResult.BuildVersion); Assert.Equal("3.4.0+" + repo.Head.Tip.Id.Sha.Substring(0, VersionOptions.DefaultGitCommitIdShortFixedLength), buildResult.AssemblyInformationalVersion); diff --git a/src/NerdBank.GitVersioning.Tests/ManagedGit/DeltaStreamReaderTests.cs b/src/NerdBank.GitVersioning.Tests/ManagedGit/DeltaStreamReaderTests.cs index 2e475ca9..279e0a16 100644 --- a/src/NerdBank.GitVersioning.Tests/ManagedGit/DeltaStreamReaderTests.cs +++ b/src/NerdBank.GitVersioning.Tests/ManagedGit/DeltaStreamReaderTests.cs @@ -89,7 +89,7 @@ public void ReadStreamTest() DeltaInstruction? current; - while ((current = DeltaStreamReader.Read(stream)) != null) + while ((current = DeltaStreamReader.Read(stream)) is not null) { instructions.Add(current.Value); } @@ -139,7 +139,7 @@ public void ReadStreamTest_Memory() DeltaInstruction? current; - while ((current = DeltaStreamReader.Read(ref memory)) != null) + while ((current = DeltaStreamReader.Read(ref memory)) is not null) { instructions.Add(current.Value); } diff --git a/src/NerdBank.GitVersioning.Tests/ReleaseManagerTests.cs b/src/NerdBank.GitVersioning.Tests/ReleaseManagerTests.cs index c69f5120..c95500bf 100644 --- a/src/NerdBank.GitVersioning.Tests/ReleaseManagerTests.cs +++ b/src/NerdBank.GitVersioning.Tests/ReleaseManagerTests.cs @@ -320,7 +320,7 @@ public void PrepeareRelease_ReleaseBranchWithVersionDecrement(string initialVers // prepare release var releaseManager = new ReleaseManager(); - releaseManager.PrepareRelease(this.RepoPath, releaseUnstableTag, (nextVersion == null ? null : Version.Parse(nextVersion)), parameterVersionIncrement); + releaseManager.PrepareRelease(this.RepoPath, releaseUnstableTag, (nextVersion is null ? null : Version.Parse(nextVersion)), parameterVersionIncrement); // check if a branch was created Assert.Contains(this.LibGit2Repository.Branches, branch => branch.FriendlyName == expectedBranchName); @@ -394,7 +394,7 @@ public void PrepareRelease_MasterWithVersionDecrement(string initialVersion, str // running PrepareRelease should result in an error // because we're trying to add a prerelease tag to a version without prerelease tag this.AssertError( - () => new ReleaseManager().PrepareRelease(this.RepoPath, releaseUnstableTag, (nextVersion == null ? null : Version.Parse(nextVersion))), + () => new ReleaseManager().PrepareRelease(this.RepoPath, releaseUnstableTag, (nextVersion is null ? null : Version.Parse(nextVersion))), ReleasePreparationError.VersionDecrement); } diff --git a/src/NerdBank.GitVersioning.Tests/RepoTestBase.cs b/src/NerdBank.GitVersioning.Tests/RepoTestBase.cs index 4bcd8bbb..5cc81647 100644 --- a/src/NerdBank.GitVersioning.Tests/RepoTestBase.cs +++ b/src/NerdBank.GitVersioning.Tests/RepoTestBase.cs @@ -143,7 +143,7 @@ protected void AddCommits(int count = 1) protected Commit? WriteVersionTxtFile(string version = "1.2", string prerelease = "", string? relativeDirectory = null) { - if (relativeDirectory == null) + if (relativeDirectory is null) { relativeDirectory = string.Empty; } @@ -163,7 +163,7 @@ protected void AddCommits(int count = 1) { Requires.NotNull(versionData, nameof(versionData)); - if (relativeDirectory == null) + if (relativeDirectory is null) { relativeDirectory = string.Empty; } @@ -197,7 +197,7 @@ protected void AddCommits(int count = 1) if (Path.GetExtension(relativeFilePath) == ".json") { string txtFilePath = relativeFilePath.Substring(0, relativeFilePath.Length - 4) + "txt"; - if (!File.Exists(Path.Combine(this.RepoPath, txtFilePath)) && this.LibGit2Repository.Index[txtFilePath] != null) + if (!File.Exists(Path.Combine(this.RepoPath, txtFilePath)) && this.LibGit2Repository.Index[txtFilePath] is not null) { this.LibGit2Repository.Index.Remove(txtFilePath); } diff --git a/src/NerdBank.GitVersioning.Tests/TestUtilities.cs b/src/NerdBank.GitVersioning.Tests/TestUtilities.cs index a67edbd1..6d61fbf1 100644 --- a/src/NerdBank.GitVersioning.Tests/TestUtilities.cs +++ b/src/NerdBank.GitVersioning.Tests/TestUtilities.cs @@ -54,7 +54,7 @@ internal static void ExtractEmbeddedResource(string resourcePath, string extract using (var stream = GetEmbeddedResource(resourcePath)) { - Requires.Argument(stream != null, nameof(resourcePath), "Resource not found."); + Requires.Argument(stream is not null, nameof(resourcePath), "Resource not found."); using (var extractedFile = File.OpenWrite(extractedFilePath)) { stream.CopyTo(extractedFile); diff --git a/src/NerdBank.GitVersioning.Tests/VersionFileTests.cs b/src/NerdBank.GitVersioning.Tests/VersionFileTests.cs index a4ad2af3..f6330e61 100644 --- a/src/NerdBank.GitVersioning.Tests/VersionFileTests.cs +++ b/src/NerdBank.GitVersioning.Tests/VersionFileTests.cs @@ -140,7 +140,7 @@ public void SetVersion_WritesSimplestFile(string version, string assemblyVersion var versionOptions = new VersionOptions { Version = SemanticVersion.Parse(version), - AssemblyVersion = assemblyVersion != null || precision != null ? new VersionOptions.AssemblyVersionOptions(assemblyVersion != null ? new Version(assemblyVersion) : null, precision) : null, + AssemblyVersion = assemblyVersion is not null || precision is not null ? new VersionOptions.AssemblyVersionOptions(assemblyVersion is not null ? new Version(assemblyVersion) : null, precision) : null, VersionHeightOffset = versionHeightOffset, Inherit = inherit, }; diff --git a/src/NerdBank.GitVersioning/AssemblyVersionOptionsConverter.cs b/src/NerdBank.GitVersioning/AssemblyVersionOptionsConverter.cs index 0f88e0f5..0e88f638 100644 --- a/src/NerdBank.GitVersioning/AssemblyVersionOptionsConverter.cs +++ b/src/NerdBank.GitVersioning/AssemblyVersionOptionsConverter.cs @@ -51,7 +51,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var data = value as VersionOptions.AssemblyVersionOptions; - if (data != null) + if (data is not null) { if (data.PrecisionOrDefault == VersionOptions.DefaultVersionPrecision && !this.includeDefaults) { diff --git a/src/NerdBank.GitVersioning/CloudBuildServices/GitLab.cs b/src/NerdBank.GitVersioning/CloudBuildServices/GitLab.cs index aa0c649a..21abebd2 100644 --- a/src/NerdBank.GitVersioning/CloudBuildServices/GitLab.cs +++ b/src/NerdBank.GitVersioning/CloudBuildServices/GitLab.cs @@ -14,13 +14,13 @@ internal class GitLab : ICloudBuild { public string BuildingBranch => - Environment.GetEnvironmentVariable("CI_COMMIT_TAG") == null ? + Environment.GetEnvironmentVariable("CI_COMMIT_TAG") is null ? $"refs/heads/{Environment.GetEnvironmentVariable("CI_COMMIT_REF_NAME")}" : null; public string BuildingRef => this.BuildingBranch ?? this.BuildingTag; public string BuildingTag => - Environment.GetEnvironmentVariable("CI_COMMIT_TAG") != null ? + Environment.GetEnvironmentVariable("CI_COMMIT_TAG") is not null ? $"refs/tags/{Environment.GetEnvironmentVariable("CI_COMMIT_TAG")}" : null; public string GitCommitId => Environment.GetEnvironmentVariable("CI_COMMIT_SHA"); diff --git a/src/NerdBank.GitVersioning/CloudBuildServices/TeamCity.cs b/src/NerdBank.GitVersioning/CloudBuildServices/TeamCity.cs index e4df2b69..ec0cd84b 100644 --- a/src/NerdBank.GitVersioning/CloudBuildServices/TeamCity.cs +++ b/src/NerdBank.GitVersioning/CloudBuildServices/TeamCity.cs @@ -19,7 +19,7 @@ internal class TeamCity : ICloudBuild public string GitCommitId => Environment.GetEnvironmentVariable("BUILD_VCS_NUMBER"); - public bool IsApplicable => this.GitCommitId != null; + public bool IsApplicable => this.GitCommitId is not null; public bool IsPullRequest => false; diff --git a/src/NerdBank.GitVersioning/FilterPathJsonConverter.cs b/src/NerdBank.GitVersioning/FilterPathJsonConverter.cs index acd57e03..304c41f0 100644 --- a/src/NerdBank.GitVersioning/FilterPathJsonConverter.cs +++ b/src/NerdBank.GitVersioning/FilterPathJsonConverter.cs @@ -22,7 +22,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist throw new NotSupportedException(); } - if (this.repoRelativeBaseDirectory == null) + if (this.repoRelativeBaseDirectory is null) { throw new ArgumentNullException(nameof(this.repoRelativeBaseDirectory), $"Base directory must not be null to be able to deserialize filter paths. Ensure that one was passed to {nameof(VersionOptions.GetJsonSettings)}, and that the version.json file is being written to a Git repository."); } @@ -37,7 +37,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s throw new NotSupportedException(); } - if (this.repoRelativeBaseDirectory == null) + if (this.repoRelativeBaseDirectory is null) { throw new ArgumentNullException(nameof(this.repoRelativeBaseDirectory), $"Base directory must not be null to be able to serialize filter paths. Ensure that one was passed to {nameof(VersionOptions.GetJsonSettings)}, and that the version.json file is being written to a Git repository."); } diff --git a/src/NerdBank.GitVersioning/LibGit2/LibGit2GitExtensions.cs b/src/NerdBank.GitVersioning/LibGit2/LibGit2GitExtensions.cs index 3d17c5f6..045c647a 100644 --- a/src/NerdBank.GitVersioning/LibGit2/LibGit2GitExtensions.cs +++ b/src/NerdBank.GitVersioning/LibGit2/LibGit2GitExtensions.cs @@ -60,13 +60,13 @@ internal static int GetVersionHeight(LibGit2Context context, Version? baseVersio var tracker = new GitWalkTracker(context); var versionOptions = tracker.GetVersion(context.Commit); - if (versionOptions == null) + if (versionOptions is null) { return 0; } var baseSemVer = - baseVersion != null ? SemanticVersion.Parse(baseVersion.ToString()) : + baseVersion is not null ? SemanticVersion.Parse(baseVersion.ToString()) : versionOptions.Version ?? SemVer0; var versionHeightPosition = versionOptions.VersionHeightPosition; @@ -174,7 +174,7 @@ public static IEnumerable GetCommitsFromVersion(LibGit2Context context, var tracker = new GitWalkTracker(context); var possibleCommits = from commit in GetCommitsReachableFromRefs(context.Repository) let commitVersionOptions = tracker.GetVersion(commit) - where commitVersionOptions != null + where commitVersionOptions is not null where !IsCommitIdMismatch(version, commitVersionOptions, commit) where !IsVersionHeightMismatch(version, commitVersionOptions, commit, tracker) select commit; @@ -221,7 +221,7 @@ private static bool CommitMatchesVersion(this Commit commit, SemanticVersion exp var commitVersionData = tracker.GetVersion(commit); var semVerFromFile = commitVersionData?.Version; - if (semVerFromFile == null) + if (semVerFromFile is null) { return false; } @@ -250,7 +250,7 @@ private static bool CommitMatchesVersion(this Commit commit, Version expectedVer var commitVersionData = tracker.GetVersion(commit); var semVerFromFile = commitVersionData?.Version; - if (semVerFromFile == null) + if (semVerFromFile is null) { return false; } @@ -422,7 +422,7 @@ bool TryCalculateHeight(Commit commit) int height = 1; - if (includePaths != null) + if (includePaths is not null) { // If there are no include paths, or any of the include // paths refer to the root of the repository, then do not @@ -527,8 +527,8 @@ internal static Version GetIdAsVersionHelper(this Commit? commit, VersionOptions // Don't use the ?? coalescing operator here because the position property getters themselves can return null, which should NOT be overridden with our default. // The default value is only appropriate if versionOptions itself is null. - var versionHeightPosition = versionOptions != null ? versionOptions.VersionHeightPosition : SemanticVersion.Position.Build; - var commitIdPosition = versionOptions != null ? versionOptions.GitCommitIdPosition : SemanticVersion.Position.Revision; + var versionHeightPosition = versionOptions is not null ? versionOptions.VersionHeightPosition : SemanticVersion.Position.Build; + var commitIdPosition = versionOptions is not null ? versionOptions.GitCommitIdPosition : SemanticVersion.Position.Revision; // The compiler (due to WinPE header requirements) only allows 16-bit version components, // and forbids 0xffff as a value. diff --git a/src/NerdBank.GitVersioning/Managed/ManagedGitContext.cs b/src/NerdBank.GitVersioning/Managed/ManagedGitContext.cs index d42f1aec..a6d4fab5 100644 --- a/src/NerdBank.GitVersioning/Managed/ManagedGitContext.cs +++ b/src/NerdBank.GitVersioning/Managed/ManagedGitContext.cs @@ -94,7 +94,7 @@ internal override int CalculateVersionHeight(VersionOptions? committedVersion, V { var workingCopyVersion = workingVersion?.Version?.Version; - if (workingCopyVersion == null || !workingCopyVersion.Equals(headCommitVersion)) + if (workingCopyVersion is null || !workingCopyVersion.Equals(headCommitVersion)) { // The working copy has changed the major.minor version. // So by definition the version height is 0, since no commit represents it yet. @@ -153,8 +153,8 @@ private Version GetIdAsVersionHelper(VersionOptions? versionOptions, int version // Don't use the ?? coalescing operator here because the position property getters themselves can return null, which should NOT be overridden with our default. // The default value is only appropriate if versionOptions itself is null. - var versionHeightPosition = versionOptions != null ? versionOptions.VersionHeightPosition : SemanticVersion.Position.Build; - var commitIdPosition = versionOptions != null ? versionOptions.GitCommitIdPosition : SemanticVersion.Position.Revision; + var versionHeightPosition = versionOptions is not null ? versionOptions.VersionHeightPosition : SemanticVersion.Position.Build; + var commitIdPosition = versionOptions is not null ? versionOptions.GitCommitIdPosition : SemanticVersion.Position.Revision; // The compiler (due to WinPE header requirements) only allows 16-bit version components, // and forbids 0xffff as a value. diff --git a/src/NerdBank.GitVersioning/Managed/ManagedGitExtensions.cs b/src/NerdBank.GitVersioning/Managed/ManagedGitExtensions.cs index 58b8206e..2f05103e 100644 --- a/src/NerdBank.GitVersioning/Managed/ManagedGitExtensions.cs +++ b/src/NerdBank.GitVersioning/Managed/ManagedGitExtensions.cs @@ -35,13 +35,13 @@ internal static int GetVersionHeight(ManagedGitContext context, Version? baseVer var tracker = new GitWalkTracker(context); var versionOptions = tracker.GetVersion(context.Commit.Value); - if (versionOptions == null) + if (versionOptions is null) { return 0; } var baseSemVer = - baseVersion != null ? SemanticVersion.Parse(baseVersion.ToString()) : + baseVersion is not null ? SemanticVersion.Parse(baseVersion.ToString()) : versionOptions.Version ?? SemVer0; var versionHeightPosition = versionOptions.VersionHeightPosition; @@ -69,7 +69,7 @@ private static bool CommitMatchesVersion(GitCommit commit, SemanticVersion expec var commitVersionData = tracker.GetVersion(commit); var semVerFromFile = commitVersionData?.Version; - if (commitVersionData == null || semVerFromFile == null) + if (commitVersionData is null || semVerFromFile is null) { return false; } @@ -167,7 +167,7 @@ bool TryCalculateHeight(GitCommit commit) int height = 1; - if (pathFilters != null) + if (pathFilters is not null) { var relevantCommit = true; @@ -250,7 +250,7 @@ private static bool IsRelevantCommit(GitRepository repository, GitTree tree, Git isRelevant = IsRelevantCommit( repository, repository.GetTree(entry.Sha), - parentEntry == null ? GitTree.Empty : repository.GetTree(parentEntry.Sha), + parentEntry is null ? GitTree.Empty : repository.GetTree(parentEntry.Sha), $"{fullPath}/", filters); } @@ -262,7 +262,7 @@ private static bool IsRelevantCommit(GitRepository repository, GitTree tree, Git } } - if (parentEntry != null) + if (parentEntry is not null) { parent.Children.Remove(child.Key); } diff --git a/src/NerdBank.GitVersioning/ManagedGit/GitCommitReader.cs b/src/NerdBank.GitVersioning/ManagedGit/GitCommitReader.cs index 25b22e49..8af84e05 100644 --- a/src/NerdBank.GitVersioning/ManagedGit/GitCommitReader.cs +++ b/src/NerdBank.GitVersioning/ManagedGit/GitCommitReader.cs @@ -38,7 +38,7 @@ public static class GitCommitReader /// public static GitCommit Read(Stream stream, GitObjectId sha, bool readAuthor = false) { - if (stream == null) + if (stream is null) { throw new ArgumentNullException(nameof(stream)); } diff --git a/src/NerdBank.GitVersioning/ManagedGit/GitObjectId.cs b/src/NerdBank.GitVersioning/ManagedGit/GitObjectId.cs index b18d04a9..76b5d672 100644 --- a/src/NerdBank.GitVersioning/ManagedGit/GitObjectId.cs +++ b/src/NerdBank.GitVersioning/ManagedGit/GitObjectId.cs @@ -174,7 +174,7 @@ public override bool Equals(object? obj) /// public override string ToString() { - if (this.sha == null) + if (this.sha is null) { this.sha = this.CreateString(0, 20); } diff --git a/src/NerdBank.GitVersioning/ManagedGit/GitPack.cs b/src/NerdBank.GitVersioning/ManagedGit/GitPack.cs index 5d19128d..576dd50d 100644 --- a/src/NerdBank.GitVersioning/ManagedGit/GitPack.cs +++ b/src/NerdBank.GitVersioning/ManagedGit/GitPack.cs @@ -146,7 +146,7 @@ public bool TryGetObject(GitObjectId objectId, string objectType, out Stream? va { var offset = this.GetOffset(objectId); - if (offset == null) + if (offset is null) { value = null; return false; @@ -268,7 +268,7 @@ public void Dispose() var indexReader = this.indexReader.Value; var offset = indexReader.GetOffset(objectId); - if (offset != null) + if (offset is not null) { this.offsets.Add(objectId, offset.Value); } diff --git a/src/NerdBank.GitVersioning/ManagedGit/GitPackDeltafiedStream.cs b/src/NerdBank.GitVersioning/ManagedGit/GitPackDeltafiedStream.cs index f2ab7d0e..3cff6c53 100644 --- a/src/NerdBank.GitVersioning/ManagedGit/GitPackDeltafiedStream.cs +++ b/src/NerdBank.GitVersioning/ManagedGit/GitPackDeltafiedStream.cs @@ -169,7 +169,7 @@ protected override void Dispose(bool disposing) private bool TryGetInstruction(out DeltaInstruction instruction) { - if (this.current != null && this.offset < this.current.Value.Size) + if (this.current is not null && this.offset < this.current.Value.Size) { instruction = this.current.Value; return true; @@ -177,7 +177,7 @@ private bool TryGetInstruction(out DeltaInstruction instruction) this.current = DeltaStreamReader.Read(this.deltaStream); - if (this.current == null) + if (this.current is null) { instruction = default; return false; diff --git a/src/NerdBank.GitVersioning/ManagedGit/GitPackIndexMappedReader.cs b/src/NerdBank.GitVersioning/ManagedGit/GitPackIndexMappedReader.cs index 279f0403..b3690166 100644 --- a/src/NerdBank.GitVersioning/ManagedGit/GitPackIndexMappedReader.cs +++ b/src/NerdBank.GitVersioning/ManagedGit/GitPackIndexMappedReader.cs @@ -32,7 +32,7 @@ public unsafe class GitPackIndexMappedReader : GitPackIndexReader /// public GitPackIndexMappedReader(FileStream stream) { - if (stream == null) + if (stream is null) { throw new ArgumentNullException(nameof(stream)); } diff --git a/src/NerdBank.GitVersioning/ManagedGit/GitPackReader.cs b/src/NerdBank.GitVersioning/ManagedGit/GitPackReader.cs index a1eba9ae..354060d4 100644 --- a/src/NerdBank.GitVersioning/ManagedGit/GitPackReader.cs +++ b/src/NerdBank.GitVersioning/ManagedGit/GitPackReader.cs @@ -13,12 +13,12 @@ internal static class GitPackReader public static Stream GetObject(GitPack pack, Stream stream, long offset, string objectType, GitPackObjectType packObjectType) { - if (pack == null) + if (pack is null) { throw new ArgumentNullException(nameof(pack)); } - if (stream == null) + if (stream is null) { throw new ArgumentNullException(nameof(stream)); } diff --git a/src/NerdBank.GitVersioning/ManagedGit/GitRepository.cs b/src/NerdBank.GitVersioning/ManagedGit/GitRepository.cs index 459f23c6..05e8fd53 100644 --- a/src/NerdBank.GitVersioning/ManagedGit/GitRepository.cs +++ b/src/NerdBank.GitVersioning/ManagedGit/GitRepository.cs @@ -192,7 +192,7 @@ public string ShortenObjectId(GitObjectId objectId, int minimum) { var objectish = sha.Substring(0, length); - if (this.Lookup(objectish) != null) + if (this.Lookup(objectish) is not null) { return objectish; } @@ -263,7 +263,7 @@ public GitCommit GetCommit(GitObjectId sha, bool readAuthor = false) { using (Stream? stream = this.GetObjectBySha(sha, "commit")) { - if (stream == null) + if (stream is null) { throw new GitException($"The commit {sha} was not found in this repository.") { ErrorCode = GitException.ErrorCodes.ObjectNotFound }; } @@ -396,7 +396,7 @@ public GitCommit GetCommit(GitObjectId sha, bool readAuthor = false) // It's possible for the same object to be present in both the object database and the pack files, // or in multiple pack files. - if (objectId != null && !possibleObjectIds.Contains(objectId.Value)) + if (objectId is not null && !possibleObjectIds.Contains(objectId.Value)) { if (possibleObjectIds.Count > 0) { @@ -435,7 +435,7 @@ public GitTree GetTree(GitObjectId sha) { using (Stream? stream = this.GetObjectBySha(sha, "tree")) { - if (stream == null) + if (stream is null) { throw new GitException($"The tree {sha} was not found in this repository.") { ErrorCode = GitException.ErrorCodes.ObjectNotFound }; } @@ -461,7 +461,7 @@ public GitObjectId GetTreeEntry(GitObjectId treeId, ReadOnlySpan nodeName) { using (Stream? treeStream = this.GetObjectBySha(treeId, "tree")) { - if (treeStream == null) + if (treeStream is null) { throw new GitException($"The tree {treeId} was not found in this repository.") { ErrorCode = GitException.ErrorCodes.ObjectNotFound }; } diff --git a/src/NerdBank.GitVersioning/ReleaseManager.cs b/src/NerdBank.GitVersioning/ReleaseManager.cs index e30efa6a..a59e4739 100644 --- a/src/NerdBank.GitVersioning/ReleaseManager.cs +++ b/src/NerdBank.GitVersioning/ReleaseManager.cs @@ -243,7 +243,7 @@ public void PrepareRelease(string projectDirectory, string releaseUnstableTag = // get the current version var versionOptions = context.VersionFile.GetVersion(); - if (versionOptions == null) + if (versionOptions is null) { this.stderr.WriteLine($"Failed to load version file for directory '{projectDirectory}'."); throw new ReleasePreparationException(ReleasePreparationError.NoVersionFile); @@ -274,7 +274,7 @@ public void PrepareRelease(string projectDirectory, string releaseUnstableTag = var nextDevVersion = this.GetNextDevVersion(versionOptions, nextVersion, versionIncrement); // check if the release branch already exists - if (repository.Branches[releaseBranchName] != null) + if (repository.Branches[releaseBranchName] is not null) { this.stderr.WriteLine($"Cannot create branch '{releaseBranchName}' because it already exists."); throw new ReleasePreparationException(ReleasePreparationError.BranchAlreadyExists); @@ -371,7 +371,7 @@ private void UpdateVersion(LibGit2Context context, SemanticVersion oldVersion, S private Signature GetSignature(Repository repository) { var signature = repository.Config.BuildSignature(DateTimeOffset.Now); - if (signature == null) + if (signature is null) { this.stderr.WriteLine("Cannot create commits in this repo because git user name and email are not configured."); throw new ReleasePreparationException(ReleasePreparationError.UserNotConfigured); @@ -430,7 +430,7 @@ private SemanticVersion GetNextDevVersion(VersionOptions versionOptions, Version var currentVersion = versionOptions.Version; SemanticVersion nextDevVersion; - if (nextVersionOverride != null) + if (nextVersionOverride is not null) { nextDevVersion = new SemanticVersion(nextVersionOverride, currentVersion.Prerelease, currentVersion.BuildMetadata); } diff --git a/src/NerdBank.GitVersioning/SemanticVersion.cs b/src/NerdBank.GitVersioning/SemanticVersion.cs index 9b503b46..ad07b529 100644 --- a/src/NerdBank.GitVersioning/SemanticVersion.cs +++ b/src/NerdBank.GitVersioning/SemanticVersion.cs @@ -155,7 +155,7 @@ internal enum Position /// /// Gets a value indicating whether this instance is the default "0.0" instance. /// - internal bool IsDefault => this.Version?.Major == 0 && this.Version.Minor == 0 && this.Version.Build == -1 && this.Version.Revision == -1 && this.Prerelease == null && this.BuildMetadata == null; + internal bool IsDefault => this.Version?.Major == 0 && this.Version.Minor == 0 && this.Version.Build == -1 && this.Version.Revision == -1 && this.Prerelease is null && this.BuildMetadata is null; /// /// Gets the debugger display for this instance. @@ -239,7 +239,7 @@ public override string ToString() /// true if the instances have equal values; false otherwise. public bool Equals(SemanticVersion other) { - if (other == null) + if (other is null) { return false; } diff --git a/src/NerdBank.GitVersioning/SemanticVersionJsonConverter.cs b/src/NerdBank.GitVersioning/SemanticVersionJsonConverter.cs index a064cb19..a4ae7f34 100644 --- a/src/NerdBank.GitVersioning/SemanticVersionJsonConverter.cs +++ b/src/NerdBank.GitVersioning/SemanticVersionJsonConverter.cs @@ -32,7 +32,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var version = value as SemanticVersion; - if (version != null) + if (version is not null) { writer.WriteValue(version.ToString()); return; diff --git a/src/NerdBank.GitVersioning/VersionOptions.cs b/src/NerdBank.GitVersioning/VersionOptions.cs index 7aee1dfa..cac77f86 100644 --- a/src/NerdBank.GitVersioning/VersionOptions.cs +++ b/src/NerdBank.GitVersioning/VersionOptions.cs @@ -570,9 +570,7 @@ internal bool IsDefaultVersionTheOnlyPropertySet { get { - return this.Version != null - && this.AssemblyVersion == null - && (this.CloudBuild?.IsDefault ?? true) + return this.Version is not null && this.AssemblyVersion is null && (this.CloudBuild?.IsDefault ?? true) && this.VersionHeightOffset == 0 && !this.SemVer1NumericIdentifierPadding.HasValue && !this.Inherit; @@ -693,7 +691,7 @@ public bool Equals(NuGetPackageVersionOptions? x, NuGetPackageVersionOptions? y) return true; } - if (x == null || y == null) + if (x is null || y is null) { return false; } @@ -1575,7 +1573,7 @@ public bool Equals(ReleaseOptions? x, ReleaseOptions? y) /// public int GetHashCode(ReleaseOptions? obj) { - if (obj == null) + if (obj is null) return 0; unchecked diff --git a/src/NerdBank.GitVersioning/VersionOracle.cs b/src/NerdBank.GitVersioning/VersionOracle.cs index 84c83019..93a11394 100644 --- a/src/NerdBank.GitVersioning/VersionOracle.cs +++ b/src/NerdBank.GitVersioning/VersionOracle.cs @@ -294,7 +294,7 @@ public IEnumerable BuildMetadataWithCommitId var properties = this.GetType().GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance); foreach (var property in properties) { - if (property.GetCustomAttribute() == null) + if (property.GetCustomAttribute() is null) { var value = property.GetValue(this); if (value is object) diff --git a/src/Nerdbank.GitVersioning.Tasks/ContextAwareTask.cs b/src/Nerdbank.GitVersioning.Tasks/ContextAwareTask.cs index b4c1e51b..f3bb3e17 100644 --- a/src/Nerdbank.GitVersioning.Tasks/ContextAwareTask.cs +++ b/src/Nerdbank.GitVersioning.Tasks/ContextAwareTask.cs @@ -31,11 +31,11 @@ public override bool Execute() var outerProperties = this.GetType().GetRuntimeProperties().ToDictionary(i => i.Name); var innerProperties = innerTaskType.GetRuntimeProperties().ToDictionary(i => i.Name); var propertiesDiscovery = from outerProperty in outerProperties.Values - where outerProperty.SetMethod != null && outerProperty.GetMethod != null + where outerProperty.SetMethod is not null && outerProperty.GetMethod is not null let innerProperty = innerProperties[outerProperty.Name] select new { outerProperty, innerProperty }; var propertiesMap = propertiesDiscovery.ToArray(); - var outputPropertiesMap = propertiesMap.Where(pair => pair.outerProperty.GetCustomAttribute() != null).ToArray(); + var outputPropertiesMap = propertiesMap.Where(pair => pair.outerProperty.GetCustomAttribute() is not null).ToArray(); foreach (var propertyPair in propertiesMap) { @@ -54,7 +54,7 @@ public override bool Execute() return result; #else // On .NET Framework (on Windows), we find native binaries by adding them to our PATH. - if (this.UnmanagedDllDirectory != null) + if (this.UnmanagedDllDirectory is not null) { string pathEnvVar = Environment.GetEnvironmentVariable("PATH"); string[] searchPaths = pathEnvVar.Split(Path.PathSeparator); diff --git a/src/Nerdbank.GitVersioning.Tasks/GetBuildVersion.cs b/src/Nerdbank.GitVersioning.Tasks/GetBuildVersion.cs index 2a9c00d4..77b79342 100644 --- a/src/Nerdbank.GitVersioning.Tasks/GetBuildVersion.cs +++ b/src/Nerdbank.GitVersioning.Tasks/GetBuildVersion.cs @@ -237,7 +237,7 @@ protected override bool ExecuteInner() oracle.PublicRelease = string.Equals(this.DefaultPublicRelease, "true", StringComparison.OrdinalIgnoreCase); } - if (this.BuildMetadata != null) + if (this.BuildMetadata is not null) { oracle.BuildMetadata.AddRange(this.BuildMetadata.Split(';')); } @@ -259,7 +259,7 @@ protected override bool ExecuteInner() this.PrereleaseVersion = oracle.PrereleaseVersion; this.GitCommitId = oracle.GitCommitId; this.GitCommitIdShort = oracle.GitCommitIdShort; - this.GitCommitDateTicks = oracle.GitCommitDate != null ? oracle.GitCommitDate.Value.UtcTicks.ToString(CultureInfo.InvariantCulture) : null; + this.GitCommitDateTicks = oracle.GitCommitDate is not null ? oracle.GitCommitDate.Value.UtcTicks.ToString(CultureInfo.InvariantCulture) : null; this.GitVersionHeight = oracle.VersionHeight; this.BuildMetadataFragment = oracle.BuildMetadataFragment; this.CloudBuildNumber = oracle.CloudBuildNumberEnabled ? oracle.CloudBuildNumber : null; @@ -279,7 +279,7 @@ protected override bool ExecuteInner() var allVariables = oracle.CloudBuildAllVars .Select(item => new TaskItem(item.Key, new Dictionary { { "Value", item.Value } })); - if (cloudBuildVersionVars != null) + if (cloudBuildVersionVars is not null) { cloudBuildVersionVars = cloudBuildVersionVars .Union(allVariables); @@ -290,7 +290,7 @@ protected override bool ExecuteInner() } } - if (cloudBuildVersionVars != null) + if (cloudBuildVersionVars is not null) { this.CloudBuildVersionVars = cloudBuildVersionVars.ToArray(); } diff --git a/src/Nerdbank.GitVersioning.Tasks/NativeVersionInfo.cs b/src/Nerdbank.GitVersioning.Tasks/NativeVersionInfo.cs index 8709c89e..8153a545 100644 --- a/src/Nerdbank.GitVersioning.Tasks/NativeVersionInfo.cs +++ b/src/Nerdbank.GitVersioning.Tasks/NativeVersionInfo.cs @@ -106,7 +106,7 @@ BLOCK NBGV_VERSION_BLOCK public override bool Execute() { this.generator = this.CreateGenerator(); - if (this.generator != null) + if (this.generator is not null) { this.generator.StartFile(); @@ -300,7 +300,7 @@ protected void AddCodeComment(string comment, string token) { var sr = new StringReader(comment); string line; - while ((line = sr.ReadLine()) != null) + while ((line = sr.ReadLine()) is not null) { this.codeBuilder.Append(token); this.codeBuilder.AppendLine(line); diff --git a/src/Nerdbank.GitVersioning.Tasks/SetCloudBuildVariables.cs b/src/Nerdbank.GitVersioning.Tasks/SetCloudBuildVariables.cs index 9939043d..b721152c 100644 --- a/src/Nerdbank.GitVersioning.Tasks/SetCloudBuildVariables.cs +++ b/src/Nerdbank.GitVersioning.Tasks/SetCloudBuildVariables.cs @@ -20,7 +20,7 @@ public class SetCloudBuildVariables : Task public override bool Execute() { var cloudBuild = CloudBuild.Active; - if (cloudBuild != null) + if (cloudBuild is not null) { var envVars = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -42,7 +42,7 @@ public override bool Execute() } } - if (this.CloudBuildVersionVars != null) + if (this.CloudBuildVersionVars is not null) { foreach (var variable in this.CloudBuildVersionVars) { @@ -82,7 +82,7 @@ private void PipeOutputToMSBuildLog(string output, bool warning) using (var logReader = new StringReader(output)) { string line; - while ((line = logReader.ReadLine()) != null) + while ((line = logReader.ReadLine()) is not null) { // The prefix is presumed to nullify the effect in a real cloud build, // yet make it detectable by a unit test. diff --git a/src/nbgv/Program.cs b/src/nbgv/Program.cs index 7df6b7bf..e9ae5d75 100644 --- a/src/nbgv/Program.cs +++ b/src/nbgv/Program.cs @@ -282,7 +282,7 @@ private static int OnInstallCommand(string path, string version, IReadOnlyList met } var oracle = new VersionOracle(context, CloudBuild.Active); - if (metadata != null) + if (metadata is not null) { oracle.BuildMetadata.AddRange(metadata); } @@ -418,7 +418,7 @@ private static int OnGetVersionCommand(string project, IReadOnlyList met } var property = oracle.GetType().GetProperty(variable, CaseInsensitiveFlags); - if (property == null) + if (property is null) { Console.Error.WriteLine("Variable \"{0}\" not a version property.", variable); return (int)ExitCodes.BadVariable; @@ -447,7 +447,7 @@ private static int OnSetVersionCommand(string project, string version) using var context = GitContext.Create(searchPath, writable: true); var existingOptions = context.VersionFile.GetVersion(out string actualDirectory); string versionJsonPath; - if (existingOptions != null) + if (existingOptions is not null) { existingOptions.Version = semver; versionJsonPath = context.VersionFile.SetVersion(actualDirectory, existingOptions); @@ -598,7 +598,7 @@ private static int OnCloudCommand(string project, IReadOnlyList metadata using var context = GitContext.Create(searchPath, writable: AlwaysUseLibGit2); var oracle = new VersionOracle(context, cloudBuild: activeCloudBuild); - if (metadata != null) + if (metadata is not null) { oracle.BuildMetadata.AddRange(metadata); } @@ -620,7 +620,7 @@ private static int OnCloudCommand(string project, IReadOnlyList metadata } } - if (define != null) + if (define is not null) { foreach (string def in define) { @@ -641,7 +641,7 @@ private static int OnCloudCommand(string project, IReadOnlyList metadata } } - if (activeCloudBuild != null) + if (activeCloudBuild is not null) { if (string.IsNullOrEmpty(version)) {