Skip to content

Commit 9c93a82

Browse files
author
roeil
committed
pr
1 parent bcb63b0 commit 9c93a82

File tree

11 files changed

+34
-36
lines changed

11 files changed

+34
-36
lines changed

src/GitVersion.Configuration/IgnoreConfiguration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ public string? BeforeString
2424
[JsonPropertyDescription("A sequence of SHAs to be excluded from the version calculations.")]
2525
public HashSet<string> Shas { get; init; } = [];
2626

27-
[JsonIgnore]
28-
public bool IsEmpty => Before == null && Shas.Count == 0 && Paths.Count == 0;
29-
3027
IReadOnlyCollection<string> IIgnoreConfiguration.Paths => Paths;
3128

3229
[JsonPropertyName("paths")]
3330
[JsonPropertyDescription("A sequence of file paths to be excluded from the version calculations.")]
3431
public Collection<string> Paths { get; init; } = [];
32+
33+
[JsonIgnore]
34+
public bool IsEmpty => Before == null && Shas.Count == 0 && Paths.Count == 0;
3535
}

src/GitVersion.Core.Tests/VersionCalculation/Strategies/MergeMessageBaseVersionStrategyTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ private class MockCommit : ICommit
204204
public IObjectId Id => throw new NotImplementedException();
205205
public string Sha => throw new NotImplementedException();
206206
public IReadOnlyList<ICommit> Parents => throw new NotImplementedException();
207-
public IEnumerable<string> DiffPaths => throw new NotImplementedException();
207+
public IReadOnlyList<string> DiffPaths => throw new NotImplementedException();
208208
public DateTimeOffset When => throw new NotImplementedException();
209209
public string Message => throw new NotImplementedException();
210210
}

src/GitVersion.Core/Configuration/IIgnoreConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ public interface IIgnoreConfiguration
88

99
IReadOnlyCollection<string> Paths { get; }
1010

11-
bool IsEmpty => Before == null && Shas.Count == 0 && Paths.Count == 0;
11+
bool IsEmpty { get; }
1212
}

src/GitVersion.Core/Extensions/ConfigurationExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static EffectiveConfiguration GetEffectiveConfiguration(
2525
{
2626
fallbackConfiguration = parentConfiguration;
2727
}
28-
return new EffectiveConfiguration(configuration, branchConfiguration, fallbackConfiguration: fallbackConfiguration);
28+
return new EffectiveConfiguration(configuration, branchConfiguration, fallbackConfiguration);
2929
}
3030

3131
public static IBranchConfiguration GetBranchConfiguration(this IGitVersionConfiguration configuration, IBranch branch)
@@ -44,7 +44,7 @@ public static IEnumerable<IVersionFilter> ToFilters(this IIgnoreConfiguration so
4444

4545
if (source.Shas.Count != 0) yield return new ShaVersionFilter(source.Shas);
4646
if (source.Before.HasValue) yield return new MinDateVersionFilter(source.Before.Value);
47-
if (source.Paths.Count != 0) yield return new PathFilter(source.Paths);
47+
if (source.Paths.Count != 0) yield return new PathFilter(source.Paths.ToList());
4848
}
4949

5050
private static IEnumerable<IBranchConfiguration> GetBranchConfigurations(IGitVersionConfiguration configuration, string branchName)

src/GitVersion.Core/Git/ICommit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ public interface ICommit : IEquatable<ICommit?>, IComparable<ICommit>, IGitObjec
77
DateTimeOffset When { get; }
88

99
string Message { get; }
10-
IEnumerable<string> DiffPaths { get; }
10+
IReadOnlyList<string> DiffPaths { get; }
1111
}

src/GitVersion.Core/Git/ITreeChanges.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ namespace GitVersion.Git;
22

