Skip to content

Commit aa11c77

Browse files
AArnottrhodosaurqmfrederikfilipnavara
authored
Merge v3.4 to master (#645)
* Switch from PInvoke nuget dependency to CsWin32 Fixes #615 * Update CsWin32 to fix `dotnet build` * Remove dotnet/pinvoke from 3rd party licenses file * include 5E and DA values in zlib header check * ditch linq for exception * 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 * Bump libgit2sharp to 0.27.0-preview-0102 * Run 32-bit tests * GitPack: Don't use MemoryMappedFiles in 32-bit processes * Make sure Streams are disposed of. * Fix bugs with > 2 GB pack files * Apply suggestions from code review Co-authored-by: Andrew Arnott <[email protected]> * Apply `is null` pattern and analyzer Co-authored-by: rhodosaur <[email protected]> Co-authored-by: Frederik Carlier <[email protected]> Co-authored-by: Filip Navara <[email protected]>
2 parents 5789043 + 813cbf1 commit aa11c77

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+215
-152
lines changed

.editorconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,9 @@ csharp_new_line_before_catch = true
7979
csharp_new_line_before_finally = true
8080
csharp_new_line_before_members_in_object_initializers = true
8181
csharp_new_line_before_members_in_anonymous_types = true
82+
83+
# CSIsNull001: Use `is null` for null checks
84+
dotnet_diagnostic.CSIsNull001.severity = warning
85+
86+
# CSIsNull002: Use `is object` for non-null checks
87+
dotnet_diagnostic.CSIsNull002.severity = warning

3rdPartyNotices.txt

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -127,31 +127,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
127127
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
128128
SOFTWARE.
129129

130-
dotnet/PInvoke (https://github.com/dotnet/pinvoke)
131-
==============
132-
133-
MIT License
134-
135-
Copyright (c) .NET Foundation and Contributors
136-
137-
Permission is hereby granted, free of charge, to any person obtaining a copy
138-
of this software and associated documentation files (the "Software"), to deal
139-
in the Software without restriction, including without limitation the rights
140-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
141-
copies of the Software, and to permit persons to whom the Software is
142-
furnished to do so, subject to the following conditions:
143-
144-
The above copyright notice and this permission notice shall be included in all
145-
copies or substantial portions of the Software.
146-
147-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
148-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
149-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
150-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
151-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
152-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
153-
SOFTWARE.
154-
155130
Cake Contrib (https://github.com/cake-contrib/graphics)
156131
============
157132

azure-pipelines.yml

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ stages:
4343
windows:
4444
imageName: 'windows-2019'
4545
testModifier:
46+
dotnet32: "\"C:\\Program Files (x86)\\dotnet\\dotnet.exe\""
4647
variables:
4748
- ${{ if eq(variables['System.TeamFoundationCollectionUri'], 'https://dev.azure.com/andrewarnott/') }}:
4849
- group: dotnetfoundation code signing
@@ -58,17 +59,24 @@ stages:
5859
displayName: Configure git commit author for testing
5960
6061
- task: UseDotNet@2
61-
displayName: Install .NET Core SDK 5.0.202
62+
displayName: Install .NET Core 5.0.202 SDK
6263
inputs:
6364
packageType: sdk
6465
version: 5.0.202
6566

6667
- task: UseDotNet@2
67-
displayName: Install .NET Core 3.1
68+
displayName: Install .NET Core 3.1 runtime
6869
inputs:
6970
packageType: runtime
7071
version: 3.1.x
7172

73+
- pwsh: |
74+
Invoke-WebRequest -Uri "https://dot.net/v1/dotnet-install.ps1" -OutFile dotnet-install.ps1
75+
& .\dotnet-install.ps1 -Architecture x86 -Version 5.0.202 -InstallDir "C:\Program Files (x86)\dotnet\" -NoPath -Verbose
76+
& .\dotnet-install.ps1 -Architecture x86 -Channel 3.1 -InstallDir "C:\Program Files (x86)\dotnet\" -NoPath -Verbose
77+
displayName: Install 32-bit .NET Core SDK 5.0.202, 3.1
78+
condition: ne(variables['dotnet32'], '')
79+
7280
- script: dotnet --info
7381
displayName: Show dotnet SDK info
7482

@@ -121,8 +129,22 @@ stages:
121129
--collect:"XPlat Code Coverage"
122130
--
123131
RunConfiguration.DisableAppDomain=true
124-
displayName: Run tests
132+
displayName: Run x64 tests
133+
workingDirectory: src
134+
135+
- script: >
136+
$(dotnet32) test NerdBank.GitVersioning.Tests
137+
--no-build $(testModifier)
138+
-c $(BuildConfiguration)
139+
--filter "TestCategory!=FailsOnAzurePipelines"
140+
--logger "trx;LogFileName=$(Build.ArtifactStagingDirectory)/TestLogs/TestResults.trx"
141+
--results-directory $(Build.ArtifactStagingDirectory)/CodeCoverage/
142+
--collect:"XPlat Code Coverage"
143+
--
144+
RunConfiguration.DisableAppDomain=true
145+
displayName: Run x86 tests
125146
workingDirectory: src
147+
condition: ne(variables['dotnet32'], '')
126148
127149
- task: PublishCodeCoverageResults@1
128150
displayName: Publish code coverage results
@@ -296,17 +318,17 @@ stages:
296318
vmImage: $(imageName)
297319
steps:
298320
- task: UseDotNet@2
299-
displayName: Install .NET Core SDK 2.1.811
321+
displayName: Install .NET Core 2.1 runtime
300322
inputs:
301-
packageType: sdk
302-
version: 2.1.811
323+
packageType: runtime
324+
version: 2.1.x
303325
- task: UseDotNet@2
304-
displayName: Install .NET Core SDK 3.1.100
326+
displayName: Install .NET Core 3.1 runtime
305327
inputs:
306-
packageType: sdk
307-
version: 3.1.100
328+
packageType: runtime
329+
version: 3.1.x
308330
- task: UseDotNet@2
309-
displayName: Install .NET Core SDK 5.0.202
331+
displayName: Install .NET Core 5.0.202 SDK
310332
inputs:
311333
packageType: sdk
312334
version: 5.0.202

src/Directory.Build.props

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@
2424
<LibGit2SharpNativeVersion>2.0.312</LibGit2SharpNativeVersion>
2525
</PropertyGroup>
2626
<ItemGroup>
27-
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="3.10.0" PrivateAssets="all" />
27+
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="3.11.0" PrivateAssets="all" />
2828
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
2929
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
30+
<PackageReference Include="CSharpIsNullAnalyzer" Version="0.1.288-beta">
31+
<PrivateAssets>all</PrivateAssets>
32+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
33+
</PackageReference>
3034
</ItemGroup>
3135
<ItemGroup>
3236
<None Include="$(MSBuildThisFileDirectory)..\3rdPartyNotices.txt" Pack="true" PackagePath="" />

src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public async Task GetBuildVersion_In_Git_But_Head_Lacks_VersionFile()
219219
var repo = new Repository(this.RepoPath); // do not assign Repo property to avoid commits being generated later
220220
repo.Commit("empty", this.Signer, this.Signer, new CommitOptions { AllowEmptyCommit = true });
221221
this.WriteVersionFile("3.4");
222-
Assumes.True(repo.Index[VersionFile.JsonFileName] == null);
222+
Assumes.True(repo.Index[VersionFile.JsonFileName] is null);
223223
var buildResult = await this.BuildAsync();
224224
Assert.Equal("3.4.0." + this.GetVersion().Revision, buildResult.BuildVersion);
225225
Assert.Equal("3.4.0+" + repo.Head.Tip.Id.Sha.Substring(0, VersionOptions.DefaultGitCommitIdShortFixedLength), buildResult.AssemblyInformationalVersion);

src/NerdBank.GitVersioning.Tests/ManagedGit/DeltaStreamReaderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void ReadStreamTest()
8989

9090
DeltaInstruction? current;
9191

92-
while ((current = DeltaStreamReader.Read(stream)) != null)
92+
while ((current = DeltaStreamReader.Read(stream)) is not null)
9393
{
9494
instructions.Add(current.Value);
9595
}
@@ -139,7 +139,7 @@ public void ReadStreamTest_Memory()
139139

140140
DeltaInstruction? current;
141141

142-
while ((current = DeltaStreamReader.Read(ref memory)) != null)
142+
while ((current = DeltaStreamReader.Read(ref memory)) is not null)
143143
{
144144
instructions.Add(current.Value);
145145
}

src/NerdBank.GitVersioning.Tests/ManagedGit/GitPackTests.cs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ public void GetPackedObject()
6363
// This commit is not deltafied. It is stored as a .gz-compressed stream in the pack file.
6464
var zlibStream = Assert.IsType<ZLibStream>(commitStream);
6565
var deflateStream = Assert.IsType<DeflateStream>(zlibStream.BaseStream);
66-
var pooledStream = Assert.IsType<MemoryMappedStream>(deflateStream.BaseStream);
66+
67+
if (IntPtr.Size > 4)
68+
{
69+
var pooledStream = Assert.IsType<MemoryMappedStream>(deflateStream.BaseStream);
70+
}
71+
else
72+
{
73+
var pooledStream = Assert.IsType<FileStream>(deflateStream.BaseStream);
74+
}
6775

6876
Assert.Equal(222, commitStream.Length);
6977
Assert.Equal("/zgldANj+jvgOwlecnOKylZDVQg=", Convert.ToBase64String(sha.ComputeHash(commitStream)));
@@ -85,7 +93,15 @@ public void GetDeltafiedObject()
8593
var deltaStream = Assert.IsType<GitPackDeltafiedStream>(commitStream);
8694
var zlibStream = Assert.IsType<ZLibStream>(deltaStream.BaseStream);
8795
var deflateStream = Assert.IsType<DeflateStream>(zlibStream.BaseStream);
88-
var pooledStream = Assert.IsType<MemoryMappedStream>(deflateStream.BaseStream);
96+
97+
if (IntPtr.Size > 4)
98+
{
99+
var pooledStream = Assert.IsType<MemoryMappedStream>(deflateStream.BaseStream);
100+
}
101+
else
102+
{
103+
var directAccessStream = Assert.IsType<FileStream>(deflateStream.BaseStream);
104+
}
89105

90106
Assert.Equal(137, commitStream.Length);
91107
Assert.Equal("lZu/7nGb0n1UuO9SlPluFnSvj4o=", Convert.ToBase64String(sha.ComputeHash(commitStream)));
@@ -120,14 +136,24 @@ public void TryGetObjectTest()
120136
using (SHA1 sha = SHA1.Create())
121137
{
122138
Assert.True(gitPack.TryGetObject(GitObjectId.Parse("f5b401f40ad83f13030e946c9ea22cb54cb853cd"), "commit", out Stream commitStream));
139+
using (commitStream)
140+
{
141+
// This commit is not deltafied. It is stored as a .gz-compressed stream in the pack file.
142+
var zlibStream = Assert.IsType<ZLibStream>(commitStream);
143+
var deflateStream = Assert.IsType<DeflateStream>(zlibStream.BaseStream);
123144

124-
// This commit is not deltafied. It is stored as a .gz-compressed stream in the pack file.
125-
var zlibStream = Assert.IsType<ZLibStream>(commitStream);
126-
var deflateStream = Assert.IsType<DeflateStream>(zlibStream.BaseStream);
127-
var pooledStream = Assert.IsType<MemoryMappedStream>(deflateStream.BaseStream);
145+
if (IntPtr.Size > 4)
146+
{
147+
var pooledStream = Assert.IsType<MemoryMappedStream>(deflateStream.BaseStream);
148+
}
149+
else
150+
{
151+
var directAccessStream = Assert.IsType<FileStream>(deflateStream.BaseStream);
152+
}
128153

129-
Assert.Equal(222, commitStream.Length);
130-
Assert.Equal("/zgldANj+jvgOwlecnOKylZDVQg=", Convert.ToBase64String(sha.ComputeHash(commitStream)));
154+
Assert.Equal(222, commitStream.Length);
155+
Assert.Equal("/zgldANj+jvgOwlecnOKylZDVQg=", Convert.ToBase64String(sha.ComputeHash(commitStream)));
156+
}
131157
}
132158
}
133159

src/NerdBank.GitVersioning.Tests/ReleaseManagerTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ public void PrepareRelease_Master(
320320

321321
// prepare release
322322
var releaseManager = new ReleaseManager();
323-
releaseManager.PrepareRelease(this.RepoPath, releaseUnstableTag, (nextVersion == null ? null : Version.Parse(nextVersion)), parameterVersionIncrement);
323+
releaseManager.PrepareRelease(this.RepoPath, releaseUnstableTag, (nextVersion is null ? null : Version.Parse(nextVersion)), parameterVersionIncrement);
324324

325325
// check if a branch was created
326326
Assert.Contains(this.LibGit2Repository.Branches, branch => branch.FriendlyName == expectedBranchName);
@@ -394,7 +394,7 @@ public void PrepareRelease_MasterWithVersionDecrement(string initialVersion, str
394394
// running PrepareRelease should result in an error
395395
// because we're setting the version on master to a lower version
396396
this.AssertError(
397-
() => new ReleaseManager().PrepareRelease(this.RepoPath, releaseUnstableTag, (nextVersion == null ? null : Version.Parse(nextVersion))),
397+
() => new ReleaseManager().PrepareRelease(this.RepoPath, releaseUnstableTag, (nextVersion is null ? null : Version.Parse(nextVersion))),
398398
ReleasePreparationError.VersionDecrement);
399399
}
400400

@@ -412,7 +412,7 @@ public void PrepareRelease_MasterWithoutVersionIncrement(string initialVersion,
412412
// running PrepareRelease should result in an error
413413
// because we're trying to set master to the version it already has
414414
this.AssertError(
415-
() => new ReleaseManager().PrepareRelease(this.RepoPath, null, (nextVersion == null ? null : Version.Parse(nextVersion))),
415+
() => new ReleaseManager().PrepareRelease(this.RepoPath, null, (nextVersion is null ? null : Version.Parse(nextVersion))),
416416
ReleasePreparationError.NoVersionIncrement);
417417
}
418418

src/NerdBank.GitVersioning.Tests/RepoTestBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ protected void AddCommits(int count = 1)
143143

144144
protected Commit? WriteVersionTxtFile(string version = "1.2", string prerelease = "", string? relativeDirectory = null)
145145
{
146-
if (relativeDirectory == null)
146+
if (relativeDirectory is null)
147147
{
148148
relativeDirectory = string.Empty;
149149
}
@@ -163,7 +163,7 @@ protected void AddCommits(int count = 1)
163163
{
164164
Requires.NotNull(versionData, nameof(versionData));
165165

166-
if (relativeDirectory == null)
166+
if (relativeDirectory is null)
167167
{
168168
relativeDirectory = string.Empty;
169169
}
@@ -197,7 +197,7 @@ protected void AddCommits(int count = 1)
197197
if (Path.GetExtension(relativeFilePath) == ".json")
198198
{
199199
string txtFilePath = relativeFilePath.Substring(0, relativeFilePath.Length - 4) + "txt";
200-
if (!File.Exists(Path.Combine(this.RepoPath, txtFilePath)) && this.LibGit2Repository.Index[txtFilePath] != null)
200+
if (!File.Exists(Path.Combine(this.RepoPath, txtFilePath)) && this.LibGit2Repository.Index[txtFilePath] is not null)
201201
{
202202
this.LibGit2Repository.Index.Remove(txtFilePath);
203203
}

src/NerdBank.GitVersioning.Tests/TestUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal static void ExtractEmbeddedResource(string resourcePath, string extract
5454

5555
using (var stream = GetEmbeddedResource(resourcePath))
5656
{
57-
Requires.Argument(stream != null, nameof(resourcePath), "Resource not found.");
57+
Requires.Argument(stream is not null, nameof(resourcePath), "Resource not found.");
5858
using (var extractedFile = File.OpenWrite(extractedFilePath))
5959
{
6060
stream.CopyTo(extractedFile);

0 commit comments

Comments
 (0)