diff --git a/src/GitVersion.Core/Configuration/IgnoreConfigurationExtensions.cs b/src/GitVersion.Core/Configuration/IgnoreConfigurationExtensions.cs index d99c33db76..eeaf3a0ded 100644 --- a/src/GitVersion.Core/Configuration/IgnoreConfigurationExtensions.cs +++ b/src/GitVersion.Core/Configuration/IgnoreConfigurationExtensions.cs @@ -5,28 +5,20 @@ namespace GitVersion.Configuration; internal static class IgnoreConfigurationExtensions { - public static IEnumerable Filter(this IIgnoreConfiguration ignore, IEnumerable source) + public static IEnumerable Filter(this IIgnoreConfiguration ignore, ITag[] source) { ignore.NotNull(); source.NotNull(); - if (!ignore.IsEmpty) - { - return source.Where(element => ShouldBeIgnored(element.Commit, ignore)); - } - return source; + return !ignore.IsEmpty ? source.Where(element => ShouldBeIgnored(element.Commit, ignore)) : source; } - public static IEnumerable Filter(this IIgnoreConfiguration ignore, IEnumerable source) + public static IEnumerable Filter(this IIgnoreConfiguration ignore, ICommit[] source) { ignore.NotNull(); source.NotNull(); - if (!ignore.IsEmpty) - { - return source.Where(element => ShouldBeIgnored(element, ignore)); - } - return source; + return !ignore.IsEmpty ? source.Where(element => ShouldBeIgnored(element, ignore)) : source; } private static bool ShouldBeIgnored(ICommit commit, IIgnoreConfiguration ignore) diff --git a/src/GitVersion.Core/Core/RepositoryStore.cs b/src/GitVersion.Core/Core/RepositoryStore.cs index aaa1856c15..bc8554f32e 100644 --- a/src/GitVersion.Core/Core/RepositoryStore.cs +++ b/src/GitVersion.Core/Core/RepositoryStore.cs @@ -60,7 +60,7 @@ internal class RepositoryStore(ILog log, IGitRepository repository) : IRepositor this.log.Info("Using latest commit on specified branch"); } - commits = ignore.Filter(commits); + commits = ignore.Filter(commits.ToArray()); return commits.FirstOrDefault(); } @@ -219,8 +219,7 @@ public IReadOnlyList GetCommitLog(ICommit? baseVersionSource, ICommit c SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Time }; - var commits = this.repository.Commits.QueryBy(filter); - + var commits = FilterCommits(filter).ToArray(); return ignore.Filter(commits).ToList(); } @@ -232,16 +231,16 @@ public IReadOnlyList GetCommitsReacheableFromHead(ICommit? headCommit, SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Reverse }; - var commits = this.repository.Commits.QueryBy(filter); + var commits = FilterCommits(filter).ToArray(); return ignore.Filter(commits).ToList(); } public IReadOnlyList GetCommitsReacheableFrom(IGitObject commit, IBranch branch) { var filter = new CommitFilter { IncludeReachableFrom = branch }; - var commitCollection = this.repository.Commits.QueryBy(filter); - return commitCollection.Where(c => c.Sha == commit.Sha).ToList(); + var commits = FilterCommits(filter); + return commits.Where(c => c.Sha == commit.Sha).ToList(); } public ICommit? GetForwardMerge(ICommit? commitToFindCommonBase, ICommit? findMergeBase) @@ -251,18 +250,20 @@ public IReadOnlyList GetCommitsReacheableFrom(IGitObject commit, IBranc IncludeReachableFrom = commitToFindCommonBase, ExcludeReachableFrom = findMergeBase }; - var commitCollection = this.repository.Commits.QueryBy(filter); - return commitCollection.FirstOrDefault(c => c.Parents.Contains(findMergeBase)); + var commits = FilterCommits(filter); + return commits.FirstOrDefault(c => c.Parents.Contains(findMergeBase)); } public bool IsCommitOnBranch(ICommit? baseVersionSource, IBranch branch, ICommit firstMatchingCommit) { var filter = new CommitFilter { IncludeReachableFrom = branch, ExcludeReachableFrom = baseVersionSource, FirstParentOnly = true }; - var commitCollection = this.repository.Commits.QueryBy(filter); - return commitCollection.Contains(firstMatchingCommit); + var commits = FilterCommits(filter); + return commits.Contains(firstMatchingCommit); } + private IEnumerable FilterCommits(CommitFilter filter) => this.repository.Commits.QueryBy(filter); + public ICommit? FindMergeBase(ICommit commit, ICommit mainlineTip) => this.repository.FindMergeBase(commit, mainlineTip); private IBranch? FindBranch(string branchName) => this.repository.Branches.FirstOrDefault(x => x.Name.EquivalentTo(branchName)); diff --git a/src/GitVersion.Core/Core/TaggedSemanticVersionRepository.cs b/src/GitVersion.Core/Core/TaggedSemanticVersionRepository.cs index 24649b9687..f6f0de0459 100644 --- a/src/GitVersion.Core/Core/TaggedSemanticVersionRepository.cs +++ b/src/GitVersion.Core/Core/TaggedSemanticVersionRepository.cs @@ -49,7 +49,7 @@ IEnumerable GetElements() { var semanticVersions = GetTaggedSemanticVersions(tagPrefix, format, ignore); - foreach (var commit in ignore.Filter(branch.Commits)) + foreach (var commit in ignore.Filter(branch.Commits.ToArray())) { foreach (var semanticVersion in semanticVersions[commit]) { @@ -88,7 +88,7 @@ public ILookup GetTaggedSemanticVersionsOfMerge using (this.log.IndentLog($"Getting tagged semantic versions by track merge target '{branch.Name.Canonical}'. " + $"TagPrefix: {tagPrefix} and Format: {format}")) { - var shaHashSet = new HashSet(ignore.Filter(branch.Commits).Select(element => element.Id.Sha)); + var shaHashSet = new HashSet(ignore.Filter(branch.Commits.ToArray()).Select(element => element.Id.Sha)); foreach (var semanticVersion in GetTaggedSemanticVersions(tagPrefix, format, ignore).SelectMany(v => v)) { @@ -124,7 +124,7 @@ IEnumerable GetElements() { this.log.Info($"Getting tagged semantic versions. TagPrefix: {tagPrefix} and Format: {format}"); - foreach (var tag in ignore.Filter(this.repositoryStore.Tags)) + foreach (var tag in ignore.Filter(this.repositoryStore.Tags.ToArray())) { if (SemanticVersion.TryParse(tag.Name.Friendly, tagPrefix, out var semanticVersion, format)) { diff --git a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersionStrategy.cs b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersionStrategy.cs index 2dd181c896..1e0dd74209 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersionStrategy.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MainlineVersionStrategy.cs @@ -82,7 +82,7 @@ public IEnumerable GetBaseVersions(EffectiveBranchConfiguration con configuration: branchConfiguration ); - var commitsInReverseOrder = Context.Configuration.Ignore.Filter(Context.CurrentBranchCommits); + var commitsInReverseOrder = Context.Configuration.Ignore.Filter(Context.CurrentBranchCommits.ToArray()); TaggedSemanticVersions taggedSemanticVersion = TaggedSemanticVersions.OfBranch; if (branchConfiguration.TrackMergeTarget == true) taggedSemanticVersion |= TaggedSemanticVersions.OfMergeTargets; diff --git a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MergeMessageVersionStrategy.cs b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MergeMessageVersionStrategy.cs index 7dfe751dc3..2ffeaf3d9e 100644 --- a/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MergeMessageVersionStrategy.cs +++ b/src/GitVersion.Core/VersionCalculation/VersionSearchStrategies/MergeMessageVersionStrategy.cs @@ -33,7 +33,7 @@ private IEnumerable GetBaseVersionsInternal(EffectiveBranchConfigur || !configuration.Value.TrackMergeMessage) yield break; - foreach (var commit in configuration.Value.Ignore.Filter(Context.CurrentBranchCommits)) + foreach (var commit in configuration.Value.Ignore.Filter(Context.CurrentBranchCommits.ToArray())) { if (MergeMessage.TryParse(commit, Context.Configuration, out var mergeMessage) && mergeMessage.Version is not null