33
public interface ITreeChanges
44
{
5-
IEnumerable<string> Paths { get; }
5+
IReadOnlyList<string> Paths { get; }
66
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#nullable enable
22
GitVersion.Configuration.IIgnoreConfiguration.Paths.get -> System.Collections.Generic.IReadOnlyCollection<string!>!
3-
GitVersion.Git.ICommit.DiffPaths.get -> System.Collections.Generic.IEnumerable<string!>!
3+
GitVersion.Git.ICommit.DiffPaths.get -> System.Collections.Generic.IReadOnlyList<string!>!
44
GitVersion.Git.ITreeChanges
5-
GitVersion.Git.ITreeChanges.Paths.get -> System.Collections.Generic.IEnumerable<string!>!
5+
GitVersion.Git.ITreeChanges.Paths.get -> System.Collections.Generic.IReadOnlyList<string!>!
66
GitVersion.VersionCalculation.IVersionFilter.Exclude(GitVersion.Git.ICommit! commit, out string? reason) -> bool

src/GitVersion.Core/VersionCalculation/PathFilter.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
using System.Collections.Concurrent;
12
using System.Diagnostics.CodeAnalysis;
23
using System.Text.RegularExpressions;
34
using GitVersion.Git;
45

56
namespace GitVersion.VersionCalculation;
67

7-
internal class PathFilter( IEnumerable<string> paths) : IVersionFilter
8+
internal class PathFilter(IReadOnlyList<string> paths) : IVersionFilter
89
{
9-
private readonly List<Regex> pathsRegexes = paths.Select(path => new Regex(path, RegexOptions.IgnoreCase | RegexOptions.Compiled)).ToList();
10-
private readonly Dictionary<string, bool> pathMatchCache = [];
10+
private readonly List<Regex> pathsRegexes = [.. paths.Select(path => new Regex(path, RegexOptions.IgnoreCase | RegexOptions.Compiled))];
11+
private readonly ConcurrentDictionary<string, bool> pathMatchCache = [];
1112

1213
public bool Exclude(IBaseVersion baseVersion, [NotNullWhen(true)] out string? reason)
1314
{
@@ -27,21 +28,18 @@ public bool Exclude(ICommit? commit, [NotNullWhen(true)] out string? reason)
2728
{
2829
var patchPaths = commit.DiffPaths;
2930

30-
if (patchPaths != null)
31+
foreach (var path in patchPaths)
3132
{
32-
foreach (var path in patchPaths)
33+
if (!pathMatchCache.TryGetValue(path, out var isMatch))
3334
{
34-
if (!pathMatchCache.TryGetValue(path, out var isMatch))
35-
{
36-
isMatch = this.pathsRegexes.Any(regex => regex.IsMatch(path));
37-
pathMatchCache[path] = isMatch;
38-
}
39-
40-
if (isMatch)
41-
{
42-
reason = "Source was ignored due to commit path matching ignore regex";
43-
return true;
44-
}
35+
isMatch = this.pathsRegexes.Any(regex => regex.IsMatch(path));
36+
pathMatchCache[path] = isMatch;
37+
}
38+
39+
if (isMatch)
40+
{
41+
reason = "Source was ignored due to commit path matching ignore regex";
42+
return true;
4543
}
4644
}
4745
}

src/GitVersion.LibGit2Sharp/Git/Commit.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,21 @@ internal Commit(LibGit2Sharp.Commit innerCommit, LibGit2Sharp.Diff repoDiff) : b
2828
public DateTimeOffset When { get; }
2929
public string Message => this.innerCommit.Message;
3030
// TODO implement tag prefix filtering before returning the paths.
31-
public IEnumerable<string> DiffPaths
31+
public IReadOnlyList<string> DiffPaths
3232
{
3333
get
3434
{
35-
if (pathsCache.TryGetValue(this.Sha, out var paths))
36-
return paths;
37-
else
38-
return this.CommitChanges?.Paths ?? [];
35+
if (!pathsCache.TryGetValue(this.Sha, out var paths))
36+
{
37+
paths = this.CommitChanges?.Paths ?? [];
38+
pathsCache[this.Sha] = paths;
39+
}
40+
return paths;
3941
}
4042
}
4143
public override bool Equals(object? obj) => Equals(obj as ICommit);
4244
public override int GetHashCode() => equalityHelper.GetHashCode(this);
4345
public override string ToString() => $"'{Id.ToString(7)}' - {this.innerCommit.MessageShort}";
4446
public static implicit operator LibGit2Sharp.Commit(Commit d) => d.innerCommit;
45-
private ITreeChanges CommitChanges => new TreeChanges(this.repoDiff.Compare<LibGit2Sharp.TreeChanges>(this.innerCommit.Tree, this.innerCommit.Parents.FirstOrDefault()?.Tree));
47+
private TreeChanges CommitChanges => new TreeChanges(this.repoDiff.Compare<LibGit2Sharp.TreeChanges>(this.innerCommit.Tree, this.innerCommit.Parents.FirstOrDefault()?.Tree));
4648
}

src/GitVersion.LibGit2Sharp/Git/GitRepository.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Collections.Concurrent;
21
using GitVersion.Extensions;
32
using GitVersion.Helpers;
43
using LibGit2Sharp;
@@ -8,7 +7,6 @@ namespace GitVersion.Git;
87
internal sealed partial class GitRepository
98
{
109
private Lazy<IRepository>? repositoryLazy;
11-
private readonly ConcurrentDictionary<string, IReadOnlyList<string>?> patchPathsCache = new();
1210

1311
private IRepository RepositoryInstance
1412
{

src/GitVersion.LibGit2Sharp/Git/TreeChanges.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ internal sealed class TreeChanges(LibGit2Sharp.TreeChanges innerTreeChanges) : I
44
{
55
private readonly LibGit2Sharp.TreeChanges innerTreeChanges = innerTreeChanges ?? throw new ArgumentNullException(nameof(innerTreeChanges));
66

7-
public IEnumerable<string> Paths => this.innerTreeChanges.Select(element => element.Path);
7+
public IReadOnlyList<string> Paths => [.. this.innerTreeChanges.Select(element => element.Path)];
88
}

0 commit comments

Comments
 (0)