Skip to content

Commit d2fc199

Browse files
committed
wip
1 parent 819df58 commit d2fc199

16 files changed

+260
-284
lines changed

src/GitVersion.Core/Helpers/LambdaEqualityHelper.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ public bool Equals(T? instance, T? other)
1717
return true;
1818
}
1919

20-
if (instance.GetType() != other.GetType())
21-
{
22-
return false;
23-
}
24-
25-
return equalityContributorAccessors.All(accessor => Equals(accessor(instance), accessor(other)));
20+
return instance.GetType() == other.GetType() && equalityContributorAccessors.All(accessor => Equals(accessor(instance), accessor(other)));
2621
}
2722

2823
public int GetHashCode(T instance)

src/GitVersion.Core/VersionCalculation/IncrementStrategyFinder.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,16 @@ [.. taggedSemanticVersionRepository
110110

111111
foreach (var intermediateCommit in intermediateCommits.Reverse())
112112
{
113-
if (targetShas.Value.Contains(intermediateCommit.Sha) && commitLog.Remove(intermediateCommit.Sha))
113+
if (!targetShas.Value.Contains(intermediateCommit.Sha) || !commitLog.Remove(intermediateCommit.Sha)) continue;
114+
var parentCommits = intermediateCommit.Parents.ToList();
115+
while (parentCommits.Count != 0)
114116
{
115-
var parentCommits = intermediateCommit.Parents.ToList();
116-
while (parentCommits.Count != 0)
117+
List<ICommit> temporaryList = [];
118+
foreach (var parentCommit in parentCommits.Where(parentCommit => commitLog.Remove(parentCommit.Sha)))
117119
{
118-
List<ICommit> temporaryList = [];
119-
foreach (var parentCommit in parentCommits)
120-
{
121-
if (commitLog.Remove(parentCommit.Sha))
122-
{
123-
temporaryList.AddRange(parentCommit.Parents);
124-
}
125-
}
126-
parentCommits = temporaryList;
120+
temporaryList.AddRange(parentCommit.Parents);
127121
}
122+
parentCommits = temporaryList;
128123
}
129124
}
130125

src/GitVersion.Core/VersionCalculation/Mainline/MainlineCommit.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ public EffectiveConfiguration GetEffectiveConfiguration(IGitVersionConfiguration
7575
last = i.Configuration;
7676
}
7777

78-
if (branchConfiguration.Increment == IncrementStrategy.Inherit && HasParentIteration)
79-
{
80-
var parentConfiguration = ParentCommit.GetEffectiveConfiguration(configuration);
81-
branchConfiguration = branchConfiguration.Inherit(parentConfiguration);
82-
}
78+
if (branchConfiguration.Increment != IncrementStrategy.Inherit || !HasParentIteration)
79+
return this.effectiveConfiguration = new EffectiveConfiguration(configuration, branchConfiguration);
80+
81+
var parentConfiguration = ParentCommit.GetEffectiveConfiguration(configuration);
82+
branchConfiguration = branchConfiguration.Inherit(parentConfiguration);
8383

8484
return effectiveConfiguration = new EffectiveConfiguration(configuration, branchConfiguration);
8585
}

src/GitVersion.Core/VersionCalculation/Mainline/MainlineIteration.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ public EffectiveConfiguration GetEffectiveConfiguration(IGitVersionConfiguration
2525

2626
var branchConfiguration = Configuration;
2727

28-
if (branchConfiguration.Increment == IncrementStrategy.Inherit && Commits.FirstOrDefault() is { } commit)
29-
{
30-
var parentConfiguration = commit.GetEffectiveConfiguration(configuration);
31-
branchConfiguration = branchConfiguration.Inherit(parentConfiguration);
32-
}
28+
if (branchConfiguration.Increment != IncrementStrategy.Inherit || Commits.FirstOrDefault() is not { } commit)
29+
return this.effectiveConfiguration = new EffectiveConfiguration(configuration, branchConfiguration);
30+
31+
var parentConfiguration = commit.GetEffectiveConfiguration(configuration);
32+
branchConfiguration = branchConfiguration.Inherit(parentConfiguration);
3333

3434
return this.effectiveConfiguration = new EffectiveConfiguration(configuration, branchConfiguration);
3535
}

