@@ -75,26 +75,21 @@ public VersionField DetermineIncrementedField(
75
75
}
76
76
77
77
private VersionField ? FindCommitMessageIncrement (
78
- EffectiveConfiguration configuration , ICommit ? baseCommit , ICommit ? currentCommit , string ? label )
78
+ EffectiveConfiguration configuration , ICommit ? baseVersionSource , ICommit currentCommit , string ? label )
79
79
{
80
80
if ( configuration . CommitMessageIncrementing == CommitMessageIncrementMode . Disabled )
81
81
{
82
82
return null ;
83
83
}
84
84
85
- //get tags with valid version - depends on configuration (see #3757)
86
- var targetShas = new Lazy < IReadOnlySet < string > > ( ( ) =>
87
- this . taggedSemanticVersionRepository . GetTaggedSemanticVersions ( configuration . TagPrefix , configuration . SemanticVersionFormat )
88
- . SelectMany ( _ => _ ) . Where ( _ => _ . Value . IsMatchForBranchSpecificLabel ( label ) ) . Select ( _ => _ . Tag . TargetSha ) . ToHashSet ( )
85
+ IEnumerable < ICommit > commits = GetCommitHistory (
86
+ tagPrefix : configuration . TagPrefix ,
87
+ semanticVersionFormat : configuration . SemanticVersionFormat ,
88
+ baseVersionSource : baseVersionSource ,
89
+ currentCommit : currentCommit ,
90
+ label : label
89
91
) ;
90
92
91
- var commits = GetIntermediateCommits ( baseCommit , currentCommit ) ;
92
- // consider commit messages since latest tag only (see #3071)
93
- commits = commits
94
- . Reverse ( )
95
- . TakeWhile ( x => ! targetShas . Value . Contains ( x . Sha ) )
96
- . Reverse ( ) ;
97
-
98
93
if ( configuration . CommitMessageIncrementing == CommitMessageIncrementMode . MergeMessageOnly )
99
94
{
100
95
commits = commits . Where ( c => c . Parents . Count ( ) > 1 ) ;
@@ -114,6 +109,41 @@ private static Regex TryGetRegexOrDefault(string? messageRegex, Regex defaultReg
114
109
? defaultRegex
115
110
: CompiledRegexCache . GetOrAdd ( messageRegex , pattern => new ( pattern , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ) ;
116
111
112
+ private IReadOnlyCollection < ICommit > GetCommitHistory (
113
+ string ? tagPrefix , SemanticVersionFormat semanticVersionFormat , ICommit ? baseVersionSource , ICommit currentCommit , string ? label )
114
+ {
115
+ var targetShas = new Lazy < HashSet < string > > ( ( ) =>
116
+ this . taggedSemanticVersionRepository . GetTaggedSemanticVersions ( tagPrefix , semanticVersionFormat )
117
+ . SelectMany ( _ => _ ) . Where ( _ => _ . Value . IsMatchForBranchSpecificLabel ( label ) ) . Select ( _ => _ . Tag . TargetSha ) . ToHashSet ( )
118
+ ) ;
119
+
120
+ var intermediateCommits = GetIntermediateCommits ( baseVersionSource , currentCommit ) . ToArray ( ) ;
121
+
122
+ var commitLog = intermediateCommits . ToDictionary ( element => element . Id . Sha ) ;
123
+
124
+ foreach ( var intermediateCommit in intermediateCommits . Reverse ( ) )
125
+ {
126
+ if ( targetShas . Value . Contains ( intermediateCommit . Sha ) && commitLog . Remove ( intermediateCommit . Sha ) )
127
+ {
128
+ var parentCommits = intermediateCommit . Parents . ToList ( ) ;
129
+ while ( parentCommits . Count != 0 )
130
+ {
131
+ List < ICommit > temporaryList = new ( ) ;
132
+ foreach ( var parentCommit in parentCommits )
133
+ {
134
+ if ( commitLog . Remove ( parentCommit . Sha ) )
135
+ {
136
+ temporaryList . AddRange ( parentCommit . Parents ) ;
137
+ }
138
+ }
139
+ parentCommits = temporaryList ;
140
+ }
141
+ }
142
+ }
143
+
144
+ return commitLog . Values ;
145
+ }
146
+
117
147
/// <summary>
118
148
/// Get the sequence of commits in a repository between a <paramref name="baseCommit"/> (exclusive)
119
149
/// and a particular <paramref name="headCommit"/> (inclusive)
@@ -149,7 +179,7 @@ private Dictionary<string, int> GetHeadCommitsMap(ICommit? headCommit) =>
149
179
/// </summary>
150
180
private ICommit [ ] GetHeadCommits ( ICommit ? headCommit ) =>
151
181
this . headCommitsCache . GetOrAdd ( headCommit ? . Sha ?? "NULL" , ( ) =>
152
- GetCommitsReacheableFromHead ( repository , headCommit ) . ToArray ( ) ) ;
182
+ GetCommitsReacheableFromHead ( headCommit ) . ToArray ( ) ) ;
153
183
154
184
private VersionField ? GetIncrementFromCommit ( ICommit commit , Regex majorRegex , Regex minorRegex , Regex patchRegex , Regex none ) =>
155
185
this . commitIncrementCache . GetOrAdd ( commit . Sha , ( ) =>
@@ -164,19 +194,15 @@ private ICommit[] GetHeadCommits(ICommit? headCommit) =>
164
194
return null ;
165
195
}
166
196
167
- /// <summary>
168
- /// Query a <paramref name="repo"/> for the sequence of commits from the beginning to a particular
169
- /// <paramref name="headCommit"/> (inclusive)
170
- /// </summary>
171
- private static IEnumerable < ICommit > GetCommitsReacheableFromHead ( IGitRepository repo , ICommit ? headCommit )
197
+ private IEnumerable < ICommit > GetCommitsReacheableFromHead ( ICommit ? headCommit )
172
198
{
173
199
var filter = new CommitFilter
174
200
{
175
201
IncludeReachableFrom = headCommit ,
176
202
SortBy = CommitSortStrategies . Topological | CommitSortStrategies . Reverse
177
203
} ;
178
204
179
- return repo . Commits . QueryBy ( filter ) ;
205
+ return repository . Commits . QueryBy ( filter ) ;
180
206
}
181
207
182
208
public IEnumerable < ICommit > GetMergedCommits ( ICommit mergeCommit , int index )
@@ -202,7 +228,7 @@ private static ICommit GetMergedHead(ICommit mergeCommit)
202
228
{
203
229
var parents = mergeCommit . Parents . Skip ( 1 ) . ToList ( ) ;
204
230
if ( parents . Count > 1 )
205
- throw new NotSupportedException ( "Mainline development does not support more than one merge source in a single commit yet" ) ;
231
+ throw new NotSupportedException ( "GitVersion does not support more than one merge source in a single commit yet" ) ;
206
232
return parents . Single ( ) ;
207
233
}
208
234
0 commit comments