@@ -10,11 +10,10 @@ namespace GitVersion;
10
10
11
11
public class RepositoryStore : IRepositoryStore
12
12
{
13
- private const string MissingTipFormat = "{0} has no tip. Please see https://example.com/docs for information on how to fix this." ;
13
+ internal const string MissingTipFormat = "{0} has no tip. Please see https://example.com/docs for information on how to fix this." ;
14
14
private readonly IIncrementStrategyFinder incrementStrategyFinder ;
15
15
private readonly ILog log ;
16
16
private readonly Dictionary < Tuple < IBranch , IBranch ? > , ICommit ? > mergeBaseCache = new ( ) ;
17
- private readonly Dictionary < IBranch ? , List < BranchCommit > > mergeBaseCommitsCache = new ( ) ;
18
17
private readonly IGitRepository repository ;
19
18
private readonly Dictionary < IBranch , List < SemanticVersion > > semanticVersionTagsOnBranchCache = new ( ) ;
20
19
@@ -30,8 +29,7 @@ public RepositoryStore(ILog log, IGitRepository repository, IIncrementStrategyFi
30
29
/// </summary>
31
30
public ICommit ? FindMergeBase ( IBranch ? branch , IBranch ? otherBranch )
32
31
{
33
- if ( branch == null )
34
- throw new ArgumentNullException ( nameof ( branch ) ) ;
32
+ branch = branch . NotNull ( ) ;
35
33
36
34
var key = Tuple . Create ( branch , otherBranch ) ;
37
35
@@ -318,20 +316,19 @@ public BranchCommit FindCommitBranchWasBranchedFrom(IBranch? branch, Config conf
318
316
return BranchCommit . Empty ;
319
317
}
320
318
321
- var possibleBranches = GetMergeCommitsForBranch ( branch , configuration , excludedBranches )
322
- . Where ( b => ! branch . Name . EquivalentTo ( b . Branch . Name . WithoutRemote ) )
323
- . ToList ( ) ;
319
+ var possibleBranches =
320
+ new MergeCommitFinder ( this , configuration , excludedBranches , this . log )
321
+ . FindMergeCommitsFor ( branch )
322
+ . ToList ( ) ;
324
323
325
- if ( possibleBranches . Count > 1 )
326
- {
327
- var first = possibleBranches . First ( ) ;
328
- this . log . Info ( $ "Multiple source branches have been found, picking the first one ({ first . Branch } ).{ System . Environment . NewLine } " +
329
- $ "This may result in incorrect commit counting.{ System . Environment . NewLine } Options were:{ System . Environment . NewLine } " +
330
- string . Join ( ", " , possibleBranches . Select ( b => b . Branch . ToString ( ) ) ) ) ;
331
- return first ;
332
- }
324
+ if ( possibleBranches . Count <= 1 )
325
+ return possibleBranches . SingleOrDefault ( ) ;
333
326
334
- return possibleBranches . SingleOrDefault ( ) ;
327
+ var first = possibleBranches . First ( ) ;
328
+ this . log . Info ( $ "Multiple source branches have been found, picking the first one ({ first . Branch } ).{ System . Environment . NewLine } " +
329
+ $ "This may result in incorrect commit counting.{ System . Environment . NewLine } Options were:{ System . Environment . NewLine } " +
330
+ string . Join ( ", " , possibleBranches . Select ( b => b . Branch . ToString ( ) ) ) ) ;
331
+ return first ;
335
332
}
336
333
}
337
334
@@ -466,47 +463,6 @@ private bool BranchMatchesMainlineConfig(INamedReference branch, KeyValuePair<st
466
463
return null ;
467
464
}
468
465
469
- private IEnumerable < BranchCommit > GetMergeCommitsForBranch ( IBranch branch , Config configuration , IEnumerable < IBranch > excludedBranches )
470
- {
471
- branch = branch . NotNull ( ) ;
472
-
473
- if ( this . mergeBaseCommitsCache . ContainsKey ( branch ) )
474
- {
475
- this . log . Debug ( $ "Cache hit for getting merge commits for branch { branch ? . Name . Canonical } .") ;
476
- return this . mergeBaseCommitsCache [ branch ] ;
477
- }
478
-
479
- var currentBranchConfig = configuration . GetConfigForBranch ( branch . Name . WithoutRemote ) ;
480
- var regexesToCheck = currentBranchConfig ? . SourceBranches == null
481
- ? new [ ] { ".*" } // Match anything if we can't find a branch config
482
- : currentBranchConfig . SourceBranches . Select ( sb => configuration . Branches [ sb ] ? . Regex ) ;
483
- var branchMergeBases = ExcludingBranches ( excludedBranches )
484
- . Where ( b =>
485
- {
486
- if ( Equals ( b , branch ) )
487
- return false ;
488
-
489
- var branchCanBeMergeBase = regexesToCheck . Any ( regex => regex != null && Regex . IsMatch ( b . Name . Friendly , regex ) ) ;
490
-
491
- return branchCanBeMergeBase ;
492
- } )
493
- . Select ( otherBranch =>
494
- {
495
- if ( otherBranch . Tip == null )
496
- {
497
- this . log . Warning ( string . Format ( MissingTipFormat , otherBranch ) ) ;
498
- return BranchCommit . Empty ;
499
- }
500
-
501
- var findMergeBase = FindMergeBase ( branch , otherBranch ) ;
502
- return findMergeBase == null ? BranchCommit . Empty : new BranchCommit ( findMergeBase , otherBranch ) ;
503
- } )
504
- . OrderByDescending ( b => b . Commit . When )
505
- . ToList ( ) ;
506
- this . mergeBaseCommitsCache . Add ( branch , branchMergeBases ) ;
507
-
508
- return branchMergeBases ;
509
- }
510
466
511
467
private static IEnumerable < ICommit > GetCommitsReacheableFrom ( IGitRepository repository , IGitObject commit , IBranch branch )
512
468
{
0 commit comments