src/GitVersion.Core/VersionCalculation/Mainline/NonTrunk/CommitOnNonTrunk.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,18 @@ public IEnumerable<IBaseVersionIncrement> GetIncrements(
2424
var effectiveConfiguration = commit.GetEffectiveConfiguration(context.Configuration);
2525
context.Label ??= effectiveConfiguration.GetBranchSpecificLabel(commit.BranchName, null);
2626

27-
if (commit.Successor is null)
27+
if (commit.Successor is not null) yield break;
28+
yield return new BaseVersionOperator
2829
{
29-
yield return new BaseVersionOperator
30-
{
31-
Source = GetType().Name,
32-
BaseVersionSource = context.BaseVersionSource,
33-
Increment = context.Increment,
34-
ForceIncrement = context.ForceIncrement,
35-
Label = context.Label,
36-
AlternativeSemanticVersion = context.AlternativeSemanticVersions.Max()
37-
};
38-
39-
context.BaseVersionSource = commit.Value;
40-
context.ForceIncrement = false;
41-
}
30+
Source = GetType().Name,
31+
BaseVersionSource = context.BaseVersionSource,
32+
Increment = context.Increment,
33+
ForceIncrement = context.ForceIncrement,
34+
Label = context.Label,
35+
AlternativeSemanticVersion = context.AlternativeSemanticVersions.Max()
36+
};
37+
38+
context.BaseVersionSource = commit.Value;
39+
context.ForceIncrement = false;
4240
}
4341
}

src/GitVersion.Core/VersionCalculation/Mainline/NonTrunk/FirstCommitOnRelease.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ public IEnumerable<IBaseVersionIncrement> GetIncrements(
3030
MainlineIteration iteration, MainlineCommit commit, MainlineContext context)
3131
{
3232
var effectiveConfiguration = commit.GetEffectiveConfiguration(context.Configuration);
33-
if (commit.BranchName.TryGetSemanticVersion(out var element, effectiveConfiguration))
34-
{
35-
context.AlternativeSemanticVersions.Add(element.Value);
36-
yield break;
37-
}
33+
if (!commit.BranchName.TryGetSemanticVersion(out var element, effectiveConfiguration)) yield break;
34+
context.AlternativeSemanticVersions.Add(element.Value);
3835
}
3936
}

src/GitVersion.Core/VersionCalculation/Mainline/NonTrunk/MergeCommitOnNonTrunkBase.cs

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,51 +14,56 @@ public virtual IEnumerable<IBaseVersionIncrement> GetIncrements(
1414
{
1515
if (commit.ChildIteration is null) throw new InvalidOperationException("The commit child iteration is null.");
1616

17-
var baseVersion = MainlineVersionStrategy.DetermineBaseVersionRecursive(
18-
iteration: commit.ChildIteration,
19-
targetLabel: context.TargetLabel,
20-
incrementStrategyFinder: context.IncrementStrategyFinder,
21-
configuration: context.Configuration
22-
);
17+
return GetIncrementsInternal();
2318

24-
context.Label ??= baseVersion.Operator?.Label;
25-
26-
var effectiveConfiguration = commit.GetEffectiveConfiguration(context.Configuration);
27-
var increment = VersionField.None;
28-
if (!effectiveConfiguration.PreventIncrementOfMergedBranch)
19+
IEnumerable<IBaseVersionIncrement> GetIncrementsInternal()
2920
{
30-
increment = increment.Consolidate(context.Increment);
31-
}
21+
var baseVersion = MainlineVersionStrategy.DetermineBaseVersionRecursive(
22+
iteration: commit.ChildIteration,
23+
targetLabel: context.TargetLabel,
24+
incrementStrategyFinder: context.IncrementStrategyFinder,
25+
configuration: context.Configuration
26+
);
3227

33-
if (!effectiveConfiguration.PreventIncrementWhenBranchMerged)
34-
{
35-
increment = increment.Consolidate(baseVersion.Operator?.Increment);
36-
}
28+
context.Label ??= baseVersion.Operator?.Label;
3729

38-
if (effectiveConfiguration.CommitMessageIncrementing != CommitMessageIncrementMode.Disabled)
39-
{
40-
increment = increment.Consolidate(commit.Increment);
41-
}
42-
context.Increment = increment;
30+
var effectiveConfiguration = commit.GetEffectiveConfiguration(context.Configuration);
31+
var increment = VersionField.None;
32+
if (!effectiveConfiguration.PreventIncrementOfMergedBranch)
33+
{
34+
increment = increment.Consolidate(context.Increment);
35+
}
4336

44-
if (baseVersion.BaseVersionSource is not null)
45-
{
46-
context.BaseVersionSource = baseVersion.BaseVersionSource;
47-
context.SemanticVersion = baseVersion.SemanticVersion;
48-
}
49-
else
50-
{
51-
if (baseVersion.SemanticVersion != SemanticVersion.Empty)
37+
if (!effectiveConfiguration.PreventIncrementWhenBranchMerged)
5238
{
53-
context.AlternativeSemanticVersions.Add(baseVersion.SemanticVersion);
39+
increment = increment.Consolidate(baseVersion.Operator?.Increment);
5440
}
5541

56-
if (baseVersion.Operator?.AlternativeSemanticVersion is not null)
42+
if (effectiveConfiguration.CommitMessageIncrementing != CommitMessageIncrementMode.Disabled)
5743
{
58-
context.AlternativeSemanticVersions.Add(baseVersion.Operator.AlternativeSemanticVersion);
44+
increment = increment.Consolidate(commit.Increment);
5945
}
60-
}
46+
context.Increment = increment;
6147

62-
yield break;
48+
if (baseVersion.BaseVersionSource is not null)
49+
{
50+
context.BaseVersionSource = baseVersion.BaseVersionSource;
51+
context.SemanticVersion = baseVersion.SemanticVersion;
52+
}
53+
else
54+
{
55+
if (baseVersion.SemanticVersion != SemanticVersion.Empty)
56+
{
57+
context.AlternativeSemanticVersions.Add(baseVersion.SemanticVersion);
58+
}
59+
60+
if (baseVersion.Operator?.AlternativeSemanticVersion is not null)
61+
{
62+
context.AlternativeSemanticVersions.Add(baseVersion.Operator.AlternativeSemanticVersion);
63+
}
64+
}
65+
66+
yield break;
67+
}
6368
}
6469
}

