Skip to content

Commit 475f65c

Browse files
HHobeckarturcic
authored andcommitted
Change recursive call in incrementStrategyFinder
1 parent 85701ff commit 475f65c

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
@@ -112,7 +112,7 @@ private static Regex TryGetRegexOrDefault(string? messageRegex, Regex defaultReg
112112
private IReadOnlyCollection<ICommit> GetCommitHistory(
113113
string? tagPrefix, SemanticVersionFormat semanticVersionFormat, ICommit? baseVersionSource, ICommit currentCommit, string? label)
114114
{
115-
var targetShas = new Lazy<IReadOnlySet<string>>(() =>
115+
var targetShas = new Lazy<HashSet<string>>(() =>
116116
this.taggedSemanticVersionRepository.GetTaggedSemanticVersions(tagPrefix, semanticVersionFormat)
117117
.SelectMany(_ => _).Where(_ => _.Value.IsMatchForBranchSpecificLabel(label)).Select(_ => _.Tag.TargetSha).ToHashSet()
118118
);
@@ -123,20 +123,21 @@ private IReadOnlyCollection<ICommit> GetCommitHistory(
123123

124124
foreach (var intermediateCommit in intermediateCommits.Reverse())
125125
{
126-
if (!commitLog.ContainsKey(intermediateCommit.Sha)) continue;
127-
128-
if (targetShas.Value.Contains(intermediateCommit.Sha))
126+
if (targetShas.Value.Contains(intermediateCommit.Sha) && commitLog.Remove(intermediateCommit.Sha))
129127
{
130-
void RemoveCommitFromHistory(ICommit commit, HashSet<ICommit> traversedCommits)
128+
var parentCommits = intermediateCommit.Parents.ToList();
129+
while (parentCommits.Count != 0)
131130
{
132-
if (!traversedCommits.Add(commit) || !commitLog.Remove(commit.Sha)) return;
133-
134-
foreach (var parentCommit in commit.Parents)
131+
List<ICommit> temporaryList = new();
132+
foreach (var parentCommit in parentCommits)
135133
{
136-
RemoveCommitFromHistory(parentCommit, traversedCommits);
134+
if (commitLog.Remove(parentCommit.Sha))
135+
{
136+
temporaryList.AddRange(parentCommit.Parents);
137+
}
137138
}
139+
parentCommits = temporaryList;
138140
}
139-
RemoveCommitFromHistory(intermediateCommit, new HashSet<ICommit>());
140141
}
141142
}
142143

0 commit comments

Comments
 (0)