Skip to content

Commit 85701ff

Browse files
HHobeckarturcic
authored andcommitted
Integrate code review remarks
1 parent cb5eca3 commit 85701ff

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/GitVersion.Core/VersionCalculation/IncrementStrategyFinder.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private static Regex TryGetRegexOrDefault(string? messageRegex, Regex defaultReg
109109
? defaultRegex
110110
: CompiledRegexCache.GetOrAdd(messageRegex, pattern => new(pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase));
111111

112-
public IReadOnlyCollection<ICommit> GetCommitHistory(
112+
private IReadOnlyCollection<ICommit> GetCommitHistory(
113113
string? tagPrefix, SemanticVersionFormat semanticVersionFormat, ICommit? baseVersionSource, ICommit currentCommit, string? label)
114114
{
115115
var targetShas = new Lazy<IReadOnlySet<string>>(() =>
@@ -121,23 +121,22 @@ public IReadOnlyCollection<ICommit> GetCommitHistory(
121121

122122
var commitLog = intermediateCommits.ToDictionary(element => element.Id.Sha);
123123

124-
foreach (var item in intermediateCommits.Reverse())
124+
foreach (var intermediateCommit in intermediateCommits.Reverse())
125125
{
126-
if (!commitLog.ContainsKey(item.Sha)) continue;
126+
if (!commitLog.ContainsKey(intermediateCommit.Sha)) continue;
127127

128-
if (targetShas.Value.Contains(item.Sha))
128+
if (targetShas.Value.Contains(intermediateCommit.Sha))
129129
{
130-
void RemoveCommitFromHistory(ICommit commit)
130+
void RemoveCommitFromHistory(ICommit commit, HashSet<ICommit> traversedCommits)
131131
{
132-
if (!commitLog.ContainsKey(commit.Sha)) return;
132+
if (!traversedCommits.Add(commit) || !commitLog.Remove(commit.Sha)) return;
133133

134-
commitLog.Remove(commit.Sha);
135-
foreach (var item in commit.Parents)
134+
foreach (var parentCommit in commit.Parents)
136135
{
137-
RemoveCommitFromHistory(item);
136+
RemoveCommitFromHistory(parentCommit, traversedCommits);
138137
}
139138
}
140-
RemoveCommitFromHistory(item);
139+
RemoveCommitFromHistory(intermediateCommit, new HashSet<ICommit>());
141140
}
142141
}
143142

0 commit comments

Comments
 (0)