src/GitVersion.Core/VersionCalculation/Mainline/RemoveIncrement.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ internal sealed class RemoveIncrement : IContextPostEnricher
44
{
55
public void Enrich(MainlineCommit commit, MainlineContext context)
66
{
7-
if (commit.GetEffectiveConfiguration(context.Configuration).IsMainBranch)
8-
{
9-
context.Increment = VersionField.None;
10-
context.Label = null;
11-
context.AlternativeSemanticVersions.Clear();
12-
}
7+
if (!commit.GetEffectiveConfiguration(context.Configuration).IsMainBranch) return;
8+
context.Increment = VersionField.None;
9+
context.Label = null;
10+
context.AlternativeSemanticVersions.Clear();
1311
}
1412
}

src/GitVersion.Core/VersionCalculation/Mainline/Trunk/LastCommitOnTrunkWithPreReleaseTag.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,21 @@ public override IEnumerable<IBaseVersionIncrement> GetIncrements(
1818
yield return item;
1919
}
2020

21-
if (iteration.GetEffectiveConfiguration(context.Configuration).IsMainBranch)
22-
{
23-
context.Increment = commit.GetIncrementForcedByBranch(context.Configuration);
21+
if (!iteration.GetEffectiveConfiguration(context.Configuration).IsMainBranch) yield break;
22+
context.Increment = commit.GetIncrementForcedByBranch(context.Configuration);
2423

25-
var effectiveConfiguration = commit.GetEffectiveConfiguration(context.Configuration);
26-
context.Label = effectiveConfiguration.GetBranchSpecificLabel(commit.BranchName, null);
27-
context.ForceIncrement = false;
24+
var effectiveConfiguration = commit.GetEffectiveConfiguration(context.Configuration);
25+
context.Label = effectiveConfiguration.GetBranchSpecificLabel(commit.BranchName, null);
26+
context.ForceIncrement = false;
2827

29-
yield return new BaseVersionOperator
30-
{
31-
Source = GetType().Name,
32-
BaseVersionSource = context.BaseVersionSource,
33-
Increment = context.Increment,
34-
ForceIncrement = context.ForceIncrement,
35-
Label = context.Label,
36-
AlternativeSemanticVersion = context.AlternativeSemanticVersions.Max()
37-
};
38-
}
28+
yield return new BaseVersionOperator
29+
{
30+
Source = GetType().Name,
31+
BaseVersionSource = context.BaseVersionSource,
32+
Increment = context.Increment,
33+
ForceIncrement = context.ForceIncrement,
34+
Label = context.Label,
35+
AlternativeSemanticVersion = context.AlternativeSemanticVersions.Max()
36+
};
3937
}
4038
}

src/GitVersion.Core/VersionCalculation/Mainline/Trunk/LastCommitOnTrunkWithStableTag.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,17 @@ public override IEnumerable<IBaseVersionIncrement> GetIncrements(
1616
yield return item;
1717
}
1818

19-
if (iteration.GetEffectiveConfiguration(context.Configuration).IsMainBranch)
20-
{
21-
context.ForceIncrement = true;
19+
if (!iteration.GetEffectiveConfiguration(context.Configuration).IsMainBranch) yield break;
20+
context.ForceIncrement = true;
2221

23-
yield return new BaseVersionOperator
24-
{
25-
Source = GetType().Name,
26-
BaseVersionSource = context.BaseVersionSource,
27-
Increment = context.Increment,
28-
ForceIncrement = context.ForceIncrement,
29-
Label = context.Label,
30-
AlternativeSemanticVersion = context.AlternativeSemanticVersions.Max()
31-
};
32-
}
22+
yield return new BaseVersionOperator
23+
{
24+
Source = GetType().Name,
25+
BaseVersionSource = context.BaseVersionSource,
26+
Increment = context.Increment,
27+
ForceIncrement = context.ForceIncrement,
28+
Label = context.Label,
29+
AlternativeSemanticVersion = context.AlternativeSemanticVersions.Max()
30+
};
3331
}
3432
}

0 commit comments

Comments
 (0)