Skip to content

Commit 976eadc

Browse files
committed
Merge pull request #680 from orjan/performance-get-base-config
Make sure that we're not evaluating excluded branches
2 parents 2f4da61 + 33f8921 commit 976eadc

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,4 @@ NuGetExeBuild/
9090
NuGetRefBuild/
9191
Packages/
9292
NuGetTaskBuild/
93+
GitVersionTfsTaskBuild/

src/GitVersionCore/BranchConfigurationCalculator.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,33 @@ static KeyValuePair<string, BranchConfig> InheritBranchConfiguration(bool onlyEv
6565
{
6666
excludedBranches = CalculateWhenMultipleParents(repository, currentCommit, ref currentBranch, excludedBranches);
6767
}
68+
6869
if (excludedInheritBranches == null)
6970
{
7071
excludedInheritBranches = repository.Branches.Where(b =>
7172
{
7273
var branchConfig = LookupBranchConfiguration(config, b);
73-
return branchConfig.Length == 1 && branchConfig[0].Value.Increment == IncrementStrategy.Inherit;
74+
75+
// NOTE: if length is 0 we couldn't find the configuration for the branch e.g. "origin/master"
76+
// NOTE: if the length is greater than 1 we cannot decide which merge strategy to pick
77+
return (branchConfig.Length != 1) || (branchConfig.Length == 1 && branchConfig[0].Value.Increment == IncrementStrategy.Inherit);
7478
}).ToList();
7579
}
7680
excludedBranches.ToList().ForEach(excludedInheritBranches.Add);
81+
var branchesToEvaluate = repository.Branches.Except(excludedInheritBranches).ToList();
7782

7883
var branchPoint = currentBranch.FindCommitBranchWasBranchedFrom(repository, excludedInheritBranches.ToArray());
79-
8084
List<Branch> possibleParents;
8185
if (branchPoint == null)
8286
{
83-
possibleParents = currentCommit.GetBranchesContainingCommit(repository, true).Except(excludedInheritBranches).ToList();
87+
possibleParents = currentCommit.GetBranchesContainingCommit(repository, branchesToEvaluate, true).ToList();
8488
}
8589
else
8690
{
87-
var branches = branchPoint.GetBranchesContainingCommit(repository, true).Except(excludedInheritBranches).ToList();
91+
var branches = branchPoint.GetBranchesContainingCommit(repository, branchesToEvaluate, true).ToList();
8892
if (branches.Count > 1)
8993
{
90-
var currentTipBranches = currentCommit.GetBranchesContainingCommit(repository, true).Except(excludedInheritBranches).ToList();
94+
var currentTipBranches = currentCommit.GetBranchesContainingCommit(repository, branchesToEvaluate, true).ToList();
9195
possibleParents = branches.Except(currentTipBranches).ToList();
9296
}
9397
else

src/GitVersionCore/GitVersionContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public GitVersionContext(IRepository repository, Branch currentBranch, Config co
4848

4949
if (currentBranch.IsDetachedHead())
5050
{
51-
CurrentBranch = CurrentCommit.GetBranchesContainingCommit(repository, OnlyEvaluateTrackedBranches).OnlyOrDefault() ?? currentBranch;
51+
CurrentBranch = CurrentCommit.GetBranchesContainingCommit(repository, repository.Branches.ToList(), OnlyEvaluateTrackedBranches).OnlyOrDefault() ?? currentBranch;
5252
}
5353
else
5454
{

src/GitVersionCore/LibGitExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ static bool IsSameBranch(Branch branch, Branch b)
9292
return (b.IsRemote ? b.Name.Replace(b.Remote.Name + "/", string.Empty) : b.Name) != branch.Name;
9393
}
9494

95-
public static IEnumerable<Branch> GetBranchesContainingCommit([NotNull] this Commit commit, IRepository repository, bool onlyTrackedBranches)
95+
public static IEnumerable<Branch> GetBranchesContainingCommit([NotNull] this Commit commit, IRepository repository, IList<Branch> branches, bool onlyTrackedBranches)
9696
{
9797
if (commit == null)
9898
{
9999
throw new ArgumentNullException("commit");
100100
}
101101

102102
var directBranchHasBeenFound = false;
103-
foreach (var branch in repository.Branches)
103+
foreach (var branch in branches)
104104
{
105105
if (branch.Tip != null && branch.Tip.Sha != commit.Sha || (onlyTrackedBranches && !branch.IsTracking))
106106
{
@@ -116,7 +116,7 @@ public static IEnumerable<Branch> GetBranchesContainingCommit([NotNull] this Com
116116
yield break;
117117
}
118118

119-
foreach (var branch in repository.Branches.Where(b => (onlyTrackedBranches && !b.IsTracking)))
119+
foreach (var branch in branches.Where(b => (onlyTrackedBranches && !b.IsTracking)))
120120
{
121121
var commits = repository.Commits.QueryBy(new CommitFilter { Since = branch }).Where(c => c.Sha == commit.Sha);
122122

0 commit comments

Comments
 (0)