Skip to content

Commit c50672a

Browse files
committed
Hide Cache and call GetOrAddCachedRegex instead.
1 parent 2330173 commit c50672a

File tree

9 files changed

+11
-11
lines changed

9 files changed

+11
-11
lines changed

src/GitVersion.Core/Configuration/IBranchConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ bool IsMatch(string branchName)
2929
return false;
3030
}
3131

32-
var regex = RegexPatterns.Cache.GetOrAdd(RegularExpression);
32+
var regex = RegexPatterns.GetOrAddCachedRegex(RegularExpression);
3333
return regex.IsMatch(branchName);
3434
}
3535

src/GitVersion.Core/Configuration/ReferenceNameExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private static bool TryGetSemanticVersion(this ReferenceName referenceName, out
1717
string? tagPrefix,
1818
SemanticVersionFormat format)
1919
{
20-
var versionPatternRegex = RegexPatterns.Cache.GetOrAdd(GetVersionInBranchPattern(versionPatternPattern));
20+
var versionPatternRegex = RegexPatterns.GetOrAddCachedRegex(GetVersionInBranchPattern(versionPatternPattern));
2121
result = default;
2222

2323
var length = 0;

src/GitVersion.Core/Core/RegexPatterns.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ namespace GitVersion.Core;
55

66
internal static partial class RegexPatterns
77
{
8-
internal static readonly ConcurrentDictionary<string, Regex> Cache = new();
8+
private static readonly ConcurrentDictionary<string, Regex> Cache = new();
99

10-
public static Regex GetRegex(string pattern) => Cache.GetOrAdd(
10+
public static Regex GetOrAddCachedRegex(string pattern) => Cache.GetOrAdd(
1111
pattern,
1212
_ => pattern switch
1313
{

src/GitVersion.Core/Core/SourceBranchFinder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private static IEnumerable<Regex> GetSourceBranchRegexes(INamedReference branch,
3636
var currentBranchConfig = configuration.GetBranchConfiguration(branch.Name);
3737
if (currentBranchConfig is { SourceBranches: null })
3838
{
39-
yield return RegexPatterns.Cache.GetOrAdd(".*");
39+
yield return RegexPatterns.GetOrAddCachedRegex(".*");
4040
}
4141
else
4242
{
@@ -45,7 +45,7 @@ private static IEnumerable<Regex> GetSourceBranchRegexes(INamedReference branch,
4545
{
4646
var regex = branches[sourceBranch].RegularExpression;
4747
if (regex != null)
48-
yield return RegexPatterns.Cache.GetOrAdd(regex);
48+
yield return RegexPatterns.GetOrAddCachedRegex(regex);
4949
}
5050
}
5151
}

src/GitVersion.Core/Extensions/ConfigurationExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static bool IsReleaseBranch(this IGitVersionConfiguration configuration,
9090

9191
var effectiveBranchName = branchNameOverride ?? branchName;
9292
if (configuration.RegularExpression.IsNullOrWhiteSpace() || effectiveBranchName.IsNullOrEmpty()) return label;
93-
var regex = RegexPatterns.Cache.GetOrAdd(configuration.RegularExpression);
93+
var regex = RegexPatterns.GetOrAddCachedRegex(configuration.RegularExpression);
9494
var match = regex.Match(effectiveBranchName);
9595
if (!match.Success) return label;
9696
foreach (var groupName in regex.GetGroupNames())

src/GitVersion.Core/Extensions/StringExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static void AppendLineFormat(this StringBuilder stringBuilder, string for
1313

1414
public static string RegexReplace(this string input, string pattern, string replace)
1515
{
16-
var regex = RegexPatterns.Cache.GetOrAdd(pattern);
16+
var regex = RegexPatterns.GetOrAddCachedRegex(pattern);
1717
return regex.Replace(input, replace);
1818
}
1919

src/GitVersion.Core/MergeMessage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public MergeMessage(string mergeMessage, IGitVersionConfiguration configuration)
3030
// Concatenate configuration formats with the defaults.
3131
// Ensure configurations are processed first.
3232
var allFormats = configuration.MergeMessageFormats
33-
.Select(x => (Name: x.Key, Pattern: RegexPatterns.Cache.GetOrAdd(x.Value)))
33+
.Select(x => (Name: x.Key, Pattern: RegexPatterns.GetOrAddCachedRegex(x.Value)))
3434
.Concat(DefaultFormats);
3535

3636
foreach (var (Name, Pattern) in allFormats)

src/GitVersion.Core/SemVer/SemanticVersion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public static SemanticVersion Parse(
132132
public static bool TryParse(string version, string? tagPrefixRegex,
133133
[NotNullWhen(true)] out SemanticVersion? semanticVersion, SemanticVersionFormat format = SemanticVersionFormat.Strict)
134134
{
135-
var regex = RegexPatterns.Cache.GetOrAdd($"^({tagPrefixRegex})(?<version>.*)$");
135+
var regex = RegexPatterns.GetOrAddCachedRegex($"^({tagPrefixRegex})(?<version>.*)$");
136136
var match = regex.Match(version);
137137

138138
if (!match.Success)

src/GitVersion.Core/VersionCalculation/IncrementStrategyFinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public VersionField DetermineIncrementedField(
9292
private static Regex TryGetRegexOrDefault(string? messageRegex, Regex defaultRegex) =>
9393
messageRegex == null
9494
? defaultRegex
95-
: RegexPatterns.Cache.GetOrAdd(messageRegex);
95+
: RegexPatterns.GetOrAddCachedRegex(messageRegex);
9696

9797
private Dictionary<string, ICommit>.ValueCollection GetCommitHistory(string? tagPrefix, SemanticVersionFormat semanticVersionFormat,
9898
ICommit? baseVersionSource, ICommit currentCommit, string? label, IIgnoreConfiguration ignore)

0 commit comments

Comments
 (0)