Skip to content

Commit 31868de

Browse files
committed
Change recursive call in incrementStrategyFinder
1 parent 9cfc193 commit 31868de

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/GitVersion.Core/VersionCalculation/IncrementStrategyFinder.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private static Regex TryGetRegexOrDefault(string? messageRegex, Regex defaultReg
117117
private IReadOnlyCollection<ICommit> GetCommitHistory(
118118
string? tagPrefix, SemanticVersionFormat semanticVersionFormat, ICommit? baseVersionSource, ICommit currentCommit, string? label)
119119
{
120-
var targetShas = new Lazy<IReadOnlySet<string>>(() =>
120+
var targetShas = new Lazy<HashSet<string>>(() =>
121121
this.taggedSemanticVersionRepository.GetTaggedSemanticVersions(tagPrefix, semanticVersionFormat)
122122
.SelectMany(_ => _).Where(_ => _.Value.IsMatchForBranchSpecificLabel(label)).Select(_ => _.Tag.TargetSha).ToHashSet()
123123
);
@@ -128,20 +128,21 @@ private IReadOnlyCollection<ICommit> GetCommitHistory(
128128

129129
foreach (var intermediateCommit in intermediateCommits.Reverse())
130130
{
131-
if (!commitLog.ContainsKey(intermediateCommit.Sha)) continue;
132-
133-
if (targetShas.Value.Contains(intermediateCommit.Sha))
131+
if (targetShas.Value.Contains(intermediateCommit.Sha) && commitLog.Remove(intermediateCommit.Sha))
134132
{
135-
void RemoveCommitFromHistory(ICommit commit, HashSet<ICommit> traversedCommits)
133+
var parentCommits = intermediateCommit.Parents.ToList();
134+
while (parentCommits.Count != 0)
136135
{
137-
if (!traversedCommits.Add(commit) || !commitLog.Remove(commit.Sha)) return;
138-
139-
foreach (var parentCommit in commit.Parents)
136+
List<ICommit> temporaryList = new();
137+
foreach (var parentCommit in parentCommits)
140138
{
141-
RemoveCommitFromHistory(parentCommit, traversedCommits);
139+
if (commitLog.Remove(parentCommit.Sha))
140+
{
141+
temporaryList.AddRange(parentCommit.Parents);
142+
}
142143
}
144+
parentCommits = temporaryList;
143145
}
144-
RemoveCommitFromHistory(intermediateCommit, new HashSet<ICommit>());
145146
}
146147
}
147148

0 commit comments

Comments
 